markedjs / marked Goto Github PK
View Code? Open in Web Editor NEWA markdown parser and compiler. Built for speed.
Home Page: https://marked.js.org
License: Other
A markdown parser and compiler. Built for speed.
Home Page: https://marked.js.org
License: Other
As you know from my ticket, contneditables will convert spaces to \u00a0
. From: http://www.fileformat.info/info/unicode/char/A0/index.htm
It's decomposition is actually a \u0020
, or, a space. It'd be nice if Marked checked for both of those characters since they mean almost the same thing. I can't imagine someone wanting to keep a no-break space but convert spaces.
Thoughts?
% Markdown.pl
\>
^ID
<p>></p>
% ../marked/bin/marked
\>
<p>\>
</p>
Github understands ``` as block comments:
``` javascript
var a = 2;
console.log(a);
```
will produce
var a = 2;
console.log(a);
It would be nice to make marked
understand such blocks. That's significant sometime, when you like to use existing readme in generated docs.
I see on line 506, in parse(), you separate tokens with a space which makes viewing the rendered HTML source really hard to read. If you could change that single space to a newline then it makes all the difference and is no more or less efficient in bandwidth as the resulting filesize is the same.
- return out.join(' ');
+ return out.join('\n');
Curious about how this compares to
https://github.com/visionmedia/node-discount
Either way, I like yours because I was able to install it, no C-compiling, yay!
Also, I like that GFM is on your roadmap :)
(Hopefully you can do the newer version that they use on the site, but if not that's cool too).
Cheers and thanks for working code!
D
The Markdown formatting syntax should not be processed within block-level HTML tags, according to http://daringfireball.net/projects/markdown/syntax
% ../marked/bin/marked
*test **test***
<p><em>test *</em>test<em>*</em>
</p>
Of course it is arguable what counts as proper, since the standard is so vague. But I would expect (and good markdown implementations provide):
<p><em>test <strong>test</strong></em></p>
Think i figured it out. Marked doesn't know what to do with literal \n
like this:
marked('hello \
world');
I think this is in fact a bug with Marked since in this example, native JSON.parse
will convert that and to get it to work with Marked we'd have to go and add \n
(the text, not literal) in place of it. What do think?
Thanks for the excellent md parser!
There are a bunch of various extensions to markdown
eg
http://freewisdom.org/projects/python-markdown/Extra
http://michelf.com/projects/php-markdown/extra/
http://maruku.rubyforge.org/proposal.html
While not all are exactly critical, things like super/subscript, tables, definition lists, abbreviations can go a long way to make writing md documents easier.
Also simple transformations (like texttile http://rpc.textpattern.com/help/?item=intro) can make the text much more readable
For example
... -> …
' ' -> ‘ ’
" " -> “ ”
-- -> –
(c) -> ©
(r) -> ®
and so on .
Ideally the goal should be to never write pure html for any typographical feature.
% ../marked/bin/marked
<div style=">"/>
^D
<p><div style=">"/>
</p>
Hi!
If output from marked
is fed further to syntax highlighter (say, [https://github.com/andris9/highlight]) the resulting output contains html entities codes instead of symbols.
Wonder if you could make call to escape()
optional, or, better, make escape
configurable from outside function.
update: marked.escape
would fit perfectly, i believe.
TIA,
--Vladimir
Would it be possible to have the option of adding no follow for all output anchor tags?
If this is relatively trivial to add, it would be nice.
Otherwise, it's not that important and I could just hack it directly onto the links.
Just wanted to let you know that we're using marked for previewing markdown on http://prose.io. In case you want to link to in-the-wild-examples. :)
Here's an example doc, rendered by marked.
http://prose.io/#substance/text/blob/gh-pages/README.md
Thank you! :)
I'm really surprised to see that marked
will not filter out the <script>
tag, and there's not an option to do it. If a website uses marked
on its comment system, then this can be a very severe security issue. And the unfiltered style
attribute for html tags can also be used by malicious visitors to make the site dysfunctional.
So, I wonder if there's a plan to add in options for safe parsing ?
And another problem: the lexer fails for the following case (the type should be html
, not paragraph
IMO)
> m.lexer('<script>document.write(\'Oops\')</script><br>')
[ { type: 'paragraph',
text: '<script>document.write(\'Oops\')</script><br>' },
links: {} ]
Test case:
> marked.parse('<p>Already linked: <a href="http://foo.com">http://foo.com</a> </p>')
'<p>Already linked: <a href="http://foo.com"><a href="http://foo.com</a>">http://foo.com</a></a> </p>'
This is quite common when a bit of markdown contains some inline HTML.
A simple workaround that is probably not ideal or free of edge case failures:
result = result.replace(/<a href="([^"]+)<\/a>">\1<\/a>/, '$1');
% Markdown.pl
> hi there
bud
<blockquote>
<p>hi there
bud</p>
</blockquote>
% ../marked/bin/marked
> hi there
bud
<blockquote><p> hi there</p></blockquote>
<p>bud
</p>
The handling of multiple underscores in words is not consistent. github_flavored_markdown handles this differently than the original MarkDown syntax, so does marked. Try this:
perform_complicated_task
do_this_and_do_that_and_another_thing
This bug affects prose/prose#146 see there for how to reproduce it.
I've been doing a few tests with marked, and I've found that if I feed it large documents with embedded HTML (or plain HTML alone), it will crash Chrome Renderer.
I've been able to reproduce this reliably by force-feeding it raw HTML - notably the contents of the container div at http://oss.sapo.pt/ (which I'm re-doing using marked, BTW - you'll notice the site currently fetches Markdown and parses it on the fly using showdown...).
Further testing reveals that Safari and Firefox are immune to this, BTW - I can toss in the same documents and they come out fine.
by itself,
#### *expression<sub>1</sub>* *expression<sub>2</sub>* ... *expression<sub>n</sub>*
renders correctly as
<h4><em>expression<sub>1</sub></em> <em>expression<sub>2</sub></em> ... <em>expression<sub>n</sub></em></h4>
but in the context of https://raw.github.com/dmajda/pegjs/master/README.md renders as
<h4><em>expression<sub>1</sub></em> / <em>expression<sub>2</sub></em> / ... / <em>expression<sub>n</sub></em></h4>
maybe a parser issue?
thanks!
Part of the Github Flavored Markdown is to support output of links that will link to users, commit sha's, repo, and issues. This is my understanding, when reading through showdown.js which is included in 'github-flavored-markdown' available on NPM. Do you have any plan for the future to add these features to the parser?
Example:
[Test](http://google.com "Google (Test)")
... should be:
It doesn't work in GitHub's markdown parser too (Redcarpet), but it works in other markdown parsers like Showdown (JS) and RDiscount (Ruby).
If text have 2 empty lines after block quote, then empty line is attached to quoted text after rendering. That should not happen.
% ../marked/bin/marked
\\[test](not a link)
^D
/Users/jgm/src/marked/lib/marked.js:386
href: text[1],
^
TypeError: Cannot read property '1' of null
at Object.lexer (/Users/jgm/src/marked/lib/marked.js:386:19)
at /Users/jgm/src/marked/lib/marked.js:578:18
at /Users/jgm/src/marked/lib/marked.js:606:14
at /Users/jgm/src/marked/lib/marked.js:652:10
at write (/Users/jgm/src/marked/bin/marked:111:9)
at ReadStream.<anonymous> (/Users/jgm/src/marked/bin/marked:101:7)
at ReadStream.emit (events.js:61:17)
at ReadStream._onReadable (net.js:652:51)
at IOWatcher.onReadable [as callback] (net.js:177:10)
% ../marked/bin/marked
[the `]` character](/url)
<p>[the <code>]</code> character](/url)
</p>
Markdown.pl's behavior is more intuitive:
% Markdown.pl
[the `]` character](/url)
<p><a href="/url">the <code>]</code> character</a></p>
The syntax doc is explicit on this. Many implementations don't notice.
% Markdown.pl
[hi]
[hi]: /url (there)
<p><a href="/url" title="there">hi</a></p>
% ../marked/bin/marked
[hi]
[hi]: /url (there)
<p>[hi]
</p>
<p>[hi]: /url (there)
</p>
Any chance you could add support for strikethrough? I know it's not in the official Markdown spec but it's something I need for my application.
We need to extend marked with [[reference]]
syntax, that woud work in the same way, like highlight (via external function call)
https://github.com/nodeca/ndoc/blob/master/syntax.md#short-links
Could you explain, how to monkeypatch marked, to add this inline tag?
[http://www.facebook.com/developers/](http://www.facebook.com/developers/)
gives
<p><a href="http://www.facebook.com/developers/"><a href="http://www.facebook.com/developers/">http://www.facebook.com/developers/</a></a></p>
should be
<p><a href="http://www.facebook.com/developers/">http://www.facebook.com/developers/</a></p>
I'm using marked together with highlight.js, but there's a bit of snag: highlight.js (and/or its styles) requires the plain name of the language (like "python"
) as a class on the <code>
tag, but marked uses class names that look like "lang-python"
. I hacked around this in my copy of marked.js by adding the class name -- you can see the change here -- but it'd be nicer if marked let me specify additional/alternative class names.
I suggest that options.highlight()
be allowed (optionally -- use a type check) to return an object that has two properties: the code string (i.e., what is returned now) and an array of class names to be applied. I can certainly code it and submit a pull request, if desired.
(For completeness: I could alternatively ask highlight.js to make the class names it expects be configurable. But it's not clear how to do that in any sane way -- the classes are explicit in the CSS. Making the change in marked feels like the correct approach anyway.)
Thanks for the great tool. It was utterly essential in the development of my Markdown-email browser extension.
The popularity of Markdown has lead to several syntax variants extending the original Markdown syntax. Marked currently supports github_flavored_markdown. In adition there is at least Pandoc's markdown and StackExchange Markdown. The latter should be easy to implement, to support [tag:foo]
links. Pandoc markdown may be more difficult but more useful too. See gitit for a use case. Maybe additional syntax variants are something for a 1.0 release?
It would be nice to be able to have the "highlight" callback function return asynchronously, as it's the only way to integrate with something like pygments
. I realize that this means that marked
itself would have to have a new API that returns asynchronously, but that's probably ok. Thoughts?
it looks like a strong/em is incorrectly parsed out of the ascii flower <pre>
element here:
https://github.com/mojombo/github-flavored-markdown/blob/gh-pages/_site/sample_content.md
vs raw:
https://raw.github.com/mojombo/github-flavored-markdown/gh-pages/_site/sample_content.md
what's interesting is that Github's own parser seems to trip up on the same thing. i don't believe this should be happening so maybe it's a bug?
php-markdown parses it correctly though.
thanks!
GFM line breaks are not supported :
Line 1
Line 2
Sould be rendered as
Line 1<br/>Line 2
When the gfm flag is set to true.
I have run across a slight problem with marked when trying to render html with line breaks between the attributes:
<input type="text"
name="email"
value=""
id="email-input"
class="etc" />
I know this is not a normal use case but as far as I know it is valid html, I am willing to submit a patch if I can get some pointers on where/ how to modify this behavior.
I.e.
First Header | Second Header
------------ | -------------
Content Cell | Content Cell
Content Cell | Content Cell
becomes
First Header | Second Header |
---|---|
Content Cell | Content Cell |
Content Cell | Content Cell |
I've been using marked for a while, but today I was doing cross-platform test and I noticed that Firefox crashed when marked tried to parse my *.md file. Firefox just crash. I test it in chrome (still on windows XP) and it works fine. Also I test it on Firefox (Windows 7) and works fine. I don't know what is the main problem in here.
ps. Firefox v6.0
Read the syntax document's explanation of code spans carefully - it's a bit more complicated than marked seems to assume.
% Markdown.pl
````` hi ther `` ok ``` `````
<p><code>hi ther `` ok ```</code></p>
% ../marked/bin/marked
````` hi ther `` ok ``` `````
<p><code>`</code> hi ther <code> ok </code><code> </code>````
</p>
Sometimes you do not want to parse and convert all markdown into html.
Maybe someone do not want links,etc. to be parsed. node-discount does it this way.
Kind regards
It would be great if you somehow could access the inline lexer.
One example where this would be useful is to transform relative urls to absolute.
for token in tokens
if token.type is 'link' and is_relative(token.href)
token.href = base + token.href
When "loose" lists, as they're called (lists with their items separated by 2 line feeds), get implemented, it introduces some ambiguity to parsing. This is a bit of a problem with the markdown grammar itself.
* List 1
Text
* List 1
Text
* Loose List 1
Text
* Loose List 1
Text
What is that? Is it 2 separate lists? One tight, one loose? Is it three lists? One with 2 items, and 2 with one item? Is it a single list with the items spaced differently? The only solution I see, is to actually always separate consecutive lists by 3 line feeds:
* List 1
Text
* List 1
Text
* Loose List 1
Text
* Loose List 1
Text
Which would be rendered as 2 lists: one tight, one loose. This is probably what will happen once I merge the experimental branch.
As specified in the syntax document, and demonstrated thus:
% Markdown.pl
[hi]
[HI]: /url
<p><a href="/url">hi</a></p>
Hi,
Would it be possible for you to mark tables using "table" instead of "paragraph" at the lexer? This would make my work a lot easier. I use your lexer to apply some custom transformations to the source and then output as HTML using your parser. Having tables marked properly would make my life a lot easier. :)
It appears to be an inconsistency in how marked handles single line conversions of headings.
If I have the following test.js
:
var marked = require('marked');
console.log(marked('# title'));
I would expect the output to be <h1>title</h1>
, but I get:
$ node test.js
<p># title</p>
If I however do the following:
$ marked -o test.html
# title
^D
I get:
$ cat test.html
<h1>title</h1>
Which is correct.
If I change my test.js
to the following:
var marked = require('marked');
console.log(marked('# title\n\ntest'));
It works properly:
$ node test.js
<h1>title</h1>
<p>test</p>
The markdown syntax document is pretty explicit that the marker doesn't matter:
% ../marked/bin/marked
* test
+ test
- test
<ul><li>test <ul><li>test <ul><li>test </li></ul></li></ul></li></ul>
% Markdown.pl
* test
+ test
- test
<ul>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>
GitHub flavored markdown supports syntax highlighted code like this:
/* comment */
var s = "string", i = 123;
function foo () {
for (var x in xs) {
console.log(x, xs[x]);
}
}
This is not supported by marked. It should either state this or (better) implement it.
I would expect the following input:
* list
* list
* list
1. list
2. list
3. list
To produce an unordered list followed by an ordered list, but instead it produces a single unordered list (with a bit of funky spacing). Inserting an extra line break between the two resolves the issue.
GitHub handles this case as expected.
missing <br> and <hr> respectively
GitHub's code fences should output a pre
element and not a code
element, you can see that at the first lines of http://github.github.com/github-flavored-markdown/
Btw, thanks for an awesome module. It was a huge advantage to be able to use marked instead of other, more limited JavaScript Markdown parsers for my StyleDocco project.
I'm not sure whether this is a bug in marked or a symbol I need to escape, but parsing:
### Something [blabla](#/bla) is *great*.
results in a new paragraph starting and the header ending on the # in #/bla and doesn't give me a link (to #/bla) in the header.
Thanks for marked, I'm using it in coffeekup in a zappa project and it's awesome to parse markdown so easily.
Input:
**v0.1.3** _(16 Apr 2012)_
* Removed `getFileName()` internal function.
**v0.1.2** _(15 Apr 2012)_
* The property value is now converted to a string before persisting.
**v0.1.1** _(15 Apr 2012)_
* Now it's possible to add comments for each key-value pair. A header comment can also be added.
**v0.1.0** _(15 Apr 2012)_
* First commit.
Output:
<p><strong>v0.1.3</strong> <em>(16 Apr 2012)</em>
</p>
<ul>
<li><p>Removed <code>getFileName()</code> internal function.</p>
<p><strong>v0.1.2</strong> <em>(15 Apr 2012)</em></p>
</li>
<li><p>The property value is now converted to a string before persisting.</p>
<p><strong>v0.1.1</strong> <em>(15 Apr 2012)</em></p>
</li>
<li><p>Now it's possible to add comments for each key-value pair. A header comment can also be added.</p>
<p><strong>v0.1.0</strong> <em>(15 Apr 2012)</em></p>
</li>
<li><p>First commit.</p>
</li>
</ul>
Expected:
<p><strong>v0.1.3</strong> <em>(16 Apr 2012)</em></p>
<ul>
<li><p>Removed <code>getFileName()</code> internal function.</p>
</li>
</ul>
<p><strong>v0.1.2</strong> <em>(15 Apr 2012)</em></p>
<ul>
<li><p>The property value is now converted to a string before persisting.</p>
</li>
</ul>
<p><strong>v0.1.1</strong> <em>(15 Apr 2012)</em></p>
<ul>
<li><p>Now it's possible to add comments for each key-value pair. A header comment can also be added.</p>
</li>
</ul>
<p><strong>v0.1.0</strong> <em>(15 Apr 2012)</em></p>
<ul>
<li><p>First commit.</p>
</li>
</ul>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.