Giter VIP home page Giter VIP logo

js-markdown-extra's Introduction

js-markdown-extra

ver 1.2.4 based on PHP Markdown Extra 1.2.5
originally developed by boumankan

What's this?

js-markdown-extra is a experimental JavaScript port of PHP Markdown Extra.

PHP Markdown Extra demo

I couldn't retain complete comaptibility because of difference between PHP's regular expression and JavaScript's one, but it can convert most of simple markdown text. perhaps.

Demo

You can try in your hand.

Demo page

How to use

Load this script in HTML and call Markdown function.

	//example :
	var html = Markdown( text );

Notice

It has possibility of entering infinite loop by some user input because I try to port PHP Markdown Extra with incompatible regular expression test.

Known issues

  • Emphasis or strong syntax may have a bug.
  • Possible to freeze when incomplete syntax.
  • Bracket nesting is unsupported.

Copyright

License

This software is based on BSD license.

Free for modification, redistribution and embedding if copyright included.

Agreement

Shall we not be liable for any damages caused by this software.

js-markdown-extra's People

Contributors

chingjun avatar iphands avatar jakov avatar petarov avatar tanakahisateru avatar taubmann avatar thisduck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-markdown-extra's Issues

Refactor and Comment

To continue develop I should clean source code:

  • functions and variables name
  • sync coding order with original PHP version
  • comment for each part

Unrecognized inline tags in paragraphs

When writing HTML tags inside a paragraph, the tag isn't seen as a tag when it contains attributes. For instance, this will not work (the tag gets escaped):

<img src="blah.png" class="abc">

But interestingly, this will work and pass the tag as-is in the HTML output:

<img>

The problem seems to be in parseSpan. You're suing (?= in two places for non-capture blocks. The original in PHP Markdown Extra uses (?> which consumes the input, unlike (?=. As a general rule you should probably use (?: to replace (?> in JS rather than the non-consuming (?=.

Reference to PHP's once-only patterns (?>: http://www.php.net/manual/en/regexp.reference.onlyonce.php

double underline renders wrongly

__strong__, __double__snake, is__double__snake, endsnake__double__

renders as

<strong>strong</strong>, __double__snake, is__double__snake, endsnake<strong>double</strong>

although in php markdown you get the following:

<strong>strong</strong>, <strong>double__snake, is__double__snake, endsnake__double</strong>

reference style links don't work

Reference-style labels (titles are optional):
An [example][id]. Then, anywhere  
else in the doc, define the link:

  [id]: http://example.com/  "Title"

The above works fine, but when you remove the [example] and just leave the [id] it doesn't work for some strange reasons.
I've tested it in your preview website (http://tanakahisateru.github.com/js-markdown-extra/demo.html), and it doesn't work there either. I found the corresponding code, but i can't figure out why it doens't work:

