diff --git a/.eslintrc.yml b/.eslintrc.yml
index 70e0873..25cfeec 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -1,11 +1,17 @@
env:
- node: true
+ es6: true
+ node: true
+
+parserOptions:
+ ecmaVersion: 2022
overrides:
-
files: [ '*.mjs' ]
parserOptions:
sourceType: module
+ rules:
+ no-restricted-globals: [ 2, require, __dirname ]
ignorePatterns:
- coverage/
diff --git a/Procfile b/Procfile
index 678637d..3b74fcc 100644
--- a/Procfile
+++ b/Procfile
@@ -1 +1 @@
-web: node support/babelmark-responder.js
+web: node support/babelmark-responder.mjs
diff --git a/README.md b/README.md
index 46e7aff..02338ec 100644
--- a/README.md
+++ b/README.md
@@ -253,8 +253,8 @@ You can find all rules in sources:
Here is the result of readme parse at MB Pro Retina 2013 (2.4 GHz):
```bash
-make benchmark-deps
-benchmark/benchmark.js readme
+npm run benchmark-deps
+benchmark/benchmark.mjs readme
Selected samples: (1 of 28)
> README
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js
deleted file mode 100755
index 6fe04ae..0000000
--- a/benchmark/benchmark.js
+++ /dev/null
@@ -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');
-}));
diff --git a/benchmark/benchmark.mjs b/benchmark/benchmark.mjs
new file mode 100755
index 0000000..0441af2
--- /dev/null
+++ b/benchmark/benchmark.mjs
@@ -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')));
diff --git a/benchmark/implementations/commonmark-reference/index.js b/benchmark/implementations/commonmark-reference/index.js
deleted file mode 100644
index 8f8790c..0000000
--- a/benchmark/implementations/commonmark-reference/index.js
+++ /dev/null
@@ -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));
-};
diff --git a/benchmark/implementations/commonmark-reference/index.mjs b/benchmark/implementations/commonmark-reference/index.mjs
new file mode 100644
index 0000000..3487c39
--- /dev/null
+++ b/benchmark/implementations/commonmark-reference/index.mjs
@@ -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));
+}
diff --git a/benchmark/implementations/current-commonmark/index.js b/benchmark/implementations/current-commonmark/index.mjs
similarity index 73%
rename from benchmark/implementations/current-commonmark/index.js
rename to benchmark/implementations/current-commonmark/index.mjs
index 4cd2e90..4627887 100644
--- a/benchmark/implementations/current-commonmark/index.js
+++ b/benchmark/implementations/current-commonmark/index.mjs
@@ -1,6 +1,6 @@
-'use strict';
+import markdownit from '../../../index.mjs';
-var md = require('../../../')('commonmark');
+var md = markdownit('commonmark');
// Replace normalizers to more primitive, for more "honest" compare.
// Default ones can cause 1.5x slowdown.
@@ -9,6 +9,6 @@ var encode = md.utils.lib.mdurl.encode;
md.normalizeLink = function (url) { return encode(url); };
md.normalizeLinkText = function (str) { return str; };
-exports.run = function (data) {
+export function run(data) {
return md.render(data);
-};
+}
diff --git a/benchmark/implementations/current/index.js b/benchmark/implementations/current/index.js
deleted file mode 100644
index c34bb75..0000000
--- a/benchmark/implementations/current/index.js
+++ /dev/null
@@ -1,11 +0,0 @@
-'use strict';
-
-var md = require('../../../')({
- html: true,
- linkify: true,
- typographer: true
-});
-
-exports.run = function (data) {
- return md.render(data);
-};
diff --git a/benchmark/implementations/current/index.mjs b/benchmark/implementations/current/index.mjs
new file mode 100644
index 0000000..97e1519
--- /dev/null
+++ b/benchmark/implementations/current/index.mjs
@@ -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);
+}
diff --git a/benchmark/implementations/markdown-it-2.2.1-commonmark/index.js b/benchmark/implementations/markdown-it-2.2.1-commonmark/index.js
deleted file mode 100644
index 58b13e6..0000000
--- a/benchmark/implementations/markdown-it-2.2.1-commonmark/index.js
+++ /dev/null
@@ -1,7 +0,0 @@
-'use strict';
-
-var md = require('../../extra/lib/node_modules/markdown-it')('commonmark');
-
-exports.run = function (data) {
- return md.render(data);
-};
diff --git a/benchmark/implementations/markdown-it-2.2.1-commonmark/index.mjs b/benchmark/implementations/markdown-it-2.2.1-commonmark/index.mjs
new file mode 100644
index 0000000..995441e
--- /dev/null
+++ b/benchmark/implementations/markdown-it-2.2.1-commonmark/index.mjs
@@ -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);
+}
diff --git a/benchmark/implementations/marked/index.js b/benchmark/implementations/marked/index.js
deleted file mode 100644
index e7e1842..0000000
--- a/benchmark/implementations/marked/index.js
+++ /dev/null
@@ -1,7 +0,0 @@
-'use strict';
-
-var marked = require('../../extra/lib/node_modules/marked');
-
-exports.run = function (data) {
- return marked(data);
-};
diff --git a/benchmark/implementations/marked/index.mjs b/benchmark/implementations/marked/index.mjs
new file mode 100644
index 0000000..21a88f1
--- /dev/null
+++ b/benchmark/implementations/marked/index.mjs
@@ -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);
+}
diff --git a/benchmark/profile.js b/benchmark/profile.js
deleted file mode 100755
index ddc378b..0000000
--- a/benchmark/profile.js
+++ /dev/null
@@ -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);
-}
diff --git a/benchmark/profile.mjs b/benchmark/profile.mjs
new file mode 100755
index 0000000..857582c
--- /dev/null
+++ b/benchmark/profile.mjs
@@ -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);
+}
diff --git a/benchmark/samples/README.md b/benchmark/samples/README.md
index bc4f98a..196c806 100644
--- a/benchmark/samples/README.md
+++ b/benchmark/samples/README.md
@@ -217,7 +217,7 @@ md = require('markdown-it')('full', {
Here is result of CommonMark spec parse at Core i5 2.4 GHz (i5-4258U):
```bash
-$ benchmark/benchmark.js spec
+$ benchmark/benchmark.mjs spec
Selected samples: (1 of 27)
> spec
diff --git a/bin/markdown-it.js b/bin/markdown-it.mjs
similarity index 91%
rename from bin/markdown-it.js
rename to bin/markdown-it.mjs
index d916635..7ba2e53 100755
--- a/bin/markdown-it.js
+++ b/bin/markdown-it.mjs
@@ -1,12 +1,9 @@
#!/usr/bin/env node
/*eslint no-console:0*/
-'use strict';
-
-
-var fs = require('fs');
-var argparse = require('argparse');
-
+import fs from 'node:fs';
+import argparse from 'argparse';
+import markdownit from '../index.mjs';
////////////////////////////////////////////////////////////////////////////////
@@ -17,7 +14,7 @@ var cli = new argparse.ArgumentParser({
cli.add_argument('-v', '--version', {
action: 'version',
- version: require('../package.json').version
+ version: JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url))).version
});
cli.add_argument('--no-html', {
@@ -89,7 +86,7 @@ readFile(options.file, 'utf8', function (err, input) {
process.exit(1);
}
- md = require('..')({
+ md = markdownit({
html: !options.no_html,
xhtmlOut: false,
typographer: options.typographer,
diff --git a/index.js b/index.js
deleted file mode 100644
index f71477e..0000000
--- a/index.js
+++ /dev/null
@@ -1,4 +0,0 @@
-'use strict';
-
-
-module.exports = require('./lib/');
diff --git a/index.mjs b/index.mjs
new file mode 100644
index 0000000..33cef2c
--- /dev/null
+++ b/index.mjs
@@ -0,0 +1 @@
+export { default } from './lib/index.mjs';
diff --git a/lib/.eslintrc.yml b/lib/.eslintrc.yml
new file mode 100644
index 0000000..2c1d793
--- /dev/null
+++ b/lib/.eslintrc.yml
@@ -0,0 +1,5 @@
+env:
+ node: false
+
+parserOptions:
+ ecmaVersion: 2015
diff --git a/lib/common/html_blocks.js b/lib/common/html_blocks.mjs
similarity index 95%
rename from lib/common/html_blocks.js
rename to lib/common/html_blocks.mjs
index 7af48fb..db607bd 100644
--- a/lib/common/html_blocks.js
+++ b/lib/common/html_blocks.mjs
@@ -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',
diff --git a/lib/common/html_re.js b/lib/common/html_re.mjs
similarity index 88%
rename from lib/common/html_re.js
rename to lib/common/html_re.mjs
index df81906..df6ee9f 100644
--- a/lib/common/html_re.js
+++ b/lib/common/html_re.mjs
@@ -1,7 +1,5 @@
// Regexps to match html elements
-'use strict';
-
var attr_name = '[a-zA-Z_:][a-zA-Z0-9:._-]*';
var unquoted = '[^"\'=<>`\\x00-\\x20]+';
@@ -24,5 +22,4 @@ var HTML_TAG_RE = new RegExp('^(?:' + open_tag + '|' + close_tag + '|' + comment
'|' + processing + '|' + declaration + '|' + cdata + ')');
var HTML_OPEN_CLOSE_TAG_RE = new RegExp('^(?:' + open_tag + '|' + close_tag + ')');
-module.exports.HTML_TAG_RE = HTML_TAG_RE;
-module.exports.HTML_OPEN_CLOSE_TAG_RE = HTML_OPEN_CLOSE_TAG_RE;
+export { HTML_TAG_RE, HTML_OPEN_CLOSE_TAG_RE };
diff --git a/lib/common/utils.js b/lib/common/utils.mjs
similarity index 89%
rename from lib/common/utils.js
rename to lib/common/utils.mjs
index 3f02f36..3220e44 100644
--- a/lib/common/utils.js
+++ b/lib/common/utils.mjs
@@ -1,7 +1,10 @@
// Utilities
//
-'use strict';
+import mdurl from 'mdurl';
+import ucmicro from 'uc.micro';
+import { decodeHTML } from 'entities';
+import UNICODE_PUNCT_RE from 'uc.micro/categories/P/regex.js';
function _class(obj) { return Object.prototype.toString.call(obj); }
@@ -77,7 +80,6 @@ var UNESCAPE_ALL_RE = new RegExp(UNESCAPE_MD_RE.source + '|' + ENTITY_RE.source,
var DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))$/i;
-var decodeHTML = require('entities').decodeHTML;
function replaceEntityPattern(match, name) {
var decoded, code;
@@ -185,7 +187,6 @@ function isWhiteSpace(code) {
////////////////////////////////////////////////////////////////////////////////
/*eslint-disable max-len*/
-var UNICODE_PUNCT_RE = require('uc.micro/categories/P/regex');
// Currently without astral characters support.
function isPunctChar(ch) {
@@ -298,23 +299,42 @@ function normalizeReference(str) {
// so plugins won't have to depend on them explicitly, which reduces their
// bundled size (e.g. a browser build).
//
-exports.lib = {};
-exports.lib.mdurl = require('mdurl');
-exports.lib.ucmicro = require('uc.micro');
-
-exports.assign = assign;
-exports.isString = isString;
-exports.has = has;
-exports.unescapeMd = unescapeMd;
-exports.unescapeAll = unescapeAll;
-exports.isValidEntityCode = isValidEntityCode;
-exports.fromCodePoint = fromCodePoint;
-// exports.replaceEntities = replaceEntities;
-exports.escapeHtml = escapeHtml;
-exports.arrayReplaceAt = arrayReplaceAt;
-exports.isSpace = isSpace;
-exports.isWhiteSpace = isWhiteSpace;
-exports.isMdAsciiPunct = isMdAsciiPunct;
-exports.isPunctChar = isPunctChar;
-exports.escapeRE = escapeRE;
-exports.normalizeReference = normalizeReference;
+const lib = { mdurl, ucmicro };
+
+export {
+ lib,
+ assign,
+ isString,
+ has,
+ unescapeMd,
+ unescapeAll,
+ isValidEntityCode,
+ fromCodePoint,
+ escapeHtml,
+ arrayReplaceAt,
+ isSpace,
+ isWhiteSpace,
+ isMdAsciiPunct,
+ isPunctChar,
+ escapeRE,
+ normalizeReference
+};
+
+export default {
+ lib,
+ assign,
+ isString,
+ has,
+ unescapeMd,
+ unescapeAll,
+ isValidEntityCode,
+ fromCodePoint,
+ escapeHtml,
+ arrayReplaceAt,
+ isSpace,
+ isWhiteSpace,
+ isMdAsciiPunct,
+ isPunctChar,
+ escapeRE,
+ normalizeReference
+};
diff --git a/lib/helpers/index.js b/lib/helpers/index.js
deleted file mode 100644
index bfdbfa2..0000000
--- a/lib/helpers/index.js
+++ /dev/null
@@ -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');
diff --git a/lib/helpers/index.mjs b/lib/helpers/index.mjs
new file mode 100644
index 0000000..150f087
--- /dev/null
+++ b/lib/helpers/index.mjs
@@ -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
+};
diff --git a/lib/helpers/parse_link_destination.js b/lib/helpers/parse_link_destination.mjs
similarity index 91%
rename from lib/helpers/parse_link_destination.js
rename to lib/helpers/parse_link_destination.mjs
index 4840ff8..5dfa1bd 100644
--- a/lib/helpers/parse_link_destination.js
+++ b/lib/helpers/parse_link_destination.mjs
@@ -1,12 +1,9 @@
// Parse link destination
//
-'use strict';
+import { unescapeAll } from '../common/utils.mjs';
-var unescapeAll = require('../common/utils').unescapeAll;
-
-
-module.exports = function parseLinkDestination(str, start, max) {
+export default function parseLinkDestination(str, start, max) {
var code, level,
pos = start,
result = {
@@ -77,4 +74,4 @@ module.exports = function parseLinkDestination(str, start, max) {
result.pos = pos;
result.ok = true;
return result;
-};
+}
diff --git a/lib/helpers/parse_link_label.js b/lib/helpers/parse_link_label.mjs
similarity index 91%
rename from lib/helpers/parse_link_label.js
rename to lib/helpers/parse_link_label.mjs
index 5a450fd..6750793 100644
--- a/lib/helpers/parse_link_label.js
+++ b/lib/helpers/parse_link_label.mjs
@@ -3,9 +3,8 @@
// this function assumes that first character ("[") already matches;
// returns the end of the label
//
-'use strict';
-module.exports = function parseLinkLabel(state, start, disableNested) {
+export default function parseLinkLabel(state, start, disableNested) {
var level, found, marker, prevPos,
labelEnd = -1,
max = state.posMax,
@@ -45,4 +44,4 @@ module.exports = function parseLinkLabel(state, start, disableNested) {
state.pos = oldPos;
return labelEnd;
-};
+}
diff --git a/lib/helpers/parse_link_title.js b/lib/helpers/parse_link_title.mjs
similarity index 93%
rename from lib/helpers/parse_link_title.js
rename to lib/helpers/parse_link_title.mjs
index f64f87c..e283ae9 100644
--- a/lib/helpers/parse_link_title.js
+++ b/lib/helpers/parse_link_title.mjs
@@ -1,12 +1,10 @@
// Parse link title
//
-'use strict';
+import { unescapeAll } from '../common/utils.mjs';
-var unescapeAll = require('../common/utils').unescapeAll;
-
-module.exports = function parseLinkTitle(str, start, max) {
+export default function parseLinkTitle(str, start, max) {
var code,
marker,
lines = 0,
@@ -52,4 +50,4 @@ module.exports = function parseLinkTitle(str, start, max) {
}
return result;
-};
+}
diff --git a/lib/index.js b/lib/index.mjs
similarity index 96%
rename from lib/index.js
rename to lib/index.mjs
index 5b722c2..8ea5cea 100644
--- a/lib/index.js
+++ b/lib/index.mjs
@@ -1,23 +1,23 @@
// Main parser class
-'use strict';
-
-
-var utils = require('./common/utils');
-var helpers = require('./helpers');
-var Renderer = require('./renderer');
-var ParserCore = require('./parser_core');
-var ParserBlock = require('./parser_block');
-var ParserInline = require('./parser_inline');
-var LinkifyIt = require('linkify-it');
-var mdurl = require('mdurl');
-var punycode = require('punycode/');
-
+import utils from './common/utils.mjs';
+import helpers from './helpers/index.mjs';
+import Renderer from './renderer.mjs';
+import ParserCore from './parser_core.mjs';
+import ParserBlock from './parser_block.mjs';
+import ParserInline from './parser_inline.mjs';
+import LinkifyIt from 'linkify-it';
+import mdurl from 'mdurl';
+import punycode from 'punycode';
+
+import cfg_default from './presets/default.mjs';
+import cfg_zero from './presets/zero.mjs';
+import cfg_commonmark from './presets/commonmark.mjs';
var config = {
- default: require('./presets/default'),
- zero: require('./presets/zero'),
- commonmark: require('./presets/commonmark')
+ default: cfg_default,
+ zero: cfg_zero,
+ commonmark: cfg_commonmark
};
////////////////////////////////////////////////////////////////////////////////
@@ -329,7 +329,7 @@ function MarkdownIt(presetName, options) {
* MarkdownIt#utils -> utils
*
* Assorted utility functions, useful to write plugins. See details
- * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/common/utils.js).
+ * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/common/utils.mjs).
**/
this.utils = utils;
@@ -579,4 +579,4 @@ MarkdownIt.prototype.renderInline = function (src, env) {
};
-module.exports = MarkdownIt;
+export default MarkdownIt;
diff --git a/lib/parser_block.js b/lib/parser_block.mjs
similarity index 65%
rename from lib/parser_block.js
rename to lib/parser_block.mjs
index 61f184f..106d476 100644
--- a/lib/parser_block.js
+++ b/lib/parser_block.mjs
@@ -3,26 +3,36 @@
*
* Block-level tokenizer.
**/
-'use strict';
-
-
-var Ruler = require('./ruler');
+import Ruler from './ruler.mjs';
+import StateBlock from './rules_block/state_block.mjs';
+
+import r_table from './rules_block/table.mjs';
+import r_code from './rules_block/code.mjs';
+import r_fence from './rules_block/fence.mjs';
+import r_blockquote from './rules_block/blockquote.mjs';
+import r_hr from './rules_block/hr.mjs';
+import r_list from './rules_block/list.mjs';
+import r_reference from './rules_block/reference.mjs';
+import r_html_block from './rules_block/html_block.mjs';
+import r_heading from './rules_block/heading.mjs';
+import r_lheading from './rules_block/lheading.mjs';
+import r_paragraph from './rules_block/paragraph.mjs';
var _rules = [
// First 2 params - rule name & source. Secondary array - list of rules,
// which can be terminated by this one.
- [ 'table', require('./rules_block/table'), [ 'paragraph', 'reference' ] ],
- [ 'code', require('./rules_block/code') ],
- [ 'fence', require('./rules_block/fence'), [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
- [ 'blockquote', require('./rules_block/blockquote'), [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
- [ 'hr', require('./rules_block/hr'), [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
- [ 'list', require('./rules_block/list'), [ 'paragraph', 'reference', 'blockquote' ] ],
- [ 'reference', require('./rules_block/reference') ],
- [ 'html_block', require('./rules_block/html_block'), [ 'paragraph', 'reference', 'blockquote' ] ],
- [ 'heading', require('./rules_block/heading'), [ 'paragraph', 'reference', 'blockquote' ] ],
- [ 'lheading', require('./rules_block/lheading') ],
- [ 'paragraph', require('./rules_block/paragraph') ]
+ [ 'table', r_table, [ 'paragraph', 'reference' ] ],
+ [ 'code', r_code ],
+ [ 'fence', r_fence, [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
+ [ 'blockquote', r_blockquote, [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
+ [ 'hr', r_hr, [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
+ [ 'list', r_list, [ 'paragraph', 'reference', 'blockquote' ] ],
+ [ 'reference', r_reference ],
+ [ 'html_block', r_html_block, [ 'paragraph', 'reference', 'blockquote' ] ],
+ [ 'heading', r_heading, [ 'paragraph', 'reference', 'blockquote' ] ],
+ [ 'lheading', r_lheading ],
+ [ 'paragraph', r_paragraph ]
];
@@ -125,7 +135,7 @@ ParserBlock.prototype.parse = function (src, md, env, outTokens) {
};
-ParserBlock.prototype.State = require('./rules_block/state_block');
+ParserBlock.prototype.State = StateBlock;
-module.exports = ParserBlock;
+export default ParserBlock;
diff --git a/lib/parser_core.js b/lib/parser_core.js
deleted file mode 100644
index a8831fb..0000000
--- a/lib/parser_core.js
+++ /dev/null
@@ -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;
diff --git a/lib/parser_core.mjs b/lib/parser_core.mjs
new file mode 100644
index 0000000..4e9ce95
--- /dev/null
+++ b/lib/parser_core.mjs
@@ -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;
diff --git a/lib/parser_inline.js b/lib/parser_inline.mjs
similarity index 71%
rename from lib/parser_inline.js
rename to lib/parser_inline.mjs
index a076e42..202aba4 100644
--- a/lib/parser_inline.js
+++ b/lib/parser_inline.mjs
@@ -3,28 +3,44 @@
*
* Tokenizes paragraph content.
**/
-'use strict';
+import Ruler from './ruler.mjs';
+import StateInline from './rules_inline/state_inline.mjs';
+
+import r_text from './rules_inline/text.mjs';
+import r_linkify from './rules_inline/linkify.mjs';
+import r_newline from './rules_inline/newline.mjs';
+import r_escape from './rules_inline/escape.mjs';
+import r_backticks from './rules_inline/backticks.mjs';
+import r_strikethrough from './rules_inline/strikethrough.mjs';
+import r_emphasis from './rules_inline/emphasis.mjs';
+import r_link from './rules_inline/link.mjs';
+import r_image from './rules_inline/image.mjs';
+import r_autolink from './rules_inline/autolink.mjs';
+import r_html_inline from './rules_inline/html_inline.mjs';
+import r_entity from './rules_inline/entity.mjs';
+
+import r_balance_pairs from './rules_inline/balance_pairs.mjs';
+import r_fragments_join from './rules_inline/fragments_join.mjs';
-var Ruler = require('./ruler');
////////////////////////////////////////////////////////////////////////////////
// Parser rules
var _rules = [
- [ 'text', require('./rules_inline/text') ],
- [ 'linkify', require('./rules_inline/linkify') ],
- [ 'newline', require('./rules_inline/newline') ],
- [ 'escape', require('./rules_inline/escape') ],
- [ 'backticks', require('./rules_inline/backticks') ],
- [ 'strikethrough', require('./rules_inline/strikethrough').tokenize ],
- [ 'emphasis', require('./rules_inline/emphasis').tokenize ],
- [ 'link', require('./rules_inline/link') ],
- [ 'image', require('./rules_inline/image') ],
- [ 'autolink', require('./rules_inline/autolink') ],
- [ 'html_inline', require('./rules_inline/html_inline') ],
- [ 'entity', require('./rules_inline/entity') ]
+ [ 'text', r_text ],
+ [ 'linkify', r_linkify ],
+ [ 'newline', r_newline ],
+ [ 'escape', r_escape ],
+ [ 'backticks', r_backticks ],
+ [ 'strikethrough', r_strikethrough.tokenize ],
+ [ 'emphasis', r_emphasis.tokenize ],
+ [ 'link', r_link ],
+ [ 'image', r_image ],
+ [ 'autolink', r_autolink ],
+ [ 'html_inline', r_html_inline ],
+ [ 'entity', r_entity ]
];
// `rule2` ruleset was created specifically for emphasis/strikethrough
@@ -33,12 +49,12 @@ var _rules = [
// Don't use this for anything except pairs (plugins working with `balance_pairs`).
//
var _rules2 = [
- [ 'balance_pairs', require('./rules_inline/balance_pairs') ],
- [ 'strikethrough', require('./rules_inline/strikethrough').postProcess ],
- [ 'emphasis', require('./rules_inline/emphasis').postProcess ],
+ [ 'balance_pairs', r_balance_pairs ],
+ [ 'strikethrough', r_strikethrough.postProcess ],
+ [ 'emphasis', r_emphasis.postProcess ],
// rules for pairs separate '**' into its own text tokens, which may be left unused,
// rule below merges unused segments back with the rest of the text
- [ 'fragments_join', require('./rules_inline/fragments_join') ]
+ [ 'fragments_join', r_fragments_join ]
];
@@ -186,7 +202,7 @@ ParserInline.prototype.parse = function (str, md, env, outTokens) {
};
-ParserInline.prototype.State = require('./rules_inline/state_inline');
+ParserInline.prototype.State = StateInline;
-module.exports = ParserInline;
+export default ParserInline;
diff --git a/lib/presets/commonmark.js b/lib/presets/commonmark.mjs
similarity index 98%
rename from lib/presets/commonmark.js
rename to lib/presets/commonmark.mjs
index c0a8275..621742d 100644
--- a/lib/presets/commonmark.js
+++ b/lib/presets/commonmark.mjs
@@ -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 (
)
diff --git a/lib/presets/default.js b/lib/presets/default.mjs
similarity index 97%
rename from lib/presets/default.js
rename to lib/presets/default.mjs
index 17ecef2..1777dd4 100644
--- a/lib/presets/default.js
+++ b/lib/presets/default.mjs
@@ -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 (
)
diff --git a/lib/presets/zero.js b/lib/presets/zero.mjs
similarity index 97%
rename from lib/presets/zero.js
rename to lib/presets/zero.mjs
index fc90aac..34e22f6 100644
--- a/lib/presets/zero.js
+++ b/lib/presets/zero.mjs
@@ -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 (
)
diff --git a/lib/renderer.js b/lib/renderer.mjs
similarity index 97%
rename from lib/renderer.js
rename to lib/renderer.mjs
index 268cf78..e1f61fe 100644
--- a/lib/renderer.js
+++ b/lib/renderer.mjs
@@ -5,13 +5,8 @@
* copy of rules. Those can be rewritten with ease. Also, you can add new
* rules if you create plugin and adds new token types.
**/
-'use strict';
-
-
-var assign = require('./common/utils').assign;
-var unescapeAll = require('./common/utils').unescapeAll;
-var escapeHtml = require('./common/utils').escapeHtml;
+import { assign, unescapeAll, escapeHtml } from './common/utils.mjs';
////////////////////////////////////////////////////////////////////////////////
@@ -338,4 +333,4 @@ Renderer.prototype.render = function (tokens, options, env) {
return result;
};
-module.exports = Renderer;
+export default Renderer;
diff --git a/lib/ruler.js b/lib/ruler.mjs
similarity index 99%
rename from lib/ruler.js
rename to lib/ruler.mjs
index 9ad5da4..83591f0 100644
--- a/lib/ruler.js
+++ b/lib/ruler.mjs
@@ -15,7 +15,6 @@
* rules control use [[MarkdownIt.disable]], [[MarkdownIt.enable]] and
* [[MarkdownIt.use]].
**/
-'use strict';
/**
@@ -349,4 +348,4 @@ Ruler.prototype.getRules = function (chainName) {
return this.__cache__[chainName] || [];
};
-module.exports = Ruler;
+export default Ruler;
diff --git a/lib/rules_block/blockquote.js b/lib/rules_block/blockquote.mjs
similarity index 97%
rename from lib/rules_block/blockquote.js
rename to lib/rules_block/blockquote.mjs
index e4044cb..65bba4f 100644
--- a/lib/rules_block/blockquote.js
+++ b/lib/rules_block/blockquote.mjs
@@ -1,11 +1,8 @@
// Block quotes
-'use strict';
+import { isSpace } from '../common/utils.mjs';
-var isSpace = require('../common/utils').isSpace;
-
-
-module.exports = function blockquote(state, startLine, endLine, silent) {
+export default function blockquote(state, startLine, endLine, silent) {
var adjustTab,
ch,
i,
@@ -223,4 +220,4 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
state.blkIndent = oldIndent;
return true;
-};
+}
diff --git a/lib/rules_block/code.js b/lib/rules_block/code.mjs
similarity index 87%
rename from lib/rules_block/code.js
rename to lib/rules_block/code.mjs
index 018e019..252f385 100644
--- a/lib/rules_block/code.js
+++ b/lib/rules_block/code.mjs
@@ -1,9 +1,6 @@
// Code block (4 spaces padded)
-'use strict';
-
-
-module.exports = function code(state, startLine, endLine/*, silent*/) {
+export default function code(state, startLine, endLine/*, silent*/) {
var nextLine, last, token;
if (state.sCount[startLine] - state.blkIndent < 4) { return false; }
@@ -31,4 +28,4 @@ module.exports = function code(state, startLine, endLine/*, silent*/) {
token.map = [ startLine, state.line ];
return true;
-};
+}
diff --git a/lib/rules_block/fence.js b/lib/rules_block/fence.mjs
similarity index 96%
rename from lib/rules_block/fence.js
rename to lib/rules_block/fence.mjs
index 44f1538..498e841 100644
--- a/lib/rules_block/fence.js
+++ b/lib/rules_block/fence.mjs
@@ -1,9 +1,6 @@
// fences (``` lang, ~~~ lang)
-'use strict';
-
-
-module.exports = function fence(state, startLine, endLine, silent) {
+export default function fence(state, startLine, endLine, silent) {
var marker, len, params, nextLine, mem, token, markup,
haveEndMarker = false,
pos = state.bMarks[startLine] + state.tShift[startLine],
@@ -95,4 +92,4 @@ module.exports = function fence(state, startLine, endLine, silent) {
token.map = [ startLine, state.line ];
return true;
-};
+}
diff --git a/lib/rules_block/heading.js b/lib/rules_block/heading.mjs
similarity index 90%
rename from lib/rules_block/heading.js
rename to lib/rules_block/heading.mjs
index 9863f48..0bbd2d2 100644
--- a/lib/rules_block/heading.js
+++ b/lib/rules_block/heading.mjs
@@ -1,11 +1,8 @@
// heading (#, ##, ...)
-'use strict';
+import { isSpace } from '../common/utils.mjs';
-var isSpace = require('../common/utils').isSpace;
-
-
-module.exports = function heading(state, startLine, endLine, silent) {
+export default function heading(state, startLine, endLine, silent) {
var ch, level, tmp, token,
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
@@ -52,4 +49,4 @@ module.exports = function heading(state, startLine, endLine, silent) {
token.markup = '########'.slice(0, level);
return true;
-};
+}
diff --git a/lib/rules_block/hr.js b/lib/rules_block/hr.mjs
similarity index 87%
rename from lib/rules_block/hr.js
rename to lib/rules_block/hr.mjs
index a3bb14e..e7ae1e8 100644
--- a/lib/rules_block/hr.js
+++ b/lib/rules_block/hr.mjs
@@ -1,11 +1,8 @@
// Horizontal rule
-'use strict';
+import { isSpace } from '../common/utils.mjs';
-var isSpace = require('../common/utils').isSpace;
-
-
-module.exports = function hr(state, startLine, endLine, silent) {
+export default function hr(state, startLine, endLine, silent) {
var marker, cnt, ch, token,
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
@@ -42,4 +39,4 @@ module.exports = function hr(state, startLine, endLine, silent) {
token.markup = Array(cnt + 1).join(String.fromCharCode(marker));
return true;
-};
+}
diff --git a/lib/rules_block/html_block.js b/lib/rules_block/html_block.mjs
similarity index 90%
rename from lib/rules_block/html_block.js
rename to lib/rules_block/html_block.mjs
index 2f17675..4d5f356 100644
--- a/lib/rules_block/html_block.js
+++ b/lib/rules_block/html_block.mjs
@@ -1,10 +1,7 @@
// HTML block
-'use strict';
-
-
-var block_names = require('../common/html_blocks');
-var HTML_OPEN_CLOSE_TAG_RE = require('../common/html_re').HTML_OPEN_CLOSE_TAG_RE;
+import block_names from '../common/html_blocks.mjs';
+import { HTML_OPEN_CLOSE_TAG_RE } from '../common/html_re.mjs';
// An array of opening and corresponding closing sequences for html tags,
// last argument defines whether it can terminate a paragraph or not
@@ -20,7 +17,7 @@ var HTML_SEQUENCES = [
];
-module.exports = function html_block(state, startLine, endLine, silent) {
+export default function html_block(state, startLine, endLine, silent) {
var i, nextLine, token, lineText,
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
@@ -71,4 +68,4 @@ module.exports = function html_block(state, startLine, endLine, silent) {
token.content = state.getLines(startLine, nextLine, state.blkIndent, true);
return true;
-};
+}
diff --git a/lib/rules_block/lheading.js b/lib/rules_block/lheading.mjs
similarity index 96%
rename from lib/rules_block/lheading.js
rename to lib/rules_block/lheading.mjs
index 19bdc39..aa532e2 100644
--- a/lib/rules_block/lheading.js
+++ b/lib/rules_block/lheading.mjs
@@ -1,9 +1,6 @@
// lheading (---, ===)
-'use strict';
-
-
-module.exports = function lheading(state, startLine, endLine/*, silent*/) {
+export default function lheading(state, startLine, endLine/*, silent*/) {
var content, terminate, i, l, token, pos, max, level, marker,
nextLine = startLine + 1, oldParentType,
terminatorRules = state.md.block.ruler.getRules('paragraph');
@@ -80,4 +77,4 @@ module.exports = function lheading(state, startLine, endLine/*, silent*/) {
state.parentType = oldParentType;
return true;
-};
+}
diff --git a/lib/rules_block/list.js b/lib/rules_block/list.mjs
similarity index 98%
rename from lib/rules_block/list.js
rename to lib/rules_block/list.mjs
index f45aebc..aa101c3 100644
--- a/lib/rules_block/list.js
+++ b/lib/rules_block/list.mjs
@@ -1,9 +1,6 @@
// Lists
-'use strict';
-
-var isSpace = require('../common/utils').isSpace;
-
+import { isSpace } from '../common/utils.mjs';
// Search `[-+*][\n ]`, returns next pos after marker on success
// or -1 on fail.
@@ -97,7 +94,7 @@ function markTightParagraphs(state, idx) {
}
-module.exports = function list(state, startLine, endLine, silent) {
+export default function list(state, startLine, endLine, silent) {
var ch,
contentStart,
i,
@@ -359,4 +356,4 @@ module.exports = function list(state, startLine, endLine, silent) {
}
return true;
-};
+}
diff --git a/lib/rules_block/paragraph.js b/lib/rules_block/paragraph.mjs
similarity index 94%
rename from lib/rules_block/paragraph.js
rename to lib/rules_block/paragraph.mjs
index 31d25b2..5f6e1b2 100644
--- a/lib/rules_block/paragraph.js
+++ b/lib/rules_block/paragraph.mjs
@@ -1,9 +1,6 @@
// Paragraph
-'use strict';
-
-
-module.exports = function paragraph(state, startLine, endLine) {
+export default function paragraph(state, startLine, endLine) {
var content, terminate, i, l, token, oldParentType,
nextLine = startLine + 1,
terminatorRules = state.md.block.ruler.getRules('paragraph');
@@ -48,4 +45,4 @@ module.exports = function paragraph(state, startLine, endLine) {
state.parentType = oldParentType;
return true;
-};
+}
diff --git a/lib/rules_block/reference.js b/lib/rules_block/reference.mjs
similarity index 95%
rename from lib/rules_block/reference.js
rename to lib/rules_block/reference.mjs
index 78daa26..9ba5e3c 100644
--- a/lib/rules_block/reference.js
+++ b/lib/rules_block/reference.mjs
@@ -1,11 +1,6 @@
-'use strict';
+import { isSpace, normalizeReference } from '../common/utils.mjs';
-
-var normalizeReference = require('../common/utils').normalizeReference;
-var isSpace = require('../common/utils').isSpace;
-
-
-module.exports = function reference(state, startLine, _endLine, silent) {
+export default function reference(state, startLine, _endLine, silent) {
var ch,
destEndPos,
destEndLineNo,
@@ -195,4 +190,4 @@ module.exports = function reference(state, startLine, _endLine, silent) {
state.line = startLine + lines + 1;
return true;
-};
+}
diff --git a/lib/rules_block/state_block.js b/lib/rules_block/state_block.mjs
similarity index 97%
rename from lib/rules_block/state_block.js
rename to lib/rules_block/state_block.mjs
index 58aa85b..5a5dcb3 100644
--- a/lib/rules_block/state_block.js
+++ b/lib/rules_block/state_block.mjs
@@ -1,9 +1,7 @@
// Parser state class
-'use strict';
-
-var Token = require('../token');
-var isSpace = require('../common/utils').isSpace;
+import Token from '../token.mjs';
+import { isSpace } from '../common/utils.mjs';
function StateBlock(src, md, env, tokens) {
@@ -225,4 +223,4 @@ StateBlock.prototype.getLines = function getLines(begin, end, indent, keepLastLF
StateBlock.prototype.Token = Token;
-module.exports = StateBlock;
+export default StateBlock;
diff --git a/lib/rules_block/table.js b/lib/rules_block/table.mjs
similarity index 97%
rename from lib/rules_block/table.js
rename to lib/rules_block/table.mjs
index 3cb416f..88d4b45 100644
--- a/lib/rules_block/table.js
+++ b/lib/rules_block/table.mjs
@@ -1,9 +1,6 @@
// GFM table, https://github.github.com/gfm/#tables-extension-
-'use strict';
-
-var isSpace = require('../common/utils').isSpace;
-
+import { isSpace } from '../common/utils.mjs';
function getLine(state, line) {
var pos = state.bMarks[line] + state.tShift[line],
@@ -49,7 +46,7 @@ function escapedSplit(str) {
}
-module.exports = function table(state, startLine, endLine, silent) {
+export default function table(state, startLine, endLine, silent) {
var ch, lineText, pos, i, l, nextLine, columns, columnCount, token,
aligns, t, tableLines, tbodyLines, oldParentType, terminate,
terminatorRules, firstCh, secondCh;
@@ -218,4 +215,4 @@ module.exports = function table(state, startLine, endLine, silent) {
state.parentType = oldParentType;
state.line = nextLine;
return true;
-};
+}
diff --git a/lib/rules_core/block.js b/lib/rules_core/block.mjs
similarity index 83%
rename from lib/rules_core/block.js
rename to lib/rules_core/block.mjs
index 2a365fa..62fa0bb 100644
--- a/lib/rules_core/block.js
+++ b/lib/rules_core/block.mjs
@@ -1,7 +1,4 @@
-'use strict';
-
-
-module.exports = function block(state) {
+export default function block(state) {
var token;
if (state.inlineMode) {
@@ -13,4 +10,4 @@ module.exports = function block(state) {
} else {
state.md.block.parse(state.src, state.md, state.env, state.tokens);
}
-};
+}
diff --git a/lib/rules_core/inline.js b/lib/rules_core/inline.mjs
similarity index 80%
rename from lib/rules_core/inline.js
rename to lib/rules_core/inline.mjs
index 4c33d0d..5c00ef0 100644
--- a/lib/rules_core/inline.js
+++ b/lib/rules_core/inline.mjs
@@ -1,6 +1,4 @@
-'use strict';
-
-module.exports = function inline(state) {
+export default function inline(state) {
var tokens = state.tokens, tok, i, l;
// Parse inlines
@@ -10,4 +8,4 @@ module.exports = function inline(state) {
state.md.inline.parse(tok.content, state.md, state.env, tok.children);
}
}
-};
+}
diff --git a/lib/rules_core/linkify.js b/lib/rules_core/linkify.mjs
similarity index 97%
rename from lib/rules_core/linkify.js
rename to lib/rules_core/linkify.mjs
index 11294a5..8d1e265 100644
--- a/lib/rules_core/linkify.js
+++ b/lib/rules_core/linkify.mjs
@@ -2,10 +2,8 @@
//
// Currently restricted by `md.validateLink()` to http/https/ftp
//
-'use strict';
-
-var arrayReplaceAt = require('../common/utils').arrayReplaceAt;
+import { arrayReplaceAt } from '../common/utils.mjs';
function isLinkOpen(str) {
@@ -16,7 +14,7 @@ function isLinkClose(str) {
}
-module.exports = function linkify(state) {
+export default function linkify(state) {
var i, j, l, tokens, token, currentToken, nodes, ln, text, pos, lastPos,
level, htmlLinkLevel, url, fullUrl, urlText,
blockTokens = state.tokens,
@@ -139,4 +137,4 @@ module.exports = function linkify(state) {
}
}
}
-};
+}
diff --git a/lib/rules_core/normalize.js b/lib/rules_core/normalize.mjs
similarity index 83%
rename from lib/rules_core/normalize.js
rename to lib/rules_core/normalize.mjs
index ad196cd..64b68e0 100644
--- a/lib/rules_core/normalize.js
+++ b/lib/rules_core/normalize.mjs
@@ -1,14 +1,12 @@
// Normalize input string
-'use strict';
-
// https://spec.commonmark.org/0.29/#line-ending
var NEWLINES_RE = /\r\n?|\n/g;
var NULL_RE = /\0/g;
-module.exports = function normalize(state) {
+export default function normalize(state) {
var str;
// Normalize newlines
@@ -18,4 +16,4 @@ module.exports = function normalize(state) {
str = str.replace(NULL_RE, '\uFFFD');
state.src = str;
-};
+}
diff --git a/lib/rules_core/replacements.js b/lib/rules_core/replacements.mjs
similarity index 97%
rename from lib/rules_core/replacements.js
rename to lib/rules_core/replacements.mjs
index 9d8e55c..e41a6f4 100644
--- a/lib/rules_core/replacements.js
+++ b/lib/rules_core/replacements.mjs
@@ -8,7 +8,6 @@
// ???????? → ???, !!!!! → !!!, `,,` → `,`
// -- → –, --- → —
//
-'use strict';
// TODO:
// - fractionals 1/2, 1/4, 3/4 -> ½, ¼, ¾
@@ -84,7 +83,7 @@ function replace_rare(inlineTokens) {
}
-module.exports = function replace(state) {
+export default function replace(state) {
var blkIdx;
if (!state.md.options.typographer) { return; }
@@ -102,4 +101,4 @@ module.exports = function replace(state) {
}
}
-};
+}
diff --git a/lib/rules_core/smartquotes.js b/lib/rules_core/smartquotes.mjs
similarity index 95%
rename from lib/rules_core/smartquotes.js
rename to lib/rules_core/smartquotes.mjs
index 42d6851..45a7b12 100644
--- a/lib/rules_core/smartquotes.js
+++ b/lib/rules_core/smartquotes.mjs
@@ -1,11 +1,7 @@
// Convert straight quotation marks to typographic ones
//
-'use strict';
-
-var isWhiteSpace = require('../common/utils').isWhiteSpace;
-var isPunctChar = require('../common/utils').isPunctChar;
-var isMdAsciiPunct = require('../common/utils').isMdAsciiPunct;
+import { isWhiteSpace, isPunctChar, isMdAsciiPunct } from '../common/utils.mjs';
var QUOTE_TEST_RE = /['"]/;
var QUOTE_RE = /['"]/g;
@@ -183,7 +179,7 @@ function process_inlines(tokens, state) {
}
-module.exports = function smartquotes(state) {
+export default function smartquotes(state) {
/*eslint max-depth:0*/
var blkIdx;
@@ -198,4 +194,4 @@ module.exports = function smartquotes(state) {
process_inlines(state.tokens[blkIdx].children, state);
}
-};
+}
diff --git a/lib/rules_core/state_core.js b/lib/rules_core/state_core.mjs
similarity index 78%
rename from lib/rules_core/state_core.js
rename to lib/rules_core/state_core.mjs
index 87cfd85..5eddad0 100644
--- a/lib/rules_core/state_core.js
+++ b/lib/rules_core/state_core.mjs
@@ -1,9 +1,7 @@
// Core state object
//
-'use strict';
-
-var Token = require('../token');
+import Token from '../token.mjs';
function StateCore(src, md, env) {
this.src = src;
@@ -17,4 +15,4 @@ function StateCore(src, md, env) {
StateCore.prototype.Token = Token;
-module.exports = StateCore;
+export default StateCore;
diff --git a/lib/rules_core/text_join.js b/lib/rules_core/text_join.mjs
similarity index 94%
rename from lib/rules_core/text_join.js
rename to lib/rules_core/text_join.mjs
index a0c083a..83c245f 100644
--- a/lib/rules_core/text_join.js
+++ b/lib/rules_core/text_join.mjs
@@ -5,10 +5,8 @@
//
// For example, `\:)` shouldn't be replaced with an emoji.
//
-'use strict';
-
-module.exports = function text_join(state) {
+export default function text_join(state) {
var j, l, tokens, curr, max, last,
blockTokens = state.tokens;
@@ -42,4 +40,4 @@ module.exports = function text_join(state) {
tokens.length = last;
}
}
-};
+}
diff --git a/lib/rules_inline/autolink.js b/lib/rules_inline/autolink.mjs
similarity index 96%
rename from lib/rules_inline/autolink.js
rename to lib/rules_inline/autolink.mjs
index 66deb90..ed16432 100644
--- a/lib/rules_inline/autolink.js
+++ b/lib/rules_inline/autolink.mjs
@@ -1,14 +1,11 @@
// Process autolinks ''
-'use strict';
-
-
/*eslint max-len:0*/
var EMAIL_RE = /^([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)$/;
var AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.\-]{1,31}):([^<>\x00-\x20]*)$/;
-module.exports = function autolink(state, silent) {
+export default function autolink(state, silent) {
var url, fullUrl, token, ch, start, max,
pos = state.pos;
@@ -73,4 +70,4 @@ module.exports = function autolink(state, silent) {
}
return false;
-};
+}
diff --git a/lib/rules_inline/backticks.js b/lib/rules_inline/backticks.mjs
similarity index 95%
rename from lib/rules_inline/backticks.js
rename to lib/rules_inline/backticks.mjs
index 21282de..bbfdc55 100644
--- a/lib/rules_inline/backticks.js
+++ b/lib/rules_inline/backticks.mjs
@@ -1,9 +1,6 @@
// Parse backticks
-'use strict';
-
-
-module.exports = function backtick(state, silent) {
+export default function backtick(state, silent) {
var start, max, marker, token, matchStart, matchEnd, openerLength, closerLength,
pos = state.pos,
ch = state.src.charCodeAt(pos);
@@ -60,4 +57,4 @@ module.exports = function backtick(state, silent) {
if (!silent) state.pending += marker;
state.pos += openerLength;
return true;
-};
+}
diff --git a/lib/rules_inline/balance_pairs.js b/lib/rules_inline/balance_pairs.mjs
similarity index 98%
rename from lib/rules_inline/balance_pairs.js
rename to lib/rules_inline/balance_pairs.mjs
index d4fdfdb..2756e9a 100644
--- a/lib/rules_inline/balance_pairs.js
+++ b/lib/rules_inline/balance_pairs.mjs
@@ -1,7 +1,5 @@
// For each opening emphasis-like marker find a matching closing one
//
-'use strict';
-
function processDelimiters(delimiters) {
var closerIdx, openerIdx, closer, opener, minOpenerIdx, newMinOpenerIdx,
@@ -115,7 +113,7 @@ function processDelimiters(delimiters) {
}
-module.exports = function link_pairs(state) {
+export default function link_pairs(state) {
var curr,
tokens_meta = state.tokens_meta,
max = state.tokens_meta.length;
@@ -127,4 +125,4 @@ module.exports = function link_pairs(state) {
processDelimiters(tokens_meta[curr].delimiters);
}
}
-};
+}
diff --git a/lib/rules_inline/emphasis.js b/lib/rules_inline/emphasis.mjs
similarity index 95%
rename from lib/rules_inline/emphasis.js
rename to lib/rules_inline/emphasis.mjs
index 7e8ab4c..b55aa26 100644
--- a/lib/rules_inline/emphasis.js
+++ b/lib/rules_inline/emphasis.mjs
@@ -1,11 +1,9 @@
// Process *this* and _that_
//
-'use strict';
-
// Insert each marker as a separate text token, and add it to delimiter list
//
-module.exports.tokenize = function emphasis(state, silent) {
+function emphasis_tokenize(state, silent) {
var i, scanned, token,
start = state.pos,
marker = state.src.charCodeAt(start);
@@ -49,7 +47,7 @@ module.exports.tokenize = function emphasis(state, silent) {
state.pos += scanned.length;
return true;
-};
+}
function postProcess(state, delimiters) {
@@ -115,7 +113,7 @@ function postProcess(state, delimiters) {
// Walk through delimiter list and replace text tokens with tags
//
-module.exports.postProcess = function emphasis(state) {
+function emphasis_post_process(state) {
var curr,
tokens_meta = state.tokens_meta,
max = state.tokens_meta.length;
@@ -127,4 +125,9 @@ module.exports.postProcess = function emphasis(state) {
postProcess(state, tokens_meta[curr].delimiters);
}
}
+}
+
+export default {
+ tokenize: emphasis_tokenize,
+ postProcess: emphasis_post_process
};
diff --git a/lib/rules_inline/entity.js b/lib/rules_inline/entity.mjs
similarity index 83%
rename from lib/rules_inline/entity.js
rename to lib/rules_inline/entity.mjs
index 1ef5075..38d05d9 100644
--- a/lib/rules_inline/entity.js
+++ b/lib/rules_inline/entity.mjs
@@ -1,17 +1,14 @@
// Process html entity - {, ¯, ", ...
-'use strict';
-
-var decodeHTML = require('entities').decodeHTML;
-var isValidEntityCode = require('../common/utils').isValidEntityCode;
-var fromCodePoint = require('../common/utils').fromCodePoint;
+import { decodeHTML } from 'entities';
+import { isValidEntityCode, fromCodePoint } from '../common/utils.mjs';
var DIGITAL_RE = /^((?:x[a-f0-9]{1,6}|[0-9]{1,7}));/i;
var NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i;
-module.exports = function entity(state, silent) {
+export default function entity(state, silent) {
var ch, code, match, decoded, token, pos = state.pos, max = state.posMax;
if (state.src.charCodeAt(pos) !== 0x26/* & */) return false;
@@ -52,4 +49,4 @@ module.exports = function entity(state, silent) {
}
return false;
-};
+}
diff --git a/lib/rules_inline/escape.js b/lib/rules_inline/escape.mjs
similarity index 91%
rename from lib/rules_inline/escape.js
rename to lib/rules_inline/escape.mjs
index 8adda0c..3ee00d1 100644
--- a/lib/rules_inline/escape.js
+++ b/lib/rules_inline/escape.mjs
@@ -1,8 +1,6 @@
// Process escaped chars and hardbreaks
-'use strict';
-
-var isSpace = require('../common/utils').isSpace;
+import { isSpace } from '../common/utils.mjs';
var ESCAPED = [];
@@ -12,7 +10,7 @@ for (var i = 0; i < 256; i++) { ESCAPED.push(0); }
.split('').forEach(function (ch) { ESCAPED[ch.charCodeAt(0)] = 1; });
-module.exports = function escape(state, silent) {
+export default function escape(state, silent) {
var ch1, ch2, origStr, escapedStr, token, pos = state.pos, max = state.posMax;
if (state.src.charCodeAt(pos) !== 0x5C/* \ */) return false;
@@ -68,4 +66,4 @@ module.exports = function escape(state, silent) {
state.pos = pos + 1;
return true;
-};
+}
diff --git a/lib/rules_inline/fragments_join.js b/lib/rules_inline/fragments_join.mjs
similarity index 94%
rename from lib/rules_inline/fragments_join.js
rename to lib/rules_inline/fragments_join.mjs
index 0eafb45..3f321df 100644
--- a/lib/rules_inline/fragments_join.js
+++ b/lib/rules_inline/fragments_join.mjs
@@ -6,10 +6,8 @@
// leaves them as text (needed to merge with adjacent text) or turns them
// into opening/closing tags (which messes up levels inside).
//
-'use strict';
-
-module.exports = function fragments_join(state) {
+export default function fragments_join(state) {
var curr, last,
level = 0,
tokens = state.tokens,
@@ -38,4 +36,4 @@ module.exports = function fragments_join(state) {
if (curr !== last) {
tokens.length = last;
}
-};
+}
diff --git a/lib/rules_inline/html_inline.js b/lib/rules_inline/html_inline.mjs
similarity index 88%
rename from lib/rules_inline/html_inline.js
rename to lib/rules_inline/html_inline.mjs
index d307819..c5ac486 100644
--- a/lib/rules_inline/html_inline.js
+++ b/lib/rules_inline/html_inline.mjs
@@ -1,9 +1,6 @@
// Process html tags
-'use strict';
-
-
-var HTML_TAG_RE = require('../common/html_re').HTML_TAG_RE;
+import { HTML_TAG_RE } from '../common/html_re.mjs';
function isLinkOpen(str) {
@@ -21,7 +18,7 @@ function isLetter(ch) {
}
-module.exports = function html_inline(state, silent) {
+export default function html_inline(state, silent) {
var ch, match, max, token,
pos = state.pos;
@@ -55,4 +52,4 @@ module.exports = function html_inline(state, silent) {
}
state.pos += match[0].length;
return true;
-};
+}
diff --git a/lib/rules_inline/image.js b/lib/rules_inline/image.mjs
similarity index 94%
rename from lib/rules_inline/image.js
rename to lib/rules_inline/image.mjs
index 53edd32..8ca1d74 100644
--- a/lib/rules_inline/image.js
+++ b/lib/rules_inline/image.mjs
@@ -1,12 +1,9 @@
// Process ![image]( "title")
-'use strict';
+import { normalizeReference, isSpace } from '../common/utils.mjs';
-var normalizeReference = require('../common/utils').normalizeReference;
-var isSpace = require('../common/utils').isSpace;
-
-module.exports = function image(state, silent) {
+export default function image(state, silent) {
var attrs,
code,
content,
@@ -149,4 +146,4 @@ module.exports = function image(state, silent) {
state.pos = pos;
state.posMax = max;
return true;
-};
+}
diff --git a/lib/rules_inline/link.js b/lib/rules_inline/link.mjs
similarity index 94%
rename from lib/rules_inline/link.js
rename to lib/rules_inline/link.mjs
index fec5acb..475a6c7 100644
--- a/lib/rules_inline/link.js
+++ b/lib/rules_inline/link.mjs
@@ -1,12 +1,8 @@
// Process [link]( "stuff")
-'use strict';
+import { normalizeReference, isSpace } from '../common/utils.mjs';
-var normalizeReference = require('../common/utils').normalizeReference;
-var isSpace = require('../common/utils').isSpace;
-
-
-module.exports = function link(state, silent) {
+export default function link(state, silent) {
var attrs,
code,
label,
@@ -147,4 +143,4 @@ module.exports = function link(state, silent) {
state.pos = pos;
state.posMax = max;
return true;
-};
+}
diff --git a/lib/rules_inline/linkify.js b/lib/rules_inline/linkify.mjs
similarity index 95%
rename from lib/rules_inline/linkify.js
rename to lib/rules_inline/linkify.mjs
index 1d7cdd9..991890f 100644
--- a/lib/rules_inline/linkify.js
+++ b/lib/rules_inline/linkify.mjs
@@ -1,13 +1,10 @@
// Process links like https://example.org/
-'use strict';
-
-
// RFC3986: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
var SCHEME_RE = /(?:^|[^a-z0-9.+-])([a-z][a-z0-9.+-]*)$/i;
-module.exports = function linkify(state, silent) {
+export default function linkify(state, silent) {
var pos, max, match, proto, link, url, fullUrl, token;
if (!state.md.options.linkify) return false;
@@ -59,4 +56,4 @@ module.exports = function linkify(state, silent) {
state.pos += url.length - proto.length;
return true;
-};
+}
diff --git a/lib/rules_inline/newline.js b/lib/rules_inline/newline.mjs
similarity index 90%
rename from lib/rules_inline/newline.js
rename to lib/rules_inline/newline.mjs
index 9eeead4..562818a 100644
--- a/lib/rules_inline/newline.js
+++ b/lib/rules_inline/newline.mjs
@@ -1,11 +1,8 @@
// Proceess '\n'
-'use strict';
+import { isSpace } from '../common/utils.mjs';
-var isSpace = require('../common/utils').isSpace;
-
-
-module.exports = function newline(state, silent) {
+export default function newline(state, silent) {
var pmax, max, ws, pos = state.pos;
if (state.src.charCodeAt(pos) !== 0x0A/* \n */) { return false; }
@@ -43,4 +40,4 @@ module.exports = function newline(state, silent) {
state.pos = pos;
return true;
-};
+}
diff --git a/lib/rules_inline/state_inline.js b/lib/rules_inline/state_inline.mjs
similarity index 93%
rename from lib/rules_inline/state_inline.js
rename to lib/rules_inline/state_inline.mjs
index 5d41acd..45ac55d 100644
--- a/lib/rules_inline/state_inline.js
+++ b/lib/rules_inline/state_inline.mjs
@@ -1,13 +1,7 @@
// Inline parser state
-'use strict';
-
-
-var Token = require('../token');
-var isWhiteSpace = require('../common/utils').isWhiteSpace;
-var isPunctChar = require('../common/utils').isPunctChar;
-var isMdAsciiPunct = require('../common/utils').isMdAsciiPunct;
-
+import Token from '../token.mjs';
+import { isWhiteSpace, isPunctChar, isMdAsciiPunct } from '../common/utils.mjs';
function StateInline(src, md, env, outTokens) {
this.src = src;
@@ -155,4 +149,4 @@ StateInline.prototype.scanDelims = function (start, canSplitWord) {
StateInline.prototype.Token = Token;
-module.exports = StateInline;
+export default StateInline;
diff --git a/lib/rules_inline/strikethrough.js b/lib/rules_inline/strikethrough.mjs
similarity index 93%
rename from lib/rules_inline/strikethrough.js
rename to lib/rules_inline/strikethrough.mjs
index 3c35adf..1ef52c1 100644
--- a/lib/rules_inline/strikethrough.js
+++ b/lib/rules_inline/strikethrough.mjs
@@ -1,11 +1,9 @@
// ~~strike through~~
//
-'use strict';
-
// Insert each marker as a separate text token, and add it to delimiter list
//
-module.exports.tokenize = function strikethrough(state, silent) {
+function strikethrough_tokenize(state, silent) {
var i, scanned, token, len, ch,
start = state.pos,
marker = state.src.charCodeAt(start);
@@ -43,7 +41,7 @@ module.exports.tokenize = function strikethrough(state, silent) {
state.pos += scanned.length;
return true;
-};
+}
function postProcess(state, delimiters) {
@@ -115,7 +113,7 @@ function postProcess(state, delimiters) {
// Walk through delimiter list and replace text tokens with tags
//
-module.exports.postProcess = function strikethrough(state) {
+function strikethrough_postProcess(state) {
var curr,
tokens_meta = state.tokens_meta,
max = state.tokens_meta.length;
@@ -127,4 +125,10 @@ module.exports.postProcess = function strikethrough(state) {
postProcess(state, tokens_meta[curr].delimiters);
}
}
+}
+
+
+export default {
+ tokenize: strikethrough_tokenize,
+ postProcess: strikethrough_postProcess
};
diff --git a/lib/rules_inline/text.js b/lib/rules_inline/text.mjs
similarity index 96%
rename from lib/rules_inline/text.js
rename to lib/rules_inline/text.mjs
index b19591e..a1d162f 100644
--- a/lib/rules_inline/text.js
+++ b/lib/rules_inline/text.mjs
@@ -1,9 +1,6 @@
// Skip text characters for text token, place those to pending buffer
// and increment current pos
-'use strict';
-
-
// Rule to skip pure text
// '{}$%@~+=:' reserved for extentions
@@ -42,7 +39,7 @@ function isTerminatorChar(ch) {
}
}
-module.exports = function text(state, silent) {
+export default function text(state, silent) {
var pos = state.pos;
while (pos < state.posMax && !isTerminatorChar(state.src.charCodeAt(pos))) {
@@ -56,7 +53,7 @@ module.exports = function text(state, silent) {
state.pos = pos;
return true;
-};
+}
// Alternative implementation, for memory.
//
diff --git a/lib/token.js b/lib/token.mjs
similarity index 98%
rename from lib/token.js
rename to lib/token.mjs
index c5fd271..bdccefc 100644
--- a/lib/token.js
+++ b/lib/token.mjs
@@ -1,8 +1,5 @@
// Token class
-'use strict';
-
-
/**
* class Token
**/
@@ -198,4 +195,4 @@ Token.prototype.attrJoin = function attrJoin(name, value) {
};
-module.exports = Token;
+export default Token;
diff --git a/package.json b/package.json
index 3b27a22..6a6d0d4 100644
--- a/package.json
+++ b/package.json
@@ -11,13 +11,12 @@
],
"repository": "markdown-it/markdown-it",
"license": "MIT",
- "main": "index.js",
"bin": {
- "markdown-it": "bin/markdown-it.js"
+ "markdown-it": "bin/markdown-it.mjs"
},
"scripts": {
"lint": "eslint --ext js --ext mjs .",
- "test": "npm run lint && nyc mocha && node support/specsplit.js",
+ "test": "npm run lint && nyc mocha && node support/specsplit.mjs",
"coverage": "npm run test && nyc report --reporter html",
"report-coveralls": "nyc --reporter=lcov mocha",
"doc": "node support/build_doc.js",
@@ -26,12 +25,12 @@
"gh-demo": "npm run demo && gh-pages -d demo -f -b master -r git@github.com:markdown-it/markdown-it.github.io.git",
"browserify": "rollup -c support/rollup.config.js",
"benchmark-deps": "npm install --prefix benchmark/extra/ -g marked@0.3.6 commonmark@0.26.0 markdown-it/markdown-it.git#2.2.1",
- "specsplit": "support/specsplit.js good -o test/fixtures/commonmark/good.txt && support/specsplit.js bad -o test/fixtures/commonmark/bad.txt && support/specsplit.js",
+ "specsplit": "support/specsplit.mjs good -o test/fixtures/commonmark/good.txt && support/specsplit.mjs bad -o test/fixtures/commonmark/bad.txt && support/specsplit.mjs",
"todo": "grep 'TODO' -n -r ./lib 2>/dev/null",
"prepublishOnly": "npm run gh-demo && npm run gh-doc"
},
"files": [
- "index.js",
+ "index.mjs",
"bin/",
"lib/",
"dist/"
diff --git a/support/babelmark-responder.js b/support/babelmark-responder.mjs
similarity index 77%
rename from support/babelmark-responder.js
rename to support/babelmark-responder.mjs
index 5a4cd2e..b0ae1ed 100644
--- a/support/babelmark-responder.js
+++ b/support/babelmark-responder.mjs
@@ -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 = `
diff --git a/support/specsplit.js b/support/specsplit.mjs
similarity index 83%
rename from support/specsplit.js
rename to support/specsplit.mjs
index f6f3a82..520423c 100755
--- a/support/specsplit.js
+++ b/support/specsplit.mjs
@@ -4,12 +4,9 @@
// Fixtures generator from commonmark specs. Split spec to working / not working
// examples, or show total stat.
-'use strict';
-
-
-var fs = require('fs');
-var util = require('util');
-var argparse = require('argparse');
+import fs from 'node:fs';
+import argparse from 'argparse';
+import markdownit from '../index.mjs';
var cli = new argparse.ArgumentParser({
@@ -24,7 +21,7 @@ cli.add_argument('type', {
cli.add_argument('-s', '--spec', {
help: 'spec file to read',
- default: require('path').join(__dirname, '../test/fixtures/commonmark/spec.txt')
+ default: new URL('../test/fixtures/commonmark/spec.txt', import.meta.url)
});
cli.add_argument('-o', '--output', {
@@ -65,7 +62,7 @@ function readFile(filename, encoding, callback) {
readFile(options.spec, 'utf8', function (error, input) {
var good = [], bad = [],
- markdown = require('..')('commonmark');
+ markdown = markdownit('commonmark');
if (error) {
if (error.code === 'ENOENT') {
@@ -112,17 +109,17 @@ readFile(options.spec, 'utf8', function (error, input) {
var out = [];
if (!options.type) {
- out.push(util.format('CM spec stat: passed samples - %s, failed samples - %s', good.length, bad.length));
+ out.push(`CM spec stat: passed samples - ${good.length}, failed samples - ${bad.length}`);
} else {
var data = options.type === 'good' ? good : bad;
data.forEach(function (sample) {
- out.push(util.format(
+ out.push(
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' +
- 'src line: %s\n\n.\n%s.\n%s.\n',
- sample.line, sample.md, sample.html));
+ `src line: ${sample.line}\n\n.\n${sample.md}.\n${sample.html}.\n`
+ );
if (sample.err) {
- out.push(util.format('error:\n\n%s\n', sample.err));
+ out.push(`error:\n\n${sample.err}\n`);
}
});
}
diff --git a/test/.eslintrc.yml b/test/.eslintrc.yml
index b1644db..9808c3b 100644
--- a/test/.eslintrc.yml
+++ b/test/.eslintrc.yml
@@ -1,6 +1,2 @@
env:
mocha: true
- es6: true
-
-parserOptions:
- ecmaVersion: 2020
diff --git a/test/babelmark-responder.mjs b/test/babelmark-responder.mjs
index c1d3f21..a15f55e 100644
--- a/test/babelmark-responder.mjs
+++ b/test/babelmark-responder.mjs
@@ -1,6 +1,7 @@
import supertest from 'supertest';
import { execFile } from 'child_process';
import { readFileSync } from 'fs';
+import { setTimeout as sleep } from 'node:timers/promises';
describe('babelmark responder app', function () {
@@ -9,14 +10,10 @@ describe('babelmark responder app', function () {
var PORT = 5005;
var request = supertest('http://127.0.0.1:' + PORT);
- function timeout(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
-
before(async () => {
app = execFile(
'node',
- [ '../support/babelmark-responder.js' ],
+ [ '../support/babelmark-responder.mjs' ],
{
cwd: new URL('.', import.meta.url),
env: Object.assign({}, process.env, { PORT: PORT })
@@ -29,7 +26,7 @@ describe('babelmark responder app', function () {
await request.get('/').expect(200);
break;
} catch (e) {}
- await timeout(100);
+ await sleep(100);
}
});
diff --git a/test/commonmark.mjs b/test/commonmark.mjs
index bff24eb..4e23cea 100644
--- a/test/commonmark.mjs
+++ b/test/commonmark.mjs
@@ -1,7 +1,7 @@
import { fileURLToPath } from 'node:url';
import { relative } from 'node:path';
import { load } from 'markdown-it-testgen';
-import markdownit from '../index.js';
+import markdownit from '../index.mjs';
import { assert } from 'chai';
diff --git a/test/markdown-it.mjs b/test/markdown-it.mjs
index 782fed3..a808871 100644
--- a/test/markdown-it.mjs
+++ b/test/markdown-it.mjs
@@ -1,6 +1,6 @@
import { fileURLToPath } from 'node:url';
import generate from 'markdown-it-testgen';
-import markdownit from '../index.js';
+import markdownit from '../index.mjs';
describe('markdown-it', function () {
diff --git a/test/misc.mjs b/test/misc.mjs
index b1c4c59..4d6865c 100644
--- a/test/misc.mjs
+++ b/test/misc.mjs
@@ -1,5 +1,5 @@
import { assert } from 'chai';
-import markdownit from '../index.js';
+import markdownit from '../index.mjs';
import forInline from 'markdown-it-for-inline';
diff --git a/test/pathological.mjs b/test/pathological.mjs
index e53c8ab..464012f 100644
--- a/test/pathological.mjs
+++ b/test/pathological.mjs
@@ -15,18 +15,17 @@ async function test_pattern(str) {
);
let result;
+ const ac = new AbortController();
try {
result = await Promise.race([
worker.render(str),
-
- new Promise(function (resolve, reject){
- setTimeout(() => { reject(new Error('Terminated (timeout exceeded)')); }, 3000);
- })
+ new Promise((_, reject) => setTimeout(() => reject(new Error('Terminated (timeout exceeded)')), 3000).unref())
]);
} catch (e) {
throw e;
} finally {
+ ac.abort();
await worker.end();
}
diff --git a/test/pathological_worker.js b/test/pathological_worker.js
index a04e9e5..ad3b7a2 100644
--- a/test/pathological_worker.js
+++ b/test/pathological_worker.js
@@ -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);
};
diff --git a/test/ruler.mjs b/test/ruler.mjs
index c49b323..d5f6b7a 100644
--- a/test/ruler.mjs
+++ b/test/ruler.mjs
@@ -1,5 +1,5 @@
import { assert } from 'chai';
-import Ruler from '../lib/ruler.js';
+import Ruler from '../lib/ruler.mjs';
describe('Ruler', function () {
diff --git a/test/token.mjs b/test/token.mjs
index 21ada8d..26c3e54 100644
--- a/test/token.mjs
+++ b/test/token.mjs
@@ -1,5 +1,5 @@
import { assert } from 'chai';
-import Token from '../lib/token.js';
+import Token from '../lib/token.mjs';
describe('Token', function () {
diff --git a/test/utils.mjs b/test/utils.mjs
index 42f7846..5f3139f 100644
--- a/test/utils.mjs
+++ b/test/utils.mjs
@@ -1,5 +1,5 @@
import { assert } from 'chai';
-import utils from '../lib/common/utils.js';
+import utils from '../lib/common/utils.mjs';
describe('Utils', function () {