Skip to content

Commit d5b42b0

Browse files
committed
Merge branch 'esmodules'
2 parents 34f3bea + c18d2b4 commit d5b42b0

26 files changed

+11808
-5408
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
dingus/

.eslintrc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"env": {
3+
"browser": false,
4+
"node": true
5+
},
6+
"parserOptions": {
7+
"sourceType": "module"
8+
},
9+
"rules": {
10+
"no-unused-vars": [
11+
"error",
12+
{ "vars": "all", "args": "after-used", "ignoreRestSiblings": false }
13+
],
14+
"no-constant-condition": 0,
15+
"no-underscore-dangle": 0,
16+
"camelcase": 0,
17+
"quotes": 0,
18+
"no-process-exit": 0,
19+
"no-empty": 0,
20+
"new-cap": [
21+
2,
22+
{
23+
"newIsCap": true,
24+
"capIsNew": true,
25+
"newIsCapExceptions": [],
26+
"capIsNewExceptions": []
27+
}
28+
]
29+
}
30+
}

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ jobs:
1414
- node: '12.x'
1515
- node: '11.x'
1616
- node: '10.x'
17-
- node: '9.x'
18-
- node: '8.x'
1917
steps:
2018
- uses: actions/checkout@v1
2119
- name: Use Node.js
2220
uses: actions/setup-node@v1
2321
with:
2422
node-version: ${{ matrix.versions.node }}
2523
- run: npm install
24+
- run: npm run lint
2625
- run: npm run build --if-present
2726
- run: npm test