function _DoAnchors_reference_callback( $0, $1, $2, $3 ) {
        var whole_match = $1;
        var link_text = $2;
        var link_id = $3.toLowerCase( );
        var result = "";

        if( link_id == "" ) {
            link_id = link_text.toLowerCase( );
        }
...

Demo broken

The Demo is not working in current Chrome and probably other current Browsers too. That is because you serve the JavaScript directly from raw.github.com. You should probably serve it from github pages where your HTML/CSS is located too.

See related issue in Chromium tracker for more information.

Script tag in inline code block is not escaped (after #27)

Hi!

I think the fix for #27 (which worked) introduced a new bug with inline code blocks.

input     :  `<script></script>`
expected  :  <p><code>&lt;script&gt;&lt;/script&gt;</code></p>
actual    :  <p>`</p>\n\n<script></script>\n\n<p>`</p>

Can you confirm this?

Many thanks!
Phil

Close variable scope

Currently so many functions are defined in global scope. It should be minimized.

Add source line number

How difficult would it be to add to each generated element, the source line number ? With this information, I could automatically sync the scroll of the editor and the preview in a Markdown editor.

The source line number could be added as a class, for example: class="src-line28". Or as a data attribute: data-src-line="28".

Version 1.2 won't works with node JS

I was using this lib on server-side with node js without any issues.
But the new version won't work at all.
The markdown seems completely ignored by the lib.

Typo in the README

I believe it should be JavaScript.

js-markdown-extra is a experimental JapaScript port of PHP Markdown Extra.

Lists rendered without blank line

Unlike php markdown extra lists dosen't need a blank line before the list items to be rendered in your version. I don't know if this behavior is expected.

Not run with Chrome

This script doesn't support Google Chrome (or WebKit).

compile() of RegExp object is not supported by Chrome currently...

Script tag in fenced code block is not escaped.

Normal code blocks work as expected:

console.log(Markdown("foo\r\n\r\n    <script>console.log('heya');</scr" + "ipt>"));

... leads to ...

<p>foo</p>
<pre><code>&lt;script&gt;console.log('heya');&lt;/script&gt;
</code></pre>

The script tag is properly escaped. But when using fenced code blocks, that tag is not escaped:

console.log(Markdown("~~~\r\n<script>console.log('heya');</scr" + "ipt>\r\n~~~"));

... leads to ...

<pre><code><br /><br /><script>console.log('heya');</script>
</code></pre>

I'll try to come up with a patch, but I wasn't successful yet. Any help is appreciated.

Best
Phil

Infinite loop in code block

I've made an copy/paste text from Github markdown.

There's an infinite loop with this text :

```php
function test() { echo "test".$2; };
``

You can reproduce with this (incomplete) test :

QUnit.test("Bug infinite loop", function() {
    var input =
        '```php' + "\n" +
        'function test() { echo "test".$2; }' + "\n" +
        '``' + "\n" +
        "";

    var expected =
        "";

    var result = Markdown(input); // infinite loop
    QUnit.assert.equal(result, expected);
});

Edit: this bug is only for Chrome and Node

[Propose] コマンドラインスクリプト

やっつけで作ったものですが、よかったらどうぞ

  • エラーチェックサボってます。
  • コマンドラインオプション足すと、もっとそれっぽくなるかも
var md = require("js-markdown-extra")
var fs = require('fs')

if (process.argv.length < 2) {
    console.error("Must not pass a markdown source")
}

var filePath = process.argv[2]
fs.stat(filePath, function(err, stat) {
    if (! stat.isFile()) return;

    fs.readFile(filePath, "utf-8", function(err, text) {
        console.log(md.Markdown(text))
    })
})

Doesn't support special attributes

The current version doesn't support Markdown Extra's special attributes. For example, the following Markdown should produce the subsequent HTML.

~~~ .javascript
var x = 7;
~~~
<pre><code class="javascript">var x = 7;</code></pre>

Unnecessary comma in js-markdown-extra.js

The trailing comma on line 97 is unnecessary doesn't need to (and probably shouldn't) be there.

this.block_gamut = [
     ['doHeaders',         10],
     ['doHorizontalRules', 20],
     ['doLists',           40],
     ['doCodeBlocks',      50],
     ['doBlockQuotes',     60],  /*this is line 97*/
];

Definition lists with multiple items are converted to multiple definition lists instead.

.. If the first item in the list is preceded by a blank line. For example:

term

 : definition

term

 : definition

Becomes:

<dl>
<dt>term</dt>
<dd>
<p>definition</p>
</dd>
</dl>

<dl>
<dt>term</dt>
<dd>
<p>definition</p>
</dd>
</dl>

It wraps the definitions in <p> tags correctly, but doesn't recognize that they're part of the same list. The fix is simple enough though. There's an extra space in your regex:

'(?:\\S.*\\n )+?' + // defined term

I believe it should be:

'(?:\\S.*\\n)+?' + // defined term

Allow multiple references to the same footnote

I just noticed, that you can't use the same footnote reference twice. This behaviour is actually the same as in PHP Markdown Extra, but it has also been discussed over there:

    - refer to footnote A[^1]
    - refer to footnote B[^2]
    - refer to footnote A again[^1]

[^1]: footnote A
[^2]: footnote B

The "refer to footnote A again[^1]" line doesn't get linked to footnote A.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.