Question

Using snap, I wrote a splice creating text from markdown, using this function:

markdownToHTML :: T.Text -> [Node]
markdownToHTML = renderHtmlNodes . (writeHtml writeOpts) . readMarkdown readOpts . T.unpack
    where
        readOpts = defaultParserState
        writeOpts = defaultWriterOptions
            { writerStandalone = False
            , writerHtml5 = True
            , writerStrictMarkdown = False
            }

Now, when I, for example, give it this markdown

# Hi

Lorem ipsum something somthing

# Stuff

[a link](http://twitter.com/)

It produces this HTML:

<h1 id='hi'>Hi
</h1>
<p>
 Lorem ipsum something somthing

 # Stuff

 <a href='http://twitter.com/'>a link</a></p>

No matter how many newlines I put before the #, it is still just wedged into the paragraph.

Funnily enough, if I dump the same markdown into pandoc's demo site, it produces the correct Html output.

The full code of my project can be found here, if necessary.

Was it helpful?

Solution

See the documentation for Text.Pandoc. It says:

Note: all of the readers assume that the input text has '\n' line endings. So if you get your input text from a web form, you should remove '\r' characters using filter (/='\r').

I suspect that's your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top