Makefile

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
11
SPEC=test/spec.txt
22
SPECVERSION=$(shell perl -ne 'print $$1 if /^version: *([0-9.]+)/' $(SPEC))
33
BENCHINP?=bench/samples/README.md
4-
JSMODULES=$(wildcard lib/*.js)
54
VERSION?=$(SPECVERSION)
6-
ESLINT=node_modules/.bin/eslint
5+
JSMODULES=$(wildcard lib/*.js)
76
UGLIFYJS=node_modules/.bin/uglifyjs
8-
BROWSERIFY=node_modules/.bin/browserify
7+
LICENSETEXT="/* commonmark $(VERSION) https://github.com/commonmark/commonmark.js @license BSD3 */"
98

109
.PHONY: dingus dist test bench bench-detailed npm lint clean update-spec
1110

1211
lint:
13-
$(ESLINT) -c eslint.json ${JSMODULES} bin/commonmark test/test.js dingus/dingus.js
12+
npm run lint
1413

1514
dist: dist/commonmark.js dist/commonmark.min.js
1615

1716
dist/commonmark.js: lib/index.js ${JSMODULES}
18-
echo '/* commonmark $(VERSION) https://github.com/CommonMark/commonmark.js @license BSD3 */' > $@
19-
$(BROWSERIFY) --standalone commonmark $< >> $@
17+
npm run build
18+
(echo $(LICENSETEXT) && cat $@) > $@.tmp && mv $@.tmp $@
2019

2120
dist/commonmark.min.js: dist/commonmark.js
22-
$(UGLIFYJS) --version # version should be at least 2.5.0
23-
$(UGLIFYJS) $< --compress keep_fargs=true,pure_getters=true --comments > $@
21+
(echo $(LICENSETEXT) && cat $@) > $@.tmp && mv $@.tmp $@
2422

2523
update-spec:
2624
curl 'https://raw.githubusercontent.com/jgm/CommonMark/master/spec.txt' > $(SPEC)
2725

2826
test: $(SPEC)
29-
node test/test.js
27+
npm test
3028

3129
bench:
32-
node bench/bench.js ${BENCHINP}
30+
node -r esm bench/bench.js ${BENCHINP}
3331

3432
bench-detailed:
3533
sudo renice -10 $$$$; \
36-
for x in bench/samples/*.md; do echo $$x; node bench/bench.js $$x; done | \
34+
for x in bench/samples/*.md; do echo $$x; node -r esm bench/bench.js $$x; done | \
3735
awk -f bench/format_benchmarks.awk
3836

3937
npm:

bench/bench.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
11
"use strict";
22

3-
var Benchmark = require('benchmark').Benchmark;
4-
var suite = new Benchmark.Suite();
5-
var fs = require('fs');
6-
var commonmark = require('../lib/index.js');
7-
var Showdown = require('showdown');
8-
var marked = require('marked');
9-
var markdownit = require('markdown-it')('commonmark');
3+
import benchmark from "benchmark";
4+
import fs from "fs";
5+
import * as commonmark from "../lib/index.js";
6+
import Showdown from "showdown";
7+
import marked from "marked";
8+
import _markdownit from "markdown-it";
9+
10+
var suite = new benchmark.Suite();
11+
var markdownit = _markdownit("commonmark");
1012

1113
// disable expensive IDNa links encoding:
1214
var markdownit_encode = markdownit.utils.lib.mdurl.encode;
13-
markdownit.normalizeLink = function(url) { return markdownit_encode(url); };
14-
markdownit.normalizeLinkText = function(str) { return str; };
15+
markdownit.normalizeLink = function(url) {
16+
return markdownit_encode(url);
17+
};
18+
markdownit.normalizeLinkText = function(str) {
19+
return str;
20+
};
1521

1622
var showdown = new Showdown.Converter();
1723
var parser = new commonmark.Parser();
18-
var parserSmart = new commonmark.Parser({smart: true});
1924
var renderer = new commonmark.HtmlRenderer();
2025

2126
var benchfile = process.argv[2];
2227

23-
var contents = fs.readFileSync(benchfile, 'utf8');
28+
var contents = fs.readFileSync(benchfile, "utf8");
2429

25-
suite.add('commonmark.js', function() {
26-
renderer.render(parser.parse(contents));
27-
})
30+
suite
31+
.add("commonmark.js", function() {
32+
renderer.render(parser.parse(contents));
33+
})
2834

29-
.add('showdown.js', function() {
30-
showdown.makeHtml(contents);
31-
})
35+
.add("showdown.js", function() {
36+
showdown.makeHtml(contents);
37+
})
3238

33-
.add('marked.js', function() {
34-
marked(contents);
35-
})
39+
.add("marked.js", function() {
40+
marked(contents);
41+
})
3642

37-
.add('markdown-it', function() {
38-
markdownit.render(contents);
39-
})
43+
.add("markdown-it", function() {
44+
markdownit.render(contents);
45+
})
4046

41-
.on('cycle', function(event) {
42-
console.log(String(event.target));
43-
})
44-
.run();
47+
.on("cycle", function(event) {
48+
console.log(String(event.target));
49+
})
50+
.run();

bin/commonmark

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env node -r esm
22
"use strict";
33

4-
var util = require('util');
5-
var fs = require('fs');
6-
var commonmark = require('../lib/index.js');
4+
import util from "util";
5+
import fs from "fs";
6+
import os from "os";
7+
import * as commonmark from "../lib/index.js";
78
var version = require('../package.json').version;
8-
var parseArgs = require('minimist');
9+
import parseArgs from "minimist";
10+
911
var args = process.argv.slice(2);
1012
var argv = parseArgs(args,
1113
{boolean: ["ast", "xml", "time", "smart",
@@ -75,12 +77,16 @@ if (format === 'html') {
7577
}
7678

7779
if (files.length === 0) {
78-
files = ['/dev/stdin'];
79-
}
80-
81-
for (i = 0; i < files.length; i++) {
82-
var file = files[i];
83-
inps.push(fs.readFileSync(file, 'utf8'));
80+
if (os.platform() === "win32") {
81+
inps.push(fs.readFileSync(0, 'utf-8'));
82+
} else {
83+
inps.push(fs.readFileSync('/dev/tty', 'utf-8'));
84+
}
85+
} else {
86+
for (i = 0; i < files.length; i++) {
87+
var file = files[i];
88+
inps.push(fs.readFileSync(file, 'utf8'));
89+
}
8490
}
8591

8692
var inp = inps.join('\n');

bower.json

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
{
2-
"name": "commonmark",
3-
"main": "dist/commonmark.js",
4-
"homepage": "https://github.com/commonmark/commonmark.js",
5-
"description": "CommonMark parsing and rendering library",
6-
"license": "BSD-2-Clause",
7-
"ignore": [
8-
"**/.*",
9-
"lib",
10-
"bin",
11-
"test",
12-
"tools",
13-
"bench",
14-
"dingus",
15-
"Makefile",
16-
"*.md",
17-
"release_checklist.md",
18-
"eslint.json",
19-
"package.json"
20-
],
21-
"keywords": [
22-
"markdown",
23-
"commonmark"
24-
]
2+
"name": "commonmark",
3+
"main": "dist/commonmark.js",
4+
"homepage": "https://github.com/commonmark/commonmark.js",
5+
"description": "CommonMark parsing and rendering library",
6+
"license": "BSD-2-Clause",
7+
"ignore": [
8+
"**/.*",
9+
"lib",
10+
"bin",
11+
"test",
12+
"tools",
13+
"bench",
14+
"dingus",
15+
"Makefile",
16+
"*.md",
17+
"release_checklist.md",
18+
".eslintrc",
19+
"package.json"
20+
],
21+
"keywords": ["markdown", "commonmark"]
2522
}

dingus/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ ALL=commonmark.js
22
COMPONENTS=lodash.min.js jquery.min.js jquery.min.map bootstrap.min.js bootstrap.min.css
33
LIBFILES=../lib/blocks.js ../lib/common.js ../lib/from-code-point.js ../lib/inlines.js ../lib/index.js ../lib/node.js ../lib/render/xml.js ../lib/render/html.js ../lib/render/renderer.js
44
BOWER=../node_modules/.bin/bower
5-
BROWSERIFY=../node_modules/.bin/browserify
65
HTTPSERVER=../node_modules/.bin/http-server
76

87
all: $(ALL) components
@@ -34,7 +33,8 @@ clean:
3433
rm -r bower_components
3534

3635
commonmark.js: ../lib/index.js $(LIBFILES)
37-
$(BROWSERIFY) --standalone commonmark $< -o $@
36+
make -C .. dist ;\
37+
cp ../dist/commonmark.js commonmark.js
3838

3939
dingus: all
4040
echo "Starting dingus server at http://localhost:9000/"; \

0 commit comments

Comments
 (0)