typogr.js icon indicating copy to clipboard operation
typogr.js copied to clipboard

Work better with marked

Open runarberg opened this issue 11 years ago • 3 comments

This package doesn't work well with marked. Say I first run marked on a string of markdown, it will escape quotes to ' or &qout; which means typogr.smartypants won't typeset them. However if I first run typogr.smartypants on raw markdown it will change all underlined second headings to a series of em- and en-dashes, which the marked parser will subsequently miss.

I suggest we either leave lone dashes between newlines alone, or we typeset html encoded quotes along with ascii encoded ones (or even both so that the order of operation won't matter).

runarberg avatar Jan 25 '15 18:01 runarberg

@runarberg thanks for report. Would you be able to show an example for this issue?

ekalinin avatar Jan 26 '15 08:01 ekalinin

Sure

example.md

Some basic markdown
-------------------

This text *should* be "turned into" HTML with
[marked](https://github.com/chjj/marked)---a markdown parser and
compiler--- and beautifully typeset with
[typogr](https://github.com/ekalinin/typogr.js)...

...but it isn't.

index.js

var fs = require('fs');

var marked = require('marked');
var typogr = require('typogr');

var result = '<h2 id="some-basic-markdown-">Some basic markdown</h2>\n'
        + '<p>This text <em>should</em> be &#8220;turned into&#8221; <span class="caps">HTML</span> with\n'
        + '<a href="https://github.com/chjj/marked">marked</a>&#8212;a markdown parser and\n'
        + 'compiler&#8212; and beautifully typeset with\n'
        + '<a href="https://github.com/ekalinin/typogr.js">typogr</a>&#8230;</p>\n'
        + '<p>&#8230;but it isn&#8217;t.</p>';

fs.readFile('./example.md', function(err, text) {
    console.log("\ntext -> marked -> typogrify\n");
    var html = marked(String(text));
    console.log(typogr.typogrify(html));

    console.log("\ntext -> typogrify -> marked\n");
    var typeset = typogr.typogrify(String(text));
    console.log(marked(typeset));

    console.log("\nExpecting\n");
    console.log(result);
});

Output

$ node index.js

text -> marked -> typogrify

<h2 id="some-basic-markdown">Some basic markdown</h2>
<p>This text <em>should</em> be &quot;turned into&quot; <span class="caps">HTML</span> with
<a href="https://github.com/chjj/marked">marked</a>&#8212;a markdown parser and
compiler&#8212; and beautifully typeset with
<a href="https://github.com/ekalinin/typogr.js">typogr</a>&#8230;</p>
<p>&#8230;but it isn&#39;t.</p>


text -> typogrify -> marked

<p>Some basic markdown
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>This text <em>should</em> be &#8220;turned into&#8221; <span class="caps">HTML</span> with
<a href="https://github.com/chjj/marked">marked</a>&#8212;a markdown parser and
compiler&#8212; and beautifully typeset with
<a href="https://github.com/ekalinin/typogr.js">typogr</a>&#8230;</p>
<p>&#8230;but it isn&#8217;t.</p>


Expecting

<h2 id="some-basic-markdown-">Some basic markdown</h2>
<p>This text <em>should</em> be &#8220;turned into&#8221; <span class="caps">HTML</span> with
<a href="https://github.com/chjj/marked">marked</a>&#8212;a markdown parser and
compiler&#8212; and beautifully typeset with
<a href="https://github.com/ekalinin/typogr.js">typogr</a>&#8230;</p>
<p>&#8230;but it isn&#8217;t.</p>

runarberg avatar Jan 26 '15 10:01 runarberg

I had the same issue - I fixed it by using the smartypants option in marked (which does the same thing as the smartypants option in typogr).

colophonemes avatar Mar 07 '15 20:03 colophonemes