This repository has been archived by the owner on Aug 28, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from nteract/TF2.0
TF 2.0
- Loading branch information
Showing
5 changed files
with
95 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use strict"; | ||
|
||
var commonmark = require("commonmark"); | ||
|
||
var markdownTransform = function(){ | ||
// Stick reader and writer in a closure so they only get created once. | ||
|
||
let reader = new commonmark.Parser(); | ||
let writer = new commonmark.HtmlRenderer({ | ||
safe: true | ||
}); | ||
|
||
return function(mimetype, data, document) { | ||
var div = document.createElement("div"); | ||
|
||
var parsed = reader.parse(data); | ||
|
||
// TODO: Any other transformations on the parsed object | ||
// See https://github.com/jgm/commonmark.js#usage | ||
|
||
div.innerHTML = writer.render(parsed); | ||
|
||
return div; | ||
}; | ||
}(); | ||
|
||
markdownTransform.mimetype = 'text/markdown'; | ||
|
||
export default markdownTransform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {assert} from 'chai'; | ||
|
||
import {jsdom} from 'jsdom'; | ||
|
||
var markdownTransform = require('../src/commonmark.transform'); | ||
|
||
describe('text transformer', function() { | ||
beforeEach(function() { | ||
this.document = jsdom(); | ||
}); | ||
|
||
it('should have the text/markdown mimetype', function() { | ||
assert.equal(markdownTransform.mimetype, "text/markdown"); | ||
}); | ||
describe('#transform', function() { | ||
it('should create a div with nice markup', function() { | ||
let text = `# Ratification of Markdown Association | ||
We are present here because we believe in unification | ||
across all markdowns, whether common, flavored like | ||
GitHub, or used to help an undergrad do their homework | ||
via StackOverflow. It is of *great importance* that we | ||
unify for the [sake of the sciences](https://jupyter.org), | ||
the arts, and be able to express in rich text our thoughts, | ||
feelings, and desires. | ||
## Speaking for some | ||
We need markdown to work | ||
* On the web | ||
* On your hard drive | ||
* Hanging upside down from a bridge | ||
* In letters to your lovers`; | ||
text = text + "\n\n```bash\nnpm install transformime-commonmark\n```\n"; | ||
|
||
let el = markdownTransform('text/markdown', text, this.document); | ||
|
||
assert.equal(el.innerHTML, `<h1>Ratification of Markdown Association</h1> | ||
<p>We are present here because we believe in unification | ||
across all markdowns, whether common, flavored like | ||
GitHub, or used to help an undergrad do their homework | ||
via StackOverflow. It is of <em>great importance</em> that we | ||
unify for the <a href="https://jupyter.org">sake of the sciences</a>, | ||
the arts, and be able to express in rich text our thoughts, | ||
feelings, and desires.</p> | ||
<h2>Speaking for some</h2> | ||
<p>We need markdown to work</p> | ||
<ul> | ||
<li>On the web</li> | ||
<li>On your hard drive</li> | ||
<li>Hanging upside down from a bridge</li> | ||
<li>In letters to your lovers</li> | ||
</ul> | ||
<pre><code class="language-bash">npm install transformime-commonmark | ||
</code></pre> | ||
`); | ||
assert.equal(el.localName, 'div'); | ||
|
||
}); | ||
}); | ||
}); |