diff --git a/org/html_writer.go b/org/html_writer.go index 08a5b69..878560b 100644 --- a/org/html_writer.go +++ b/org/html_writer.go @@ -4,6 +4,7 @@ import ( "fmt" "html" "log" + "reflect" "regexp" "strconv" "strings" @@ -415,8 +416,8 @@ func (w *HTMLWriter) WriteListItem(li ListItem) { if li.Status != "" { attributes += fmt.Sprintf(` class="%s"`, listItemStatuses[li.Status]) } - w.WriteString(fmt.Sprintf("\n", attributes)) - WriteNodes(w, li.Children...) + w.WriteString(fmt.Sprintf("", attributes)) + w.writeListItemContent(li.Children) w.WriteString("\n") } @@ -433,11 +434,26 @@ func (w *HTMLWriter) WriteDescriptiveListItem(di DescriptiveListItem) { w.WriteString("?") } w.WriteString("\n\n") - w.WriteString("
\n") - WriteNodes(w, di.Details...) + w.WriteString("
") + w.writeListItemContent(di.Details) w.WriteString("
\n") } +func (w *HTMLWriter) writeListItemContent(children []Node) { + if isParagraphNodeSlice(children) { + for i, c := range children { + out := w.WriteNodesAsString(c.(Paragraph).Children...) + if i != 0 && out != "" { + w.WriteString("\n") + } + w.WriteString(out) + } + } else { + w.WriteString("\n") + WriteNodes(w, children...) + } +} + func (w *HTMLWriter) WriteParagraph(p Paragraph) { if len(p.Children) == 0 { return @@ -585,6 +601,15 @@ func setHTMLAttribute(attributes []h.Attribute, k, v string) []h.Attribute { return append(attributes, h.Attribute{Namespace: "", Key: k, Val: v}) } +func isParagraphNodeSlice(ns []Node) bool { + for _, n := range ns { + if reflect.TypeOf(n).Name() != "Paragraph" { + return false + } + } + return true +} + func (fs *footnotes) add(f FootnoteLink) int { if i, ok := fs.mapping[f.Name]; ok && f.Name != "" { return i diff --git a/org/testdata/blocks.html b/org/testdata/blocks.html index 20c7746..a020dbc 100644 --- a/org/testdata/blocks.html +++ b/org/testdata/blocks.html @@ -68,12 +68,8 @@ note that /inline/ *markup* ignored

blocks like the quote block parse their content and can contain

diff --git a/org/testdata/footnotes.html b/org/testdata/footnotes.html index 4b6b9e4..cb9d7d5 100644 --- a/org/testdata/footnotes.html +++ b/org/testdata/footnotes.html @@ -12,25 +12,13 @@ Using some footnotes
    -
  • -

    normal footnote reference 1 2 3 (footnote names can be anything in the format [\w-])

    -
  • -
  • -

    further references to the same footnote should not 1 render duplicates in the footnote list

    -
  • -
  • -

    inline footnotes are also supported via 4.

    -
  • -
  • -

    anonymous inline footnotes are also supported via 5.

    -
  • -
  • -

    Footnote definitions are not printed where they appear. -Rather, they are gathered and exported at the end of the document in the footnote section. 6

    -
  • -
  • -

    footnotes that reference a non-existant definition are rendered but log a warning 7

    -
  • +
  • normal footnote reference 1 2 3 (footnote names can be anything in the format [\w-])
  • +
  • further references to the same footnote should not 1 render duplicates in the footnote list
  • +
  • inline footnotes are also supported via 4.
  • +
  • anonymous inline footnotes are also supported via 5.
  • +
  • Footnote definitions are not printed where they appear. +Rather, they are gathered and exported at the end of the document in the footnote section. 6
  • +
  • footnotes that reference a non-existant definition are rendered but log a warning 7
@@ -52,9 +40,7 @@ this is not part of

https://www.example.com

    -
  • -

    footnotes can contain markup

    -
  • +
  • footnotes can contain markup
  • and other elements

      diff --git a/org/testdata/footnotes_in_headline.html b/org/testdata/footnotes_in_headline.html index 1e69fbf..b9769d8 100644 --- a/org/testdata/footnotes_in_headline.html +++ b/org/testdata/footnotes_in_headline.html @@ -18,20 +18,12 @@ Title footnotes.add() transparently gets translated to (&footnotes).add() (docs).

      - -
    • -

      Headlines have to be htmlified twice - once for the outline and once for the headline itself. To do so we have to copy the writer

      -
    • -
    • -

      Copying the writer copies footnotes - which contains a map and a slice. Changes to the map will always be reflected in the original map. -Changes to the slice will only be reflected if the slice doesn't grow.

      -
    • -
    • -

      We can thus end up with a footnote being in the mapping but not the slice - and get an index out of range error.

      -
    • +
    • HTMLWriter.footnotes should be a pointer field. I didn't notice my error as go translated my pointer-method calls on +non-pointer values rather than complaining - i.e. footnotes.add() transparently gets translated to (&footnotes).add() (docs).
    • +
    • Headlines have to be htmlified twice - once for the outline and once for the headline itself. To do so we have to copy the writer
    • +
    • Copying the writer copies footnotes - which contains a map and a slice. Changes to the map will always be reflected in the original map. +Changes to the slice will only be reflected if the slice doesn't grow.
    • +
    • We can thus end up with a footnote being in the mapping but not the slice - and get an index out of range error.
    diff --git a/org/testdata/headlines.html b/org/testdata/headlines.html index a004144..1c72f22 100644 --- a/org/testdata/headlines.html +++ b/org/testdata/headlines.html @@ -22,17 +22,11 @@ Simple Headline [1/2]
      -
    • -

      checked

      -
    • -
    • -

      unchecked

      -
    • -
    • -

      note that statistic tokens are marked up anywhere +

    • checked
    • +
    • unchecked
    • +
    • note that statistic tokens are marked up anywhere not just where they are actually meant to be - even here > [100%] < -(Org mode proper does the same)

      -
    • +(Org mode proper does the same)
    diff --git a/org/testdata/inline.html b/org/testdata/inline.html index a58f2ab..61bedc9 100644 --- a/org/testdata/inline.html +++ b/org/testdata/inline.html @@ -1,115 +1,57 @@
      -
    • -

      emphasis and a hard line break
      +

    • emphasis and a hard line break
      see?
      -also hard line breaks not followed by a newline get ignored, see \\

      -
    • -
    • -

      .emphasis with dot border chars.

      -
    • -
    • -

      emphasis with a slash/inside

      -
    • -
    • -

      emphasis followed by raw text with slash /

      -
    • -
    • -

      ->/not an emphasis/<-

      -
    • -
    • -

      links with slashes do not become emphasis: https://somelinkshouldntrenderaccidentalemphasis.com/ emphasis

      -
    • -
    • -

      underlined bold verbatim code strikethrough

      -
    • -
    • -

      bold string with an *asterisk inside

      -
    • -
    • -

      inline source blocks like

      +also hard line breaks not followed by a newline get ignored, see \\
    • +
    • .emphasis with dot border chars.
    • +
    • emphasis with a slash/inside
    • +
    • emphasis followed by raw text with slash /
    • +
    • ->/not an emphasis/<-
    • +
    • links with slashes do not become emphasis: https://somelinkshouldntrenderaccidentalemphasis.com/ emphasis
    • +
    • underlined bold verbatim code strikethrough
    • +
    • bold string with an *asterisk inside
    • +
    • inline source blocks like
       <h1>hello</h1>
       
      -

      -
    • -
    • -

      inline export blocks

      hello

      -
    • -
    • -

      multiline emphasis is +

    • +
    • inline export blocks

      hello

    • +
    • multiline emphasis is supported - and respects MaxEmphasisNewLines (default: 1) so this -is emphasized

      -

      +is emphasized + /but this is -not emphasized/

      -
    • -
    • -

      empty emphasis markers like ++ // __ and so on are ignored

      -
    • -
    • -

      use _{} for subscriptsub and ^{} for superscriptsuper

      -
    • +not emphasized/ +
    • empty emphasis markers like ++ // __ and so on are ignored
    • +
    • use _{} for subscriptsub and ^{} for superscriptsuper
    • links

        -
      1. -

        regular link https://example.com link without description

        -
      2. -
      3. -

        regular link example.com link with description

        -
      4. -
      5. -

        regular link to a file (image) my-img.png

        -
      6. -
      7. -

        regular link to an org file (extension replaced with html) inline.html / ../testdata/inline.html

        -
      8. -
      9. -

        regular link to a file (video)

        -
      10. -
      11. -

        regular link to http (image) http://placekitten.com/200/200#.png

        -
      12. -
      13. -

        regular link to https (image) https://placekitten.com/200/200#.png

        -
      14. -
      15. -

        regular link with image as description https://placekitten.com/200/200#.png

        -
      16. -
      17. -

        regular link enclosed in [] [https://www.example.com] [example.com]

        -
      18. -
      19. -

        auto link, i.e. not inside \[[square brackets]\] https://www.example.com

        -
      20. +
      21. regular link https://example.com link without description
      22. +
      23. regular link example.com link with description
      24. +
      25. regular link to a file (image) my-img.png
      26. +
      27. regular link to an org file (extension replaced with html) inline.html / ../testdata/inline.html
      28. +
      29. regular link to a file (video)
      30. +
      31. regular link to http (image) http://placekitten.com/200/200#.png
      32. +
      33. regular link to https (image) https://placekitten.com/200/200#.png
      34. +
      35. regular link with image as description https://placekitten.com/200/200#.png
      36. +
      37. regular link enclosed in [] [https://www.example.com] [example.com]
      38. +
      39. auto link, i.e. not inside \[[square brackets]\] https://www.example.com
    • timestamps

        -
      • -

        <2019-01-06 Sun>

        -
      • -
      • -

        <2019-01-06 Sun>

        -
      • -
      • -

        <2019-01-06 Sun 18:00>

        -
      • -
      • -

        <2019-01-06 Sun 18:00 +1w>

        -
      • -
      • -

        <2019-01-06 Sun 18:00>

        -
      • -
      • -

        <2019-01-06 Sun 18:00 +1w>

        -
      • +
      • <2019-01-06 Sun>
      • +
      • <2019-01-06 Sun>
      • +
      • <2019-01-06 Sun 18:00>
      • +
      • <2019-01-06 Sun 18:00 +1w>
      • +
      • <2019-01-06 Sun 18:00>
      • +
      • <2019-01-06 Sun 18:00 +1w>
    • diff --git a/org/testdata/latex.html b/org/testdata/latex.html index 865baff..58bbb8a 100644 --- a/org/testdata/latex.html +++ b/org/testdata/latex.html @@ -1,27 +1,13 @@

      without latex delimiters the _{i=1} in \sum_{i=1}^n a_n is interpreted as subscript. we support \(...\), \[...\], $$...$$ and \begin{$env}...\end{$env} as latex fragment delimiters.

        -
      • -

        i=1^n a_n (without latex delimiter)

        -
      • -
      • -

        \(\sum_{i=1}^n a_n\)

        -
      • -
      • -

        \[\sum_{i=1}^n a_n\]

        -
      • -
      • -

        $$\sum_{i=1}^n a_n$$

        -
      • -
      • -

        \begin{xyz}\sum_{i=1}^n a_n\end{xyz}

        -
      • -
      • -

        \begin{xyz} +

      • i=1^n a_n (without latex delimiter)
      • +
      • \(\sum_{i=1}^n a_n\)
      • +
      • \[\sum_{i=1}^n a_n\]
      • +
      • $$\sum_{i=1}^n a_n$$
      • +
      • \begin{xyz}\sum_{i=1}^n a_n\end{xyz}
      • +
      • \begin{xyz} \sum_{i=1}^n a_n -\end{xyz}

        -
      • -
      • -

        $2 + 2$, $3 - 3$

        -
      • +\end{xyz} +
      • $2 + 2$, $3 - 3$
      diff --git a/org/testdata/lists.html b/org/testdata/lists.html index 83ab29c..6a514dc 100644 --- a/org/testdata/lists.html +++ b/org/testdata/lists.html @@ -1,36 +1,24 @@
        -
      • -

        unordered list item 1

        -
      • +
      • unordered list item 1
      • -

        + list item with empty first and second line
        -normally an empty line breaks the list item - but we make an exception for the first line and don't count it towards that limit

        -
      • +normally an empty line breaks the list item - but we make an exception for the first line and don't count it towards that limit
      • unordered list item 2 - with inline markup

        1. ordered sublist item 1

            -
          1. -

            ordered sublist item 1

            -
          2. -
          3. -

            ordered sublist item 2

            -
          4. -
          5. -

            ordered sublist item 3

            -
          6. +
          7. ordered sublist item 1
          8. +
          9. ordered sublist item 2
          10. +
          11. ordered sublist item 3
        2. +
        3. ordered sublist item 2
        4. -

          ordered sublist item 2

          -
        5. -
        6. -

          -list item with empty first and second line - see above

          -
        7. + +list item with empty first and second line - see above
      • @@ -85,23 +73,17 @@ descriptive lists

        term
        -
        -

        details -continued details

        -
        +
        details +continued details
        ?
        -
        -

        details without a term

        -
        +
        details without a term
        term
        -

        -details on a new line

        -
        +details on a new line
        term
        @@ -120,89 +102,51 @@ echo "Hello World!"

        some list termination tests

          -
        • -

          unordered 1

          -
        • -
        • -

          unordered 2

          -
        • +
        • unordered 1
        • +
        • unordered 2
          -
        1. -

          ordered 1

          -
        2. -
        3. -

          ordered 2

          -
        4. +
        5. ordered 1
        6. +
        7. ordered 2
          -
        1. -

          ordered 1

          -
        2. -
        3. -

          ordered 2

          -
        4. +
        5. ordered 1
        6. +
        7. ordered 2
          -
        • -

          unordered 1

          -
        • -
        • -

          unordered 2

          -
        • +
        • unordered 1
        • +
        • unordered 2
          -
        1. -

          ordered 1

          -
        2. -
        3. -

          ordered 2

          -
        4. +
        5. ordered 1
        6. +
        7. ordered 2
        unordered descriptive
        -
        -

        1

        -
        +
        1
        unordered descriptive
        -
        -

        2

        -
        +
        2
        ordered descriptive
        -
        -

        1

        -
        +
        1
        ordered descriptive
        -
        -

        2

        -
        +
        2
          -
        • -

          unordered 1

          -
        • -
        • -

          unordered 2

          -
        • +
        • unordered 1
        • +
        • unordered 2
          -
        1. -

          use `[@n]` to change the value of list items

          -
        2. -
        3. -

          foobar

          -
        4. -
        5. -

          that even works in combination with list statuses (`[ ]`)

          -
        6. +
        7. use `[@n]` to change the value of list items
        8. +
        9. foobar
        10. +
        11. that even works in combination with list statuses (`[ ]`)
        diff --git a/org/testdata/misc.html b/org/testdata/misc.html index 06ea147..40c8e00 100644 --- a/org/testdata/misc.html +++ b/org/testdata/misc.html @@ -274,21 +274,11 @@ jobs:
          -
        • -

          ndash –

          -
        • -
        • -

          mdash —

          -
        • -
        • -

          ellipsis …

          -
        • -
        • -

          acute Á and so on

          -
        • -
        • -

          note that —— is replaced with 2 mdashes and …. becomes ellipsis+. and so on - that's how org also does it

          -
        • +
        • ndash –
        • +
        • mdash —
        • +
        • ellipsis …
        • +
        • acute Á and so on
        • +
        • note that —— is replaced with 2 mdashes and …. becomes ellipsis+. and so on - that's how org also does it
        @@ -310,27 +300,19 @@ or that foo.

          -
        • -

          this list item +

        • this list item has multiple -linbreaks - but it's still just one paragraph (i.e. no line breaks are rendered)

          -
        • -
        • -

          foobar

          -
        • +linbreaks - but it's still just one paragraph (i.e. no line breaks are rendered) +
        • foobar
          -
        1. -

          same +

        2. same goes for ordered -lists

          -
        3. -
        4. -

          foo

          -
        5. +lists +
        6. foo
        @@ -364,9 +346,7 @@ lists

      • bullet 1

          -
        • -

          sub bullet

          -
        • +
        • sub bullet
      @@ -438,18 +418,12 @@ Bar

      just like #46

        -
      • -

        -- -> – (en dash)

        -
      • -
      • -

        --- -> — (em dash)

        -
      • +
      • -- -> – (en dash)
      • +
      • --- -> — (em dash)

      also, consecutive dashes inside

        -
      • -

        inline code -- --- and verbatim -- ---

        -
      • +
      • inline code -- --- and verbatim -- ---
      • src/example/export blocks should not be converted!

        @@ -579,9 +553,7 @@ list items don't end on child headline
          -
        • -

          a list item

          -
        • +
        • a list item
        @@ -589,9 +561,7 @@ followed by a child headline
          -
        • -

          followed by another list item

          -
        • +
        • followed by another list item
        @@ -612,12 +582,8 @@ Footnotes

        a footnote with markup

          -
        • -

          and a list

          -
        • -
        • -

          because that's possible

          -
        • +
        • and a list
        • +
        • because that's possible