Parsing Markdownd from WYSIWYG code editor

17 views
Skip to first unread message

Riccardo Sirigu

unread,
Jan 13, 2017, 10:41:11 AM1/13/17
to Lift
Hi everybody,

I'm using a markdown editor to allow users some control over the formatting of the text they enter.

I subclassed Transformer to add two decorators to disable img and links.

The Transformer produces a String and not a NodeSeq, so when I try to render the text, I see all the html unparsed.

I solved using "#desc" #> Unparsed(new MyMarkdownParser().apply(activityDescription))


Is there a better way to do it?
Thank you

Antonio Salazar Cardozo

unread,
Jan 13, 2017, 2:30:40 PM1/13/17
to Lift
Unfortunately right now there isn't (well, you can parse the string into XML
yourself first). It would definitely be nice to shift the Markdown parser to
parse into first-class NodeSeqs instead of into an HTML string, though.
Thanks,
Antonio

Torsten Uhlmann

unread,
Jan 14, 2017, 5:24:36 AM1/14/17
to Lift
It's not much different but uses Lift's parser, you could do something like this:

import net.liftweb.util

PCDataXmlParser(new MyMarkdownParser().apply(activityDescription)).openOr(NodeSeq.Empty)

It tries to render valid XML and will return an empty Box if that fails.

Torsten.

Riccardo Sirigu

unread,
Jan 16, 2017, 3:27:11 AM1/16/17
to Lift
Thank you guys

Antonio Salazar Cardozo

unread,
Jan 16, 2017, 12:41:50 PM1/16/17
to Lift
You got it!
Reply all
Reply to author
Forward
0 new messages