dart-markdown compatibility with markdown.js

已查看 90 次
跳至第一个未读帖子

Anders Holmgren

未读,
2014年7月20日 23:27:532014/7/20
收件人 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

未读,
2014年7月21日 05:02:522014/7/21
收件人 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

未读,
2014年7月21日 05:06:372014/7/21
收件人 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

未读,
2014年7月21日 12:27:382014/7/21
收件人 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

未读,
2014年7月21日 18:42:272014/7/21
收件人 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

未读,
2014年7月21日 19:26:232014/7/21
收件人 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

回复全部
回复作者
转发
0 个新帖子