evilstreak / markdown-js Goto Github PK
View Code? Open in Web Editor NEWA Markdown parser for javascript
A Markdown parser for javascript
Hi, Dominic
I hope there would be a reference to guibe me dealing with markdownTree result. So I can write my renderers targetting at other format, instead of HTML.
Thanks.
The the sample case of ***foo bar***
fails to parse correctly.
It should be parsed as ["em", ["strong", "foo bar"]]
but is instead parsed as [["strong", "*foo bar"], "*"]
.
However if spaces are added (* **foo** *
), it produces the correct HTML.
Currently
console.log( require( "markdown" ).parse( 'heelo' ) );
will produce this:
<b>heelo</b>
Is this normal?
Minimal repro:
> a
> b
> c
This generates output that looks like <blockquote><p>a</p><p>bundefined> c</p></blockquote>
in the DOM.
i run the first example(with a textarea) on the latest chrome。 Blockquotes, code , code fencing don't wok out complete style. TX
Is is possible to have the hyperlink open in a new window?
Version v0.3.0 appeared on npm, but now the current version there is back to 0.2.1
would be really nice, and bring it closer to the discount implementation
There's a debug code in md2html.js that I found. Removed it in my pull request. Have fun.
It complains about line 152 in markdown.js
.
if ( ( m = (/^(\s*\n)/)(input) ) != null ) {
It doesn't like that calling of an expression as it were a function.
Ideas? Is this meant to work in the browser? Thanks
The Gruber dialect "![" handler can output an img_ref which is intended to be converted when forming the HTML tree, but there is no code in place to do so.
THe regexp in function link() :
/^\[([\s\S]*?)\][ \t]*\([ \t]*(\S+)(?:[ \t]+(["'])(.*?)\3)?[ \t]*\)/
is triggered by :
[to put it another way][SECTION 1] or even [link this](#SECTION-1)
outputs :
["[to put it another way][SECTION 1] or even [link this](#SECTION-1)", "to put it another way][SECTION 1]or even [link this", "#SECTION-1", undefined, undefined]
Instead, using :
/^\[([^\[\]]*?)\][ \t]*\([ \t]*(\S+)(?:[ \t]+(["'])(.*?)\3)?[ \t]*\)/
fixes the issue.
[![alt](src "title")](link)
should also be able to only be
[![alt](src)](link)
Hi,
NPM can not install markdown-js:
Error: Not found: markdown-js@'>=0.1.0'
Did you added your module to npm?
It would be easier to get acquainted with this package if package.json
was set up to support running the test suite with npm test
. I'm interested in coding this up myself but I haven't started yet.
.
This text: foo [bar] baz
parses as:
[ 'markdown',
[ 'para',
'foo ',
[ 'link_ref', { ref: 'bar', original: '[bar]' }, 'bar' ],
' baz' ] ]
The original markdown outputs <p>foo [bar] baz</p>
which is more like what I'd expect—it's not really a link. I can't find the single [foo]
as valid syntax in the Markdown spec, so I assume this is a bug...
These two libraries seem to have almost the same amount of popularity, As a new user, what differences should I know about?
Other lib:
https://github.com/chjj/marked
Sorry, the "overlay" functionality had to go for various reasons.
Any chance that you could move the "main" field to the top-level, and rename the package "markdown" instead of "markdown-js"?
The following is interpreted as an hr abutting a list, and then throws. (I was hoping for a heading not an hr, obviously.)
1. First
2. Second
1. First
--------
Backtrace, from 4816d73:
markdown.js:370
jsonml.unshift.apply( jsonml, this.processBlock( m[ 1 ], [] ) );
^
TypeError: Object #<an Object> has no method 'processBlock'
at Object.horizRule (markdown.js:370:44)
at Markdown.<anonymous> (markdown.js:620:41)
at Markdown.processBlock (markdown.js:197:29)
at Markdown.toTree (markdown.js:234:20)
at Object.parse (markdown.js:66:13)
at Object.toHTMLTree (markdown.js:97:48)
at Object.toHTML (markdown.js:79:22)
This is a meta-issue, just wondering if you'd be willing to use the yuidoc format. I've wrapped this module in a YUI wrapper, but I'd like to also be able to generate standard documentation.
The format is quite easy and very clean, plus it has really great output.
You can read up on it here: http://yui.github.com/yuidoc/
The change is pretty minimal, and is just in formatting. Here is an example:
/**
Take markdown (either as a string or as a JsonML tree) and run it through
[[toHTMLTree]] then turn it into a well-formated HTML fragment.
@method toHTML
@static
@param source {String} markdown string to parse
@param dialect {String} dialect to use
**/
If open, please let me know and I'll submit a pull request with the documentation updated and an example YUIDoc page generated (which will be on my gallery module, which you can see at http://j.shirley.im/tech/yui/gallery-markdown/)
Thanks,
-Jay
following lines will produce a horizontal rule:
fsfsfsf
* * *
***
*****
- - -
---------------------------------------
There's markdown and node-markdown, but not markdown-js.
js: warning: "markdown.js", line 925: Assignment to undeclared variable i
js: warning: "markdown.js", line 936: Assignment to undeclared variable i
Love this tool! I've got a parser that scans my markdown and generates a Table of Contents based on headers. However, markdown.js doesn't have the ability (that I can find) to output an html anchor.
I've hacked it to work for me by modifying the render_tree function, but it's suboptimal. I'd like to either a) simply place a token in my code that would get turned into an html anchor or b) figure out how to escape literal html in my markdown.
It'd be great if an owner could suggest the proper way to implement this, and if a feature is needed I'll happily fork and fix.
Code blocks in lists do not work. Example:
This is a paragraph:
* **Heading 1**
Paragraph.
JavaScript();
* **Heading 2**
Paragraph.
JavaScript();
JavaScript();
Paragraph.
I took a look at the code but that part is pretty involved. Hoping someone more familiar with it can fix it.
i use this, it works quite nice.
// get markdown content
var body_location = 'markdown/README.markdown';
function getText(myUrl){
var result = null;
$.ajax( { url: myUrl,
type: 'get',
dataType: 'html',
async: false,
success: function(data) { result = data; }
}
);
FileReady = true;
return result;
}
var markdown_source = getText(body_location);
// convert markdown to html
var output = markdown.toHTML( markdown_source );
document.write(output);
The following markdown results in the last items of the lists having a stray <p>
tag created:
1. **Mode**
The following modes are available:
* 0 = Port Off
* 232 = RS232 (handshaking determined via the <FlowControl> setting)
* 485H = Half-duplex RS485
* 4XXF = Full-duplex RS485 or RS422
1. **BaudRate**
The following baud rates are available:
* 100
* 300
* 600
* 1200
* 2400
* 4800
* 9600
* 14400
* 19200
* 38400
* 57600
* 115200
* 128000
* 256000
1. **DataBits**
The following data bits are available:
* 8 = 8 Data Bits
1. **Parity**
The following parity types are available:
* N = No Parity
* O = Odd
* E = Even
* S = Space
* M = Mark
Resulting HTML:
<ol><li><p><strong>Mode</strong></p><p>The following modes are available:</p><ul><li>0 = Port Off</li><li>232 = RS232 (handshaking determined via the <FlowControl> setting)</li><li>485H = Half-duplex RS485</li><li><p>4XXF = Full-duplex RS485 or RS422</p></li></ul></li><li><p><strong>BaudRate</strong></p><p>The following baud rates are available:</p><ul><li>100 </li><li>300 </li><li>600 </li><li>1200</li><li>2400</li><li>4800</li><li>9600</li><li>14400</li><li>19200</li><li>38400</li><li>57600</li><li>115200</li><li>128000</li><li><p>256000</p></li></ul></li><li><p><strong>DataBits</strong></p><p>The following data bits are available:</p><ul><li><p>8 = 8 Data Bits</p></li></ul></li><li><p><strong>Parity</strong></p><p>The following parity types are available:</p><ul><li>N = No Parity</li><li>O = Odd</li><li>E = Even</li><li>S = Space</li><li>M = Mark</li></ul></li></ol>
Notice how each last item of a list is the only one that has the <p>
.
use markdonw.parse the following md string:
JavaScrip((as[nodeJS](http://nodejs.org))and[webdriverNode](https://github.com/neekey/webdriverNode).
which will out put:
<p>JavaScript( as<a href="http://nodejs.org))and[webdriverNode](https://github.com/neekey/webdriverNode">nodeJS</a>.</p>
hope to fix!
I found that markdown.js is having trouble parsing through windows linebreaks.
For example, with code blocks:
This is code
Is this also code?
Which produces this output:
<pre><code>This is code</code></pre>
<p>
Is this code?</p>
Is this something the library should handle or do I have to keep normalizing the linebreaks before I parse?
I know, you can do it yourself, but I think it'd be good to add a minified version of the code to this repo.
There are several specs and recommendations for doing in-page links in markdown.
None of them seem to work in this library, for either the Gruber or Maruku dialect.
### title ### {#anch}
### title ### {: #anch}
{#anch}
-----------
{: #anch}
-----------
<a id="anch"></a>
### title ### (expect an auto-created id from the title)
What do you suggest?
Having a header such as: ### Install [foo](http://github.com/bar) ###
won't parse the inline link between the tags.
markdown.toHTML('![image](/path/to/image.jpg)');
renders <p><img alt="image" src="/path/to/image.jpg"></img></p>
which is invalid html5. Empty image tags should be self closing.
But must be only one
I was wondering what it would take for the generated HTML to keep the original formatting text
aka, # This Text
would produce
Thanks!
I have something like this:
Lorem ipsum (lorem ipsum) dolar sit amut.
However, the last closing paren is removed. I am getting something like this instead:
Lorem ipsum (lorem ipsum dolar sit amut.
Github does this correctly, as does dingus.
I tracked it down to markdown.js:823,
/^\[([\s\S]*?)\][ \t]*\([ \t]*(\S+)(?:[ \t]+(["'])(.*?)\3)?[ \t]*\)/
This regex is greedily matching up to the last )
.
.
I tried using the approach suggested at http://blog.hectorsq.com/image-links-in-markdown, i.e.: a link, where the link text is image markdown, but it didn't work. It only outputs literally the first part of the actual markdown:
[!(alt text
Hi, I want to know how show it works for a code block and keep the codes format.
I use it like this
function flipbook_theme() { return array( 'flipbook' => array( 'template' => 'flipbook', 'variables' => array('node' => NULL), ), ); }
but he shows these code in one line, pls help.
For example:
\t\techo "x" > /tmp/file
will be translated to:
echo "x" > /tmp/file
Then in chromium, the > is not show as ">".
edit: Ash renamed the bug to talk about the failure, not the error in the runner which is now fixed.
Checked out trunk (8b3cc2f) and with patr v0.2.6 and promised-io v0.2.3, I get the above. Modified the test to be more verbose, and in more detail:
AssertionError: Failed with error on /home/kragen/devel/markdown-js/test/features/meta/list.text: AssertionError: list; expected:
["html",
["ul",
{ "id" : "list" },
["li",
"here's a\nloose list"
],
["li",
"it might confuse the\nblock_meta routine"
]
]
]
got:
[
"html",
[
"ul",
[
"li",
[
"p",
"here's a\nloose list"
]
],
[
"li",
[
"p",
"it might confuse the\nblock_meta routine\n{: #list}"
]
]
]
]
Despite the suggestion in the paragraph itself, the problem does not seem to be in Markdown.dialects.Maruku.block.block_meta
; somehow, mysteriously, processBlock
is not getting called for the last block, and so neither is block_meta
.
Hi,
all is in the title :)
Regards,
Jérémy.
The following:
This is a
line break
Is not being correctly output as
This is a
line break
Instead, two line breaks are inserted. See http://jsfiddle.net/bgwDK/
What about support of widely used GitHub Flavored Markdown?
We need it. This dialect known as the Redcarpet.
from node at least you cannot just access those methods directly
Hi there. It would be very helpful from a distribution packaging point of view if you could include a copy of the MIT license with your software, usually in a file called LICENSE.
Thanks!
Hi,
i just figured other markdown tools assume one can put whitespaces there.
Here's a simple patch :
From c195026631d0c2a735776b2d2f6cc474fd167d9e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Lal?= <[email protected]>
Date: Mon, 24 May 2010 16:58:42 +0200
Subject: [PATCH] Allow whitespace in links [] []
---
lib/markdown.js | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/markdown.js b/lib/markdown.js
index 58c6b79..899a724 100644
--- a/lib/markdown.js
+++ b/lib/markdown.js
@@ -831,7 +831,7 @@ Markdown.dialects.Gruber.inline = {
// [Alt text][id]
// [id]
- m = text.match( /^\[([\s\S]*?)\](?:\[(.*?)\])?/ );
+ m = text.match( /^\[([\s\S]*?)\][ \t]*(?:\[(.*?)\])?/ );
if ( m ) {
// [id] case, text == id
--
1.7.1
Example input:
This input crashes markdown-js
* list
hanging
---
Results in this error:
Uncaught TypeError: Object #<Object> has no method 'processBlock'
At line 638 of markdown.js
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.