Add markdown support

master
Buddy Sandidge 10 years ago
parent 917d08ac9f
commit 26080215fd

@ -16,6 +16,7 @@
return { return {
paths: { paths: {
backbone: prefix + '/vendor/backbone/backbone', backbone: prefix + '/vendor/backbone/backbone',
commonmark: prefix + '/vendor/commonmark/dist/commonmark',
handlebars: prefix + '/vendor/handlebars/handlebars.runtime', handlebars: prefix + '/vendor/handlebars/handlebars.runtime',
jquery: prefix + '/vendor/jquery/dist/jquery', jquery: prefix + '/vendor/jquery/dist/jquery',
marionette: prefix + '/vendor/marionette/lib/backbone.marionette', marionette: prefix + '/vendor/marionette/lib/backbone.marionette',

@ -0,0 +1,8 @@
define(['commonmark'], function (commonmark) {
return function convert(source) {
var reader = new commonmark.Parser();
var writer = new commonmark.HtmlRenderer();
var parsed = reader.parse(source);
return writer.render(parsed);
};
});

@ -20,6 +20,7 @@
"marionette": "~2.3.1", "marionette": "~2.3.1",
"normalize-scss": "~3.0.2", "normalize-scss": "~3.0.2",
"requirejs": "~2.1.15", "requirejs": "~2.1.15",
"handlebars": "~1.3.0" "handlebars": "~1.3.0",
"commonmark": "~0.17.1"
} }
} }

@ -0,0 +1,10 @@
define(['lib/markdown'], function (markdown) {
describe('markdown', function () {
it('→ converts to html', function () {
var expected = '<p>some <em>example</em> ' +
'<a href="http://example.com">yo</a></p>\n';
var actual = markdown('some *example* [yo](http://example.com)');
expect(actual).toBe(expected);
});
});
});

@ -0,0 +1,35 @@
{
"name": "commonmark",
"main": "dist/commonmark.js",
"homepage": "https://github.com/jgm/commonmark.js",
"description": "CommonMark parsing and rendering library",
"license": "BSD-2-Clause",
"ignore": [
"**/.*",
"lib",
"bin",
"test",
"tools",
"bench",
"Makefile",
"README.md",
"dingus.html",
"eslint.json",
"package.json"
],
"keywords": [
"markdown",
"commonmark"
],
"version": "0.17.1",
"_release": "0.17.1",
"_resolution": {
"type": "version",
"tag": "0.17.1",
"commit": "d89adcd2ba20845b6e5e9f0f8814ce6c43dbd3c8"
},
"_source": "git://github.com/jgm/commonmark.js.git",
"_target": "~0.17.1",
"_originalSource": "commonmark",
"_direct": true
}

@ -0,0 +1,25 @@
Contributing
============
Submitting bug reports
----------------------
There is a [forum for discussing CommonMark](http://talk.commonmark.org);
use it for questions and discussions that might be open-ended. Use the
[github issue tracker](http://github.com/jgm/commonmark.js/issues)
only for simple, clear, actionable issues.
Submitting pull requests
------------------------
1. A good pull request makes one logical change and does not mix
several independent changes.
2. If you have several commits that successively refine a single
logical change, rebase them into a single clean commit.
3. Ensure that all tests pass (`make test`).
4. Use `make lint` to check for problems.
5. Ensure that performance has not been affected (`make bench` before
and after the change).
6. Changes to `dist` should not be committed. (We will regenerate
`dist/commonmark.js` before a release.)
7. Follow the style of the existing code.

@ -0,0 +1,115 @@
Copyright (c) 2014, John MacFarlane
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---
lib/normalize-reference.js is a slightly modified version of
https://github.com/dmoscrop/fold-case:
Copyright Mathias Bynens <https://mathiasbynens.be/>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---
lib/from-code-point.js is derived from a polyfill
Copyright Mathias Bynens <http://mathiasbynens.be/>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---
bench/samples/*.md:
With the exception of `bench/samples/README.md`, the samples in
`bench/samples` are taken from https://github.com/markdown-it/markdown-it.
Copyright (c) 2014 Vitaly Puzrin, Alex Kocharin.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
---
The CommonMark spec (spec.txt) in test/ is
Copyright (C) 2014-15 John MacFarlane
Released under the Creative Commons CC-BY-SA 4.0 license:
<http://creativecommons.org/licenses/by-sa/4.0/>.

@ -0,0 +1,24 @@
{
"name": "commonmark",
"main": "dist/commonmark.js",
"homepage": "https://github.com/jgm/commonmark.js",
"description": "CommonMark parsing and rendering library",
"license": "BSD-2-Clause",
"ignore": [
"**/.*",
"lib",
"bin",
"test",
"tools",
"bench",
"Makefile",
"README.md",
"dingus.html",
"eslint.json",
"package.json"
],
"keywords": [
"markdown",
"commonmark"
]
}

