snoyberg / markdown

Convert Markdown to HTML, with XSS protection
BSD 3-Clause "New" or "Revised" License
69 stars 401 forks source link

Lists (ordered & unordered) don't use the correct internal Type #36

Open cimmanon opened 7 years ago

cimmanon commented 7 years ago

I'm attempting to use this library with Heist by passing the results from the markdown function through xmlhtml's renderHtmlNodes.

import Text.Markdown (markdown, defaultMarkdownSettings, msXssProtect)
import Text.Blaze.Renderer.XmlHtml (renderHtmlNodes)

renderHtmlNodes $ markdown defaultMarkdownSettings { msXssProtect = False } "# Title\n\n* one\n* two (*foo*)\n"

The results are pretty close to what I would expect except for one little problem: the opening and closing tags for the unordered list are in a TextNode:

[Element {elementTag = "h1", elementAttrs = [], elementChildren = [TextNode "Title"]}
,TextNode "<ul>"
,Element {elementTag = "li", elementAttrs = [], elementChildren = [TextNode "one"]}
,Element {elementTag = "li", elementAttrs = [], elementChildren =
    [TextNode "two ("
    ,Element {elementTag = "i", elementAttrs = [], elementChildren = [TextNode "foo"]}
    ,TextNode ")"
    ]}
,TextNode "</ul>"
]

The correct output should look like this:

[Element {elementTag = "h1", elementAttrs = [], elementChildren = [TextNode "Title"]}
,Element {elementTag = "ul", elementAttrs = [], elementChildren =
    [Element {elementTag = "li", elementAttrs = [], elementChildren = TextNode "one"]}
    ,Element {elementTag = "li", elementAttrs = [], elementChildren =
        [TextNode "two ("
        ,Element {elementTag = "i", elementAttrs = [], elementChildren = [TextNode "foo"]}
        ,TextNode ")"
        ]}
    ]}
]

The results are the same for both ordered and unordered lists.

snoyberg commented 7 years ago

This isn't a use case I've designed the library to address, but if you'd like to send a PR that keeps the output the same but makes the structure more to your liking, I'm open to it.

On Sun, Sep 17, 2017 at 8:01 PM, cimmanon notifications@github.com wrote:

I'm attempting to use this library with Heist by passing the results from the markdown function through xmlhtml's renderHtmlNodes.

import Text.Markdown (markdown, defaultMarkdownSettings, msXssProtect)import Text.Blaze.Renderer.XmlHtml (renderHtmlNodes)

renderHtmlNodes $ markdown defaultMarkdownSettings { msXssProtect = False } "# Title\n\n one\n two (foo)\n"

The results are pretty close to what I would expect except for one little problem: the opening and closing tags for the unordered list are in a TextNode:

[Element {elementTag = "h1", elementAttrs = [], elementChildren = [TextNode "Title"]} ,TextNode "

    " ,Element {elementTag = "li", elementAttrs = [], elementChildren = [TextNode "one"]} ,Element {elementTag = "li", elementAttrs = [], elementChildren = [TextNode "two (" ,Element {elementTag = "i", elementAttrs = [], elementChildren = [TextNode "foo"]} ,TextNode ")" ]} ,TextNode "
" ]

The correct output should look like this:

[Element {elementTag = "h1", elementAttrs = [], elementChildren = [TextNode "Title"]} ,Element {elementTag = "ul", elementAttrs = [], elementChildren = [Element {elementTag = "li", elementAttrs = [], elementChildren = TextNode "one"]} ,Element {elementTag = "li", elementAttrs = [], elementChildren = [TextNode "one"]} ,Element {elementTag = "li", elementAttrs = [], elementChildren = [TextNode "two (" ,Element {elementTag = "i", elementAttrs = [], elementChildren = [TextNode "foo"]} ,TextNode ")" ]} ]} ]

The results are the same for both ordered and unordered lists.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/snoyberg/markdown/issues/36, or mute the thread https://github.com/notifications/unsubscribe-auth/AADBBw81lZD6nC20VFBhQT78pkizZ4pxks5sjVBggaJpZM4PaNTb .