Vitaly Puzrin
1 year ago
88 changed files with 549 additions and 642 deletions
@ -1 +1 @@ |
|||
web: node support/babelmark-responder.js |
|||
web: node support/babelmark-responder.mjs |
|||
|
@ -1,138 +0,0 @@ |
|||
#!/usr/bin/env node
|
|||
/*eslint no-console:0*/ |
|||
|
|||
'use strict'; |
|||
|
|||
var path = require('path'); |
|||
var fs = require('fs'); |
|||
var util = require('util'); |
|||
var Benchmark = require('benchmark'); |
|||
var ansi = require('ansi'); |
|||
var cursor = ansi(process.stdout); |
|||
|
|||
var IMPLS_DIRECTORY = path.join(__dirname, 'implementations'); |
|||
var IMPLS_PATHS = {}; |
|||
var IMPLS = []; |
|||
|
|||
|
|||
fs.readdirSync(IMPLS_DIRECTORY).sort().forEach(function (name) { |
|||
var file = path.join(IMPLS_DIRECTORY, name); |
|||
var code = require(file); |
|||
|
|||
IMPLS_PATHS[name] = file; |
|||
IMPLS.push({ |
|||
name: name, |
|||
code: code |
|||
}); |
|||
}); |
|||
|
|||
|
|||
var SAMPLES_DIRECTORY = path.join(__dirname, 'samples'); |
|||
var SAMPLES = []; |
|||
|
|||
fs.readdirSync(SAMPLES_DIRECTORY).sort().forEach(function (sample) { |
|||
var filepath = path.join(SAMPLES_DIRECTORY, sample), |
|||
extname = path.extname(filepath), |
|||
basename = path.basename(filepath, extname); |
|||
|
|||
var content = {}; |
|||
|
|||
content.string = fs.readFileSync(filepath, 'utf8'); |
|||
|
|||
var title = util.format('(%d bytes)', content.string.length); |
|||
|
|||
function onComplete() { |
|||
cursor.write('\n'); |
|||
} |
|||
|
|||
|
|||
var suite = new Benchmark.Suite(title, { |
|||
|
|||
onStart: function onStart() { |
|||
console.log('\nSample: %s %s', sample, title); |
|||
}, |
|||
|
|||
onComplete: onComplete |
|||
|
|||
}); |
|||
|
|||
|
|||
IMPLS.forEach(function (impl) { |
|||
suite.add(impl.name, { |
|||
|
|||
onCycle: function onCycle(event) { |
|||
cursor.horizontalAbsolute(); |
|||
cursor.eraseLine(); |
|||
cursor.write(' > ' + event.target); |
|||
}, |
|||
|
|||
onComplete: onComplete, |
|||
|
|||
fn: function () { |
|||
impl.code.run(content.string); |
|||
return; |
|||
} |
|||
}); |
|||
}); |
|||
|
|||
|
|||
SAMPLES.push({ |
|||
name: basename, |
|||
title: title, |
|||
content: content, |
|||
suite: suite |
|||
}); |
|||
}); |
|||
|
|||
|
|||
function select(patterns) { |
|||
var result = []; |
|||
|
|||
if (!(patterns instanceof Array)) { |
|||
patterns = [ patterns ]; |
|||
} |
|||
|
|||
function checkName(name) { |
|||
return patterns.length === 0 || patterns.some(function (regexp) { |
|||
return regexp.test(name); |
|||
}); |
|||
} |
|||
|
|||
SAMPLES.forEach(function (sample) { |
|||
if (checkName(sample.name)) { |
|||
result.push(sample); |
|||
} |
|||
}); |
|||
|
|||
return result; |
|||
} |
|||
|
|||
|
|||
function run(files) { |
|||
var selected = select(files); |
|||
|
|||
if (selected.length > 0) { |
|||
console.log('Selected samples: (%d of %d)', selected.length, SAMPLES.length); |
|||
selected.forEach(function (sample) { |
|||
console.log(' > %s', sample.name); |
|||
}); |
|||
} else { |
|||
console.log('There isn\'t any sample matches any of these patterns: %s', util.inspect(files)); |
|||
} |
|||
|
|||
selected.forEach(function (sample) { |
|||
sample.suite.run(); |
|||
}); |
|||
} |
|||
|
|||
module.exports.IMPLS_DIRECTORY = IMPLS_DIRECTORY; |
|||
module.exports.IMPLS_PATHS = IMPLS_PATHS; |
|||
module.exports.IMPLS = IMPLS; |
|||
module.exports.SAMPLES_DIRECTORY = SAMPLES_DIRECTORY; |
|||
module.exports.SAMPLES = SAMPLES; |
|||
module.exports.select = select; |
|||
module.exports.run = run; |
|||
|
|||
run(process.argv.slice(2).map(function (source) { |
|||
return new RegExp(source, 'i'); |
|||
})); |
@ -0,0 +1,110 @@ |
|||
#!/usr/bin/env node
|
|||
/*eslint no-console:0*/ |
|||
|
|||
import { createRequire } from 'node:module'; |
|||
const require = createRequire(import.meta.url); |
|||
|
|||
var fs = require('fs'); |
|||
var util = require('util'); |
|||
var Benchmark = require('benchmark'); |
|||
var ansi = require('ansi'); |
|||
var cursor = ansi(process.stdout); |
|||
|
|||
var IMPLS = []; |
|||
|
|||
for (const name of fs.readdirSync(new URL('./implementations', import.meta.url)).sort()) { |
|||
const filepath = new URL(`./implementations/${name}/index.mjs`, import.meta.url); |
|||
const code = (await import(filepath)); |
|||
|
|||
IMPLS.push({ |
|||
name: name, |
|||
code: code |
|||
}); |
|||
} |
|||
|
|||
const SAMPLES = []; |
|||
|
|||
fs.readdirSync(new URL('./samples', import.meta.url)).sort().forEach(sample => { |
|||
const filepath = new URL(`./samples/${sample}`, import.meta.url); |
|||
|
|||
const content = {}; |
|||
|
|||
content.string = fs.readFileSync(filepath, 'utf8'); |
|||
|
|||
var title = `(${content.string.length} bytes)`; |
|||
|
|||
function onComplete() { cursor.write('\n'); } |
|||
|
|||
var suite = new Benchmark.Suite( |
|||
title, |
|||
{ |
|||
onStart: () => { console.log('\nSample: %s %s', sample, title); }, |
|||
onComplete: onComplete |
|||
} |
|||
); |
|||
|
|||
IMPLS.forEach(function (impl) { |
|||
suite.add( |
|||
impl.name, |
|||
{ |
|||
onCycle: function onCycle(event) { |
|||
cursor.horizontalAbsolute(); |
|||
cursor.eraseLine(); |
|||
cursor.write(' > ' + event.target); |
|||
}, |
|||
onComplete: onComplete, |
|||
fn: function () { impl.code.run(content.string); } |
|||
} |
|||
); |
|||
}); |
|||
|
|||
SAMPLES.push({ |
|||
name: sample.split('.')[0], |
|||
title: title, |
|||
content: content, |
|||
suite: suite |
|||
}); |
|||
}); |
|||
|
|||
|
|||
function select(patterns) { |
|||
var result = []; |
|||
|
|||
if (!(patterns instanceof Array)) { |
|||
patterns = [ patterns ]; |
|||
} |
|||
|
|||
function checkName(name) { |
|||
return patterns.length === 0 || patterns.some(function (regexp) { |
|||
return regexp.test(name); |
|||
}); |
|||
} |
|||
|
|||
SAMPLES.forEach(function (sample) { |
|||
if (checkName(sample.name)) { |
|||
result.push(sample); |
|||
} |
|||
}); |
|||
|
|||
return result; |
|||
} |
|||
|
|||
|
|||
function run(files) { |
|||
var selected = select(files); |
|||
|
|||
if (selected.length > 0) { |
|||
console.log('Selected samples: (%d of %d)', selected.length, SAMPLES.length); |
|||
selected.forEach(function (sample) { |
|||
console.log(' > %s', sample.name); |
|||
}); |
|||
} else { |
|||
console.log('There isn\'t any sample matches any of these patterns: %s', util.inspect(files)); |
|||
} |
|||
|
|||
selected.forEach(function (sample) { |
|||
sample.suite.run(); |
|||
}); |
|||
} |
|||
|
|||
run(process.argv.slice(2).map(source => new RegExp(source, 'i'))); |
@ -1,9 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
var commonmark = require('../../extra/lib/node_modules/commonmark'); |
|||
var parser = new commonmark.Parser(); |
|||
var renderer = new commonmark.HtmlRenderer(); |
|||
|
|||
exports.run = function (data) { |
|||
return renderer.render(parser.parse(data)); |
|||
}; |
@ -0,0 +1,11 @@ |
|||
import { createRequire } from 'node:module'; |
|||
const require = createRequire(import.meta.url); |
|||
|
|||
const commonmark = require('../../extra/lib/node_modules/commonmark'); |
|||
|
|||
var parser = new commonmark.Parser(); |
|||
var renderer = new commonmark.HtmlRenderer(); |
|||
|
|||
export function run(data) { |
|||
return renderer.render(parser.parse(data)); |
|||
} |
@ -1,11 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
var md = require('../../../')({ |
|||
html: true, |
|||
linkify: true, |
|||
typographer: true |
|||
}); |
|||
|
|||
exports.run = function (data) { |
|||
return md.render(data); |
|||
}; |
@ -0,0 +1,11 @@ |
|||
import markdownit from '../../../index.mjs'; |
|||
|
|||
var md = markdownit({ |
|||
html: true, |
|||
linkify: true, |
|||
typographer: true |
|||
}); |
|||
|
|||
export function run(data) { |
|||
return md.render(data); |
|||
} |
@ -1,7 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
var md = require('../../extra/lib/node_modules/markdown-it')('commonmark'); |
|||
|
|||
exports.run = function (data) { |
|||
return md.render(data); |
|||
}; |
@ -0,0 +1,10 @@ |
|||
import { createRequire } from 'node:module'; |
|||
const require = createRequire(import.meta.url); |
|||
|
|||
const markdownit = require('../../extra/lib/node_modules/markdown-it'); |
|||
|
|||
var md = markdownit('commonmark'); |
|||
|
|||
export function run(data) { |
|||
return md.render(data); |
|||
} |
@ -1,7 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
var marked = require('../../extra/lib/node_modules/marked'); |
|||
|
|||
exports.run = function (data) { |
|||
return marked(data); |
|||
}; |
@ -0,0 +1,8 @@ |
|||
import { createRequire } from 'node:module'; |
|||
const require = createRequire(import.meta.url); |
|||
|
|||
const marked = require('../../extra/lib/node_modules/marked'); |
|||
|
|||
export function run(data) { |
|||
return marked(data); |
|||
} |
@ -1,19 +0,0 @@ |
|||
#!/usr/bin/env node
|
|||
/*eslint no-console:0*/ |
|||
'use strict'; |
|||
|
|||
var fs = require('fs'); |
|||
var path = require('path'); |
|||
|
|||
var md = require('../')({ |
|||
html: true, |
|||
linkify: false, |
|||
typographer: false |
|||
}); |
|||
|
|||
// var data = fs.readFileSync(path.join(__dirname, '/samples/lorem1.txt'), 'utf8');
|
|||
var data = fs.readFileSync(path.join(__dirname, '../test/fixtures/commonmark/spec.txt'), 'utf8'); |
|||
|
|||
for (var i = 0; i < 20; i++) { |
|||
md.render(data); |
|||
} |
@ -0,0 +1,17 @@ |
|||
#!/usr/bin/env node
|
|||
/*eslint no-console:0*/ |
|||
|
|||
import { readFileSync } from 'fs'; |
|||
import markdownit from '../index.mjs'; |
|||
|
|||
var md = markdownit({ |
|||
html: true, |
|||
linkify: false, |
|||
typographer: false |
|||
}); |
|||
|
|||
var data = readFileSync(new URL('../test/fixtures/commonmark/spec.txt', import.meta.url), 'utf8'); |
|||
|
|||
for (var i = 0; i < 20; i++) { |
|||
md.render(data); |
|||
} |
@ -1,4 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
|
|||
module.exports = require('./lib/'); |
@ -0,0 +1 @@ |
|||
export { default } from './lib/index.mjs'; |
@ -0,0 +1,5 @@ |
|||
env: |
|||
node: false |
|||
|
|||
parserOptions: |
|||
ecmaVersion: 2015 |
@ -1,10 +1,7 @@ |
|||
// List of valid html blocks names, according to commonmark spec
|
|||
// https://spec.commonmark.org/0.30/#html-blocks
|
|||
|
|||
'use strict'; |
|||
|
|||
|
|||
module.exports = [ |
|||
export default [ |
|||
'address', |
|||
'article', |
|||
'aside', |
@ -1,7 +0,0 @@ |
|||
// Just a shortcut for bulk export
|
|||
'use strict'; |
|||
|
|||
|
|||
exports.parseLinkLabel = require('./parse_link_label'); |
|||
exports.parseLinkDestination = require('./parse_link_destination'); |
|||
exports.parseLinkTitle = require('./parse_link_title'); |
@ -0,0 +1,11 @@ |
|||
// Just a shortcut for bulk export
|
|||
|
|||
import parseLinkLabel from './parse_link_label.mjs'; |
|||
import parseLinkDestination from './parse_link_destination.mjs'; |
|||
import parseLinkTitle from './parse_link_title.mjs'; |
|||
|
|||
export default { |
|||
parseLinkLabel, |
|||
parseLinkDestination, |
|||
parseLinkTitle |
|||
}; |
@ -1,61 +0,0 @@ |
|||
/** internal |
|||
* class Core |
|||
* |
|||
* Top-level rules executor. Glues block/inline parsers and does intermediate |
|||
* transformations. |
|||
**/ |
|||
'use strict'; |
|||
|
|||
|
|||
var Ruler = require('./ruler'); |
|||
|
|||
|
|||
var _rules = [ |
|||
[ 'normalize', require('./rules_core/normalize') ], |
|||
[ 'block', require('./rules_core/block') ], |
|||
[ 'inline', require('./rules_core/inline') ], |
|||
[ 'linkify', require('./rules_core/linkify') ], |
|||
[ 'replacements', require('./rules_core/replacements') ], |
|||
[ 'smartquotes', require('./rules_core/smartquotes') ], |
|||
// `text_join` finds `text_special` tokens (for escape sequences)
|
|||
// and joins them with the rest of the text
|
|||
[ 'text_join', require('./rules_core/text_join') ] |
|||
]; |
|||
|
|||
|
|||
/** |
|||
* new Core() |
|||
**/ |
|||
function Core() { |
|||
/** |
|||
* Core#ruler -> Ruler |
|||
* |
|||
* [[Ruler]] instance. Keep configuration of core rules. |
|||
**/ |
|||
this.ruler = new Ruler(); |
|||
|
|||
for (var i = 0; i < _rules.length; i++) { |
|||
this.ruler.push(_rules[i][0], _rules[i][1]); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Core.process(state) |
|||
* |
|||
* Executes core chain rules. |
|||
**/ |
|||
Core.prototype.process = function (state) { |
|||
var i, l, rules; |
|||
|
|||
rules = this.ruler.getRules(''); |
|||
|
|||
for (i = 0, l = rules.length; i < l; i++) { |
|||
rules[i](state); |
|||
} |
|||
}; |
|||
|
|||
Core.prototype.State = require('./rules_core/state_core'); |
|||
|
|||
|
|||
module.exports = Core; |
@ -0,0 +1,68 @@ |
|||
/** internal |
|||
* class Core |
|||
* |
|||
* Top-level rules executor. Glues block/inline parsers and does intermediate |
|||
* transformations. |
|||
**/ |
|||
|
|||
import Ruler from './ruler.mjs'; |
|||
import StateCore from './rules_core/state_core.mjs'; |
|||
|
|||
import r_normalize from './rules_core/normalize.mjs'; |
|||
import r_block from './rules_core/block.mjs'; |
|||
import r_inline from './rules_core/inline.mjs'; |
|||
import r_linkify from './rules_core/linkify.mjs'; |
|||
import r_replacements from './rules_core/replacements.mjs'; |
|||
import r_smartquotes from './rules_core/smartquotes.mjs'; |
|||
import r_text_join from './rules_core/text_join.mjs'; |
|||
|
|||
|
|||
var _rules = [ |
|||
[ 'normalize', r_normalize ], |
|||
[ 'block', r_block ], |
|||
[ 'inline', r_inline ], |
|||
[ 'linkify', r_linkify ], |
|||
[ 'replacements', r_replacements ], |
|||
[ 'smartquotes', r_smartquotes ], |
|||
// `text_join` finds `text_special` tokens (for escape sequences)
|
|||
// and joins them with the rest of the text
|
|||
[ 'text_join', r_text_join ] |
|||
]; |
|||
|
|||
|
|||
/** |
|||
* new Core() |
|||
**/ |
|||
function Core() { |
|||
/** |
|||
* Core#ruler -> Ruler |
|||
* |
|||
* [[Ruler]] instance. Keep configuration of core rules. |
|||
**/ |
|||
this.ruler = new Ruler(); |
|||
|
|||
for (var i = 0; i < _rules.length; i++) { |
|||
this.ruler.push(_rules[i][0], _rules[i][1]); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Core.process(state) |
|||
* |
|||
* Executes core chain rules. |
|||
**/ |
|||
Core.prototype.process = function (state) { |
|||
var i, l, rules; |
|||
|
|||
rules = this.ruler.getRules(''); |
|||
|
|||
for (i = 0, l = rules.length; i < l; i++) { |
|||
rules[i](state); |
|||
} |
|||
}; |
|||
|
|||
Core.prototype.State = StateCore; |
|||
|
|||
|
|||
export default Core; |
@ -1,9 +1,6 @@ |
|||
// Commonmark default options
|
|||
|
|||
'use strict'; |
|||
|
|||
|
|||
module.exports = { |
|||
export default { |
|||
options: { |
|||
html: true, // Enable HTML tags in source
|
|||
xhtmlOut: true, // Use '/' to close single tags (<br />)
|
@ -1,9 +1,6 @@ |
|||
// markdown-it default options
|
|||
|
|||
'use strict'; |
|||
|
|||
|
|||
module.exports = { |
|||
export default { |
|||
options: { |
|||
html: false, // Enable HTML tags in source
|
|||
xhtmlOut: false, // Use '/' to close single tags (<br />)
|
@ -1,10 +1,7 @@ |
|||
// "Zero" preset, with nothing enabled. Useful for manual configuring of simple
|
|||
// modes. For example, to parse bold/italic only.
|
|||
|
|||
'use strict'; |
|||
|
|||
|
|||
module.exports = { |
|||
export default { |
|||
options: { |
|||
html: false, // Enable HTML tags in source
|
|||
xhtmlOut: false, // Use '/' to close single tags (<br />)
|
@ -1,13 +1,14 @@ |
|||
#!/usr/bin/env node
|
|||
|
|||
/* eslint-env es6 */ |
|||
/* eslint-disable no-console */ |
|||
'use strict'; |
|||
|
|||
const md = require('../')('commonmark'); |
|||
const app = require('express')(); |
|||
import markdownit from '../index.mjs'; |
|||
import express from 'express'; |
|||
import { readFileSync } from 'fs'; |
|||
|
|||
const version = require('../package.json').version; |
|||
const md = markdownit('commonmark'); |
|||
const app = express(); |
|||
const version = JSON.parse(readFileSync(new URL('../package.json', import.meta.url))).version; |
|||
|
|||
const banner = `<!doctype html>
|
|||
<html lang="en"> |
@ -1,7 +1,5 @@ |
|||
'use strict'; |
|||
|
|||
const markdownit = require('../'); |
|||
|
|||
exports.render = (str) => { |
|||
return markdownit().render(str); |
|||
exports.render = async (str) => { |
|||
return (await import('../index.mjs')).default().render(str); |
|||
}; |
|||
|
Loading…
Reference in new issue