1.1.0 • Published 9 years ago
marktwain v1.1.0
marktwain
Unified markdown utilities module.
Installation
$ npm install --save marktwain
Usage
var marktwain = require('marktwain');
console.log(marktwain.parse('Hello <strong>world</strong>'));
/* =>
{ type: 'root',
children: [ { type: 'paragraph', children: [Object], position: [Object] } ],
position: { start: { line: 1, column: 1 }, end: { line: 1, column: 29 } } }
*/
console.log(marktwain.renderAsHTML('Hello **world**'));
//=> <p>Hello <strong>world</strong></p>
console.log(marktwain.renderAsText('Hello *nice* <strong>world</strong>'));
// => Hello nice world
console.log(marktwain.renderFromHTML('Hello <strong>world</strong>'));
// => Hello **world**
let input = marktwain.parse('Hello **world**');
console.log(marktwain.stringifyAST(input));
// => Hello **world**
marktwain.walkAST('Hello **world**', console.log);
/* =>
{ type: 'root',
children: [ { type: 'paragraph', children: [Object], position: [Object] } ],
position: { start: { line: 1, column: 1 }, end: { line: 1, column: 16 } } } null null
{ type: 'paragraph',
children:
[ { type: 'text', value: 'Hello ', position: [Object] },
{ type: 'strong', children: [Object], position: [Object] } ],
position:
Position {
start: { line: 1, column: 1 },
end: { line: 1, column: 16 },
indent: [] } } 0 { type: 'root',
children: [ { type: 'paragraph', children: [Object], position: [Object] } ],
position: { start: { line: 1, column: 1 }, end: { line: 1, column: 16 } } }
{ type: 'text',
value: 'Hello ',
position:
Position {
start: { line: 1, column: 1 },
end: { line: 1, column: 7 },
indent: [] } } 0 { type: 'paragraph',
children:
[ { type: 'text', value: 'Hello ', position: [Object] },
{ type: 'strong', children: [Object], position: [Object] } ],
position:
Position {
start: { line: 1, column: 1 },
end: { line: 1, column: 16 },
indent: [] } }
{ type: 'strong',
children: [ { type: 'text', value: 'world', position: [Object] } ],
position:
Position {
start: { line: 1, column: 7 },
end: { line: 1, column: 16 },
indent: [] } } 1 { type: 'paragraph',
children:
[ { type: 'text', value: 'Hello ', position: [Object] },
{ type: 'strong', children: [Object], position: [Object] } ],
position:
Position {
start: { line: 1, column: 1 },
end: { line: 1, column: 16 },
indent: [] } }
{ type: 'text',
value: 'world',
position:
Position {
start: { line: 1, column: 9 },
end: { line: 1, column: 14 },
indent: [] } } 0 { type: 'strong',
children: [ { type: 'text', value: 'world', position: [Object] } ],
position:
Position {
start: { line: 1, column: 7 },
end: { line: 1, column: 16 },
indent: [] } }
*/
License
marktwain
is freely distributed under the MIT license.