@ -0,0 +1,120 @@
[0.17.1]
* Reorganized block parsing in a more modular way. There is now
a `blocks` property of the parser that contains information
about each type of block, which is used in parsing. Ultimately
this will make it easier to extend the library, but the project
is still only partially completed.
* Code cleanup and simplification, with some performance optimizations.
* Removed version from `bower.json`. Bower takes version from tags.
* Initialize some properties at beginning of 'parse'.
This fixes some mistakes in source position when the
same Parser object was used to parse multiple times (#3).
* Made parsing of backslash escapes a bit more efficient.
* Removed refmap parameter of InlineParser.parse().
Instead, set the refmap property before running the parser.
* Set `_string_content` to null after using, allowing it to be GCd.
* Removed `_strings`; just append to `_string_content`.
This gives better performance with v8.
* Format benchmarks so that samples are linked.
* Added in-browser benchmark.
* Added API documentation to README.
* xml renderer: use `sourcepos` attribute, not `data-sourcepos`.
* Changed license to 2-clause BSD. Added clause for spec.
[0.17.0]
* Renamed `DocParser` -> `Parser`.
Note: library users should update their code or it will break.
* Added `normalize-reference.js`. This does a proper unicode case
fold instead of just using `toUpperCase`. It is also faster,
partly because we can do one pass for space and case normalization.
* Removed artificial distinction btw FencedCode, IndentedCode
in `blocks.js`.
* Removed vestigial `ReferenceDef` node type.
* Added getters and (in some cases) setters for "public" properties
of Nodes. Renamed non-public properties to start with underscore.
This will allow us to keep the API stable while changing the
underlying data structure. And it will avoid exposing properties
that have only an instrumental value in parsing.
* Removed `Node.toObject()`.
* Rename `bullet_char` -> `bulletChar`.
* Check for blank line before checking indent in Item.
* Removed unnecessary setting of default `tight=true` in `finalize`.
We do that when the `listData` object is initialized.
* Performance optimization - avoid repeating scan for nonspace.
* Moved check for closing fence to close-block-check section.
This is a more logical arrangement and addresses jgm/CommonMark#285.
* Added `offset` property to `DocParser`. Use this in `addLine`,
instead of `offset` parameter, which has been removed.
* Implemented new spec for emphasis and strong emphasis with `_`.
* `html.js` - explicitly specify second parameter of `escapeXml`.
* Fixed escaping error in CDATA regex.
* Removed some dead code and fixed incorrect call to `addChild`
with three arguments (Robin Stocker).
* Adjust `lastLineLength` before returning after close fence.
* Propagate `lastLineBlank` up through parents.
Previously we just kept it set on the bottom child.
But this will give a quicker determination of `lastLineBlank`.
* Moved continuation checks & finalizers into `blocks` property
of `Parser`. This is a first step towards keeping the code for
each kind of block in a central place, rather than spread all over
the code base. This is preparatory for a more modular structure,
where each type of block has a record describing how it is parsed and
finalized. Eventually this will also contain functions for checking for
a block start, and metadata that determines how line data
should be handled.
* Added `currentLine` property to `Parser`.
* Renamed `first_nonspace` -> `next_nonspace`.
* Put generated `commonmark.js` in `dist/` rather than `js/`.
* Miscellaneous code cleanup.
* Split JS code into (this) independent repository.
* Added detailed benchmark with samples (`make bench-detailed`).
* Added `dist/commonmark.js` to repo (for bower).
* Added `bower.json` (jgm/CommonMark#288).
* Updated test suite. Now shows how performance depends on length in
pathological cases.
* Don't use -1 as second param for .slice. This seems to cause a
deoptimization, as reported by `node --trace-deopt`.
* Added `CONTRIBUTING.md`.
* Added `.travis.yml` to test against various node versions.
* Renamed `changelog.js.txt` -> `changelog.txt`.
[0.16]
* Improved regex for HTML comments (#263).
* Fixed CDATA regex (#267).
* Use linked list instead of arrays in AST: the same doubly linked
node structure as cmark uses. This simplifies some code and
eliminates the need for recursive algorithms, so we can render
deeply-nested structures without stack overflows.
* Use `children` instead of `label` (in Image and Link),
`inline_content` (in Paragraph), and `c` (in Emph and Strong).
* Renamed the `c` property to `literal` to match `libcmark`.
* Use `literal` rather than `string_content` property for code
blocks, HTML. `string_content` is reserved for raw string
content that has yet to be parsed as inlines.
* Improved end lines (#276).
* Added a node walker, for easy AST traversal (see `node.js`).
* Regularized position information into a `sourcepos` property.
Added end column information.
* Renamed `html-renderer.js` to `html.js`.
* Replace NUL characters with U+FFFD, as per spec.
* Optimized code, resulting in significant performance gains.
(We've gone from being twice as fast as showdown.js to being
three times as fast, on par with marked.)
* Made `tight` a property of `list_data` rather than `Node`.
* Added options to renderer, parser objections.
* Added a `--sourcepos` command line option to `js/bin/commonmark`.
* HTML renderer now throws an error on unknown tag type (which
indicates a programming error).
* Removed `ansi.js` code from the source tree. The test suite now
uses its own mini ansi colors implementation.
* Added `--time` option to `js/bin/commonmark`.
* Added an XML renderer (XML representation of the AST, matching
`Commonmark.dtd`).
* Changed `url` property to `destination` to match `cmark` and spec.
* Added `js/common.js` to hold some common code, like string
unescaping and URI normalization.
* Use `decodeURI` instead of `unescape`.
* Added some "pathological" test cases to test suite.

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save