dart-markdown compatibility with markdown.js

90 views
Skip to first unread message

Anders Holmgren

unread,
Jul 20, 2014, 11:27:53 PM7/20/14
to mi...@dartlang.org
I'm porting some code from js land to dart and to make sure I'm producing a compatible version I have unit tests that compare what I produce with what the js version produces.

All fine until I hit fields that are in markdown. For these the js code runs markdown.js (with default settings) over the fields.
I run dart-markdown markdownToHtml on them.

Other than newline differences around generated html (which is annoying in my diffs but understandable), the main pain point is that the dart version is escaping the html tags but the js one doesn't

At least I have seen that <p/> is being escaped to &lt;p/>

Are there any flags that turn off that escaping?

Any flags that cause the generated html to be prettyfied e.g.

the dart version outputs
<ul><li><a href=".....>Blah locations</a></li><li><a href="...">Foo locations</a></li></ul>',

where the js one outputs

<ul>
<li><a href=".....>Blah locations</a></li>
<li><a href="...">Foo locations</a></li><
/ul>',

cheers
Anders

Justin Fagnani

unread,
Jul 21, 2014, 5:02:52 AM7/21/14
to General Dart Discussion
It looks like markdown only escapes tags in code or links. Is that where you're seeing the difference?

As for pretty-printing, your best best might be to parse the HTML with html5lib and either normalize or compare structurally. That way you can easily ignore whitespace differences.


--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Anders Holmgren

unread,
Jul 21, 2014, 5:06:37 AM7/21/14
to mi...@dartlang.org
Thanks Justin

I'll have to take a closer look tomorrow to see if you're right about where the escaping occurs. 

I love the html5lib suggestion. Much prefer that over a text diff.

Cheers
A

Bob Nystrom

unread,
Jul 21, 2014, 12:27:38 PM7/21/14
to General Dart Discussion
Assuming this corner of the Dart markdown library hasn't changed since I last touched it, then it doesn't support inline HTML and will escape all of it. This is intentional, but it does indeed make it different with other markdown libraries.

- bob

Anders Holmgren

unread,
Jul 21, 2014, 6:42:27 PM7/21/14
to mi...@dartlang.org
Hi Bob

Is the escaping for potential xss protection or some other reason?

In my case I'm processing our json schemas into a form that is served out via harp.js. The schemas are generated from java classes where the javadocs are in markdown including HTML markup. So we don't have any xss concerns.

Would it be hard to expose a flag that would disable the escaping?

At the moment I am post processing the generated output from dart markdown and replacing &lt; with < which works but is rather dodgy and brittle.

Cheers
Anders

Bob Nystrom

unread,
Jul 21, 2014, 7:26:23 PM7/21/14
to General Dart Discussion
On Mon, Jul 21, 2014 at 3:42 PM, Anders Holmgren <andersm...@gmail.com> wrote:
Hi Bob

Is the escaping for potential xss protection or some other reason?

Partially, it also makes parsing much simpler. This is an area where other markdown engines aren't consistent either. For example, should markdown inside an inline HTML tag be parsed? How do mixed markdown tags that span HTML tags get interpreted? Stuff like *<strong>*</strong>.

I should clarify that is only about inline—as in in the middle of a paragraph—HTML. Paragraph-level HTML is passed through. If you have a chunk of HTML with a blank line above and below it, it should be passed through unchanged.
 
Would it be hard to expose a flag that would disable the escaping?

Maybe, but I'm not the right person to ask. I don't maintain this any more. (Not that I wouldn't like to, I just have too many other things going on.)

Cheers,

- bob
 

At the moment I am post processing the generated output from dart markdown and replacing &lt; with < which works but is rather dodgy and brittle.

Cheers
Anders

Reply all
Reply to author
Forward
0 new messages