extramark 0.3.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -1,9 +1,9 @@
1
- MIT License
2
-
3
- Copyright (c) 2018-2019 Márton Visnovitz
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2018-2025 Márton Visnovitz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,96 +1,88 @@
1
- # ExtraMark
2
-
3
- [![Version][badge-version]](https://npmjs.com/package/extramark)
4
- [![License][badge-license]](https://github.com/vimtaai/extramark/blob/master/LICENSE.md)
5
- [![Code style][badge-style]](https://github.com/prettier/prettier)
6
-
7
- > CommonMark superset with the most widely used syntax extensions
8
-
9
- **ExtraMark** is a superset of [CommonMark](https://commonmark.org/) that includes syntax extensions that are commonly used by other Markdown dialects. The list and syntax for the extensions are decided by looking at the most popular Markdown dialects and selecting the most common syntax for each feature. The goal of the project is to create a (somewhat) standard superset of CommonMark that supports the features that are requested by most. The parser is based on [markdown-it](https://github.com/markdown-it/markdown-it) and uses plugins for syntax extensions.
10
-
11
- ## Installation
12
-
13
- Install via `npm`:
14
-
15
- ```bash
16
- npm install extramark
17
- ```
18
-
19
- Load from a CDN:
20
-
21
- ```html
22
- <script src="https://cdn.jsdelivr.net/npm/extramark"></script>
23
- ```
24
-
25
- ## Usage
26
-
27
- The `extramark` package exposes two functions, `parse()` and `render()`. The `parse()` function creates an abstract syntax tree from the input while the `render()` function returns the generated HTML code (see [markdown-it](https://github.com/markdown-it/markdown-it)).
28
-
29
- ```js
30
- const { parse, render } = require("extramark");
31
-
32
- parse("# Heading");
33
- // [Object] - AST of the Markdown code
34
-
35
- render("# Heading");
36
- // <h1>Heading</h1>
37
- ```
38
-
39
- In a browser environment you can access the `parse()` and `render()` functions via the `ExtraMark` global object.
40
-
41
- ```js
42
- const { parse, render } = ExtraMark;
43
- ```
44
-
45
- ### CLI
46
-
47
- To transform documents in the command line you have to install the `extramark` package globally.
48
-
49
- ```bash
50
- npm install -g extramark
51
- ```
52
-
53
- After the installation the `extramark` command becomes available. The command can be used to transform the input text (file or `stdin`) to HTML (file or `stdout`).
54
-
55
- ```bash
56
- extramark input.md -o output.html -c style.css
57
- ```
58
-
59
- To see all options of the `extramark` see it's help:
60
-
61
- ```bash
62
- extramark --help
63
- ```
64
-
65
- ### Features
66
-
67
- - Defined clearly as a superset of CommonMark
68
- - Syntax extensions
69
- - [Automatic typographic replacements][typographer]
70
- - [Tables][table]
71
- - [Anchors for headings][anchor] (up to heading level 3)
72
- - [Definition lists][deflist]
73
- - [Superscript][superscript]
74
- - [Subscript][subscript]
75
- - [Abbreviations][abbreviation]
76
- - [Footnotes][footnote]
77
- - [Critic Markup][critic-markup]
78
- - Integrated CLI tool for command-line conversion to HTML
79
-
80
- [typographer]: https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.js
81
- [table]: https://help.github.com/articles/organizing-information-with-tables/
82
- [anchor]: https://github.com/valeriangalliat/markdown-it-anchor
83
- [deflist]: https://github.com/markdown-it/markdown-it-deflist
84
- [superscript]: https://github.com/markdown-it/markdown-it-sup
85
- [subscript]: https://github.com/markdown-it/markdown-it-sub
86
- [abbreviation]: https://github.com/markdown-it/markdown-it-abbr
87
- [footnote]: https://github.com/markdown-it/markdown-it-footnote
88
- [critic-markup]: http://criticmarkup.com/
89
-
90
- ## Contributing
91
-
92
- All ideas, recommendations, bug reports, pull requests are welcome. :smile:
93
-
94
- [badge-version]: https://img.shields.io/npm/v/extramark.svg?style=flat-square
95
- [badge-license]: https://img.shields.io/npm/l/extramark.svg?style=flat-square
96
- [badge-style]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
1
+ # ExtraMark
2
+
3
+ [![License][badge-license]][link-license]
4
+ [![Version][badge-version]][link-version]
5
+
6
+ [badge-license]: https://img.shields.io/npm/l/extramark.svg
7
+ [link-license]: https://github.com/vimtaai/extramark/blob/master/LICENSE.md
8
+ [badge-version]: https://img.shields.io/npm/v/extramark.svg
9
+ [link-version]: https://npmjs.com/package/extramark
10
+
11
+ **ExtraMark** is a superset of [CommonMark](https://commonmark.org/) that includes syntax extensions that are commonly used by other Markdown dialects. The list and syntax for the extensions are decided by looking at the most popular Markdown dialects and selecting the most common syntax for each feature. The goal of the project is to create a (somewhat) standard superset of CommonMark that supports the features that are requested by most. The parser is based on [markdown-it](https://github.com/markdown-it/markdown-it) and uses plugins for syntax extensions.
12
+
13
+ ## Installation
14
+
15
+ Install via `npm`:
16
+
17
+ ```bash
18
+ npm install extramark
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ The `extramark` package exposes two functions, `parse()` and `render()`. The `parse()` function creates an abstract syntax tree from the input while the `render()` function returns the generated HTML code (see [markdown-it](https://github.com/markdown-it/markdown-it)).
24
+
25
+ ```js
26
+ const { parse, render } = require("extramark");
27
+
28
+ parse("# Heading");
29
+ // [Object] - AST of the Markdown code
30
+
31
+ render("# Heading");
32
+ // <h1>Heading</h1>
33
+ ```
34
+
35
+ In a browser environment you can access the `parse()` and `render()` functions via the `ExtraMark` global object.
36
+
37
+ ```js
38
+ const { parse, render } = ExtraMark;
39
+ ```
40
+
41
+ ### CLI
42
+
43
+ To transform documents in the command line you have to install the `extramark` package globally.
44
+
45
+ ```bash
46
+ npm install -g extramark
47
+ ```
48
+
49
+ After the installation the `extramark` command becomes available. The command can be used to transform the input text (file or `stdin`) to HTML (file or `stdout`).
50
+
51
+ ```bash
52
+ extramark input.md -o output.html -c style.css
53
+ ```
54
+
55
+ To see all options of the `extramark` see it's help:
56
+
57
+ ```bash
58
+ extramark --help
59
+ ```
60
+
61
+ ### Features
62
+
63
+ - Defined clearly as a superset of CommonMark
64
+ - Syntax extensions
65
+ - [Automatic typographic replacements][typographer]
66
+ - [Tables][table]
67
+ - [Anchors for headings][anchor] (up to heading level 3)
68
+ - [Definition lists][definition-list]
69
+ - [Superscript][superscript]
70
+ - [Subscript][subscript]
71
+ - [Abbreviations][abbreviation]
72
+ - [Footnotes][footnote]
73
+ - [Critic Markup][critic-markup]
74
+ - Integrated CLI tool for command-line conversion to HTML
75
+
76
+ [typographer]: https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.js
77
+ [table]: https://help.github.com/articles/organizing-information-with-tables/
78
+ [anchor]: https://github.com/valeriangalliat/markdown-it-anchor
79
+ [definition-list]: https://github.com/markdown-it/markdown-it-deflist
80
+ [superscript]: https://github.com/markdown-it/markdown-it-sup
81
+ [subscript]: https://github.com/markdown-it/markdown-it-sub
82
+ [abbreviation]: https://github.com/markdown-it/markdown-it-abbr
83
+ [footnote]: https://github.com/markdown-it/markdown-it-footnote
84
+ [critic-markup]: http://criticmarkup.com/
85
+
86
+ ## Contributing
87
+
88
+ All ideas, recommendations, bug reports, pull requests are welcome. 🙂
package/bin/extramark.js CHANGED
@@ -1,73 +1,64 @@
1
- #!/usr/bin/env node
1
+ import { error, log } from "node:console";
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import { dirname } from "node:path";
4
+ import { argv, exit, stdin, stdout } from "node:process";
5
+ import { styleText } from "node:util";
2
6
 
3
- const path = require("path");
4
- const program = require("commander");
7
+ import { program } from "commander";
8
+ import { html } from "common-tags";
5
9
 
6
- const { ensureDir, readFile, writeFile } = require("fs-extra");
7
- const { html } = require("common-tags");
8
- const { render } = require("../lib/extramark");
9
- const { logger } = require("./utils/logger");
10
+ import { render } from "../src/index.js";
10
11
 
11
12
  program
12
13
  .description("CLI for converting Markdown documents to HTML with ExtraMark")
13
14
  .usage("<input> [options]")
14
- .option("-i --input [path]", "path of the input .md file")
15
15
  .option("-o --output [path]", "path of the output .html file")
16
16
  .option("-c --css [css]", "path to the CSS file to use for formatting")
17
17
  .option("-t --title [title]", "title of the output document")
18
18
  .option("-q --quiet", "omit console output")
19
- .parse(process.argv);
19
+ .parse(argv);
20
20
 
21
- async function convert(program) {
22
- const input = {
23
- file: program.input || program.args[0] || process.stdin.fd
24
- };
21
+ const options = program.opts();
22
+ const inputFile = program.args[0];
23
+ const outputFile = options.output;
24
+ const data = {};
25
25
 
26
- const output = {
27
- dir: program.output ? path.dirname(program.output) : "",
28
- file: program.output || process.stdout.fd
29
- };
30
-
31
- if (program.quiet || output.file === process.stdout.fd) {
32
- logger.disable();
33
- }
34
-
35
- try {
36
- logger.await("Reading input...");
37
- input.data = await readFile(input.file, "utf-8");
38
- } catch (err) {
39
- logger.error(`Could not read input file \`${input.file}\`.\n`, err);
40
- return;
26
+ try {
27
+ if (inputFile) {
28
+ data.raw = await readFile(inputFile, "utf-8");
29
+ } else {
30
+ const buffer = await Array.fromAsync(stdin);
31
+ data.raw = buffer.toString();
41
32
  }
33
+ } catch {
34
+ error(`${styleText("red", "!")} Could not read input file '${inputFile}'.`);
35
+ exit(1);
36
+ }
42
37
 
43
- try {
44
- logger.await("Generating output...");
45
- output.data = html`
46
- <!DOCTYPE html>
47
- <meta charset="utf-8" />
48
- <title>${program.title || `Markdown document`}</title>
49
- ${program.css ? `<link rel="stylesheet" href="${program.css}">` : ``}
50
- ${await render(input.data)}
51
- `;
52
- } catch (err) {
53
- logger.error(`Could not parse input data.\n`, err);
54
- return;
55
- }
38
+ try {
39
+ data.parsed = html`
40
+ <!DOCTYPE html>
41
+ <meta charset="utf-8" />
42
+ <title>${program.title || `Markdown document`}</title>
43
+ ${program.css ? `<link rel="stylesheet" href="${program.css}">` : ``} ${await render(data.raw)}
44
+ `;
45
+ } catch {
46
+ error(`${styleText("red", "!")} Could not parse input data.`);
47
+ exit(1);
48
+ }
56
49
 
57
- try {
58
- await ensureDir(output.dir);
59
- } catch (err) {
60
- logger.error(`Could not create output dir \`${output.dir}\`.\n`, err);
61
- return;
50
+ try {
51
+ if (outputFile) {
52
+ await mkdir(dirname(outputFile), { recursive: true });
53
+ await writeFile(outputFile, data.parsed);
54
+ } else {
55
+ stdout.write(data.parsed + "\n");
62
56
  }
63
57
 
64
- try {
65
- logger.await("Writing output...");
66
- await writeFile(output.file, output.data);
67
- logger.success(`Created: ${output.file}`);
68
- } catch (err) {
69
- logger.error(`Could not write output file \`${output.file}\`.\n`, err);
58
+ if (outputFile && !options.quiet) {
59
+ log(`${styleText("green", "✔")} Created: ${outputFile}`);
70
60
  }
61
+ } catch (e) {
62
+ error(`${styleText("red", "!")} Could not write output file '${outputFile}'.`, e);
63
+ exit(1);
71
64
  }
72
-
73
- convert(program);
package/package.json CHANGED
@@ -1,57 +1,40 @@
1
1
  {
2
2
  "name": "extramark",
3
- "version": "0.3.2",
3
+ "version": "2.0.0",
4
4
  "description": "CommonMark superset with the most widely used syntax extensions",
5
- "author": "Márton Visnovitz <vimtaai@inf.elte.hu>",
5
+ "author": "Márton Visnovitz <visnovitz.marton@gmail.com>",
6
6
  "license": "MIT",
7
7
  "repository": "github:vimtaai/extramark",
8
- "module": "src/index.js",
9
- "main": "lib/extramark.js",
10
- "browser": "dist/extramark.min.js",
8
+ "type": "module",
9
+ "main": "src/index.js",
11
10
  "bin": "bin/extramark.js",
12
11
  "files": [
13
- "/src",
14
- "/lib",
15
- "/dist",
16
- "/bin"
12
+ "src/**/.js",
13
+ "bin/**/*.js"
17
14
  ],
18
15
  "scripts": {
19
- "lint": "eslint src/**/*.js",
20
- "build:node": "rollup -c --environment TARGET:node",
21
- "build:browser": "rollup -c --environment TARGET:browser,BUILD:development",
22
- "build:browser:production": "rollup -c --environment TARGET:browser,BUILD:production",
23
- "watch:node": "rollup -c -w --environment TARGET:node",
24
- "watch:browser": "rollup -c -w --environment TARGET:browser,BUILD:development",
25
- "prepare": "npm run build:node && npm run build:browser && npm run build:browser:production"
16
+ "lint": "eslint '{src,bin}/**/*.js'",
17
+ "format": "prettier --check '{src,bin}/**/*.js'",
18
+ "release": "semantic-release"
26
19
  },
27
20
  "dependencies": {
28
- "commander": "^3.0.2",
29
- "common-tags": "^1.8.0",
30
- "critic-markup": "^0.4.0",
31
- "fs-extra": "^8.1.0",
32
- "markdown-it": "^10.0.0",
33
- "markdown-it-abbr": "^1.0.4",
34
- "markdown-it-anchor": "^5.2.4",
35
- "markdown-it-deflist": "^2.0.3",
36
- "markdown-it-footnote": "^3.0.2",
37
- "markdown-it-sub": "^1.0.0",
38
- "markdown-it-sup": "^1.0.0",
39
- "signale": "^1.4.0"
21
+ "commander": "^12.1.0",
22
+ "common-tags": "^1.8.2",
23
+ "critic-markup": "^1.1.3",
24
+ "markdown-it": "^14.1.0",
25
+ "markdown-it-abbr": "^2.0.0",
26
+ "markdown-it-anchor": "^9.2.0",
27
+ "markdown-it-deflist": "^3.0.0",
28
+ "markdown-it-footnote": "^4.0.0",
29
+ "markdown-it-sub": "^2.0.0",
30
+ "markdown-it-sup": "^2.0.0"
40
31
  },
41
32
  "devDependencies": {
42
- "@babel/core": "^7.6.2",
43
- "@babel/preset-env": "^7.6.2",
44
- "eslint": "^6.5.1",
45
- "eslint-config-prettier": "^6.3.0",
46
- "eslint-config-problems": "^3.0.1",
47
- "eslint-plugin-prettier": "^3.1.1",
48
- "prettier": "^1.18.2",
49
- "rollup": "^1.22.0",
50
- "rollup-plugin-babel": "^4.3.3",
51
- "rollup-plugin-babel-minify": "^9.1.0",
52
- "rollup-plugin-commonjs": "^10.1.0",
53
- "rollup-plugin-json": "^4.0.0",
54
- "rollup-plugin-node-builtins": "^2.1.2",
55
- "rollup-plugin-node-resolve": "^5.2.0"
33
+ "@eslint/js": "^9.17.0",
34
+ "@semantic-release/changelog": "^6.0.3",
35
+ "@semantic-release/git": "^10.0.1",
36
+ "eslint": "^9.17.0",
37
+ "prettier": "^3.4.2",
38
+ "semantic-release": "^24.2.2"
56
39
  }
57
40
  }
package/src/index.js CHANGED
@@ -1,26 +1,19 @@
1
- import MarkdownIt from "markdown-it";
2
-
3
- import anchor from "markdown-it-anchor";
4
- import deflist from "markdown-it-deflist";
5
- import sup from "markdown-it-sup";
6
- import sub from "markdown-it-sub";
7
- import abbr from "markdown-it-abbr";
8
- import footnote from "markdown-it-footnote";
9
-
10
- import critic from "./syntax/critic";
11
-
12
- const parser = new MarkdownIt("commonmark");
13
-
14
- parser.set({ typographer: true });
15
- parser.enable("replacements").enable("table");
16
- parser
17
- .use(anchor, [1, 2, 3])
18
- .use(deflist)
19
- .use(sup)
20
- .use(sub)
21
- .use(abbr)
22
- .use(footnote)
23
- .use(critic);
24
-
25
- export const parse = parser.parse.bind(parser);
26
- export const render = parser.render.bind(parser);
1
+ import MarkdownIt from "markdown-it";
2
+
3
+ import anchor from "markdown-it-anchor";
4
+ import deflist from "markdown-it-deflist";
5
+ import sup from "markdown-it-sup";
6
+ import sub from "markdown-it-sub";
7
+ import abbr from "markdown-it-abbr";
8
+ import footnote from "markdown-it-footnote";
9
+
10
+ import critic from "./critic.js";
11
+
12
+ const parser = new MarkdownIt("commonmark");
13
+
14
+ parser.set({ typographer: true });
15
+ parser.enable("replacements").enable("table");
16
+ parser.use(anchor, [1, 2, 3]).use(deflist).use(sup).use(sub).use(abbr).use(footnote).use(critic);
17
+
18
+ export const parse = parser.parse.bind(parser);
19
+ export const render = parser.render.bind(parser);
package/CHANGELOG.md DELETED
@@ -1,26 +0,0 @@
1
- # Changelog
2
-
3
- ## [0.3.2] - 2019-10-03
4
-
5
- - 🔺 Dependency update
6
-
7
- ## [0.3.1] - 2019-09-11
8
-
9
- - 🔺 Dependency update
10
-
11
- ## [0.3.0] - 2019-09-11
12
-
13
- - 🔺 Dependency update
14
- - 🔺 Changed list of supported browsers - dropped support for IE and Opera Mini (⚡)
15
- -
16
- ## [0.2.1] - 2019-09-09
17
-
18
- - 🔺 Dependency update
19
-
20
- ## [0.2.0] - 2019-06-28
21
-
22
- - 🔺 Change function export style in Node.js (⚡)
23
-
24
- ## [0.1.0] - 2019-02-06
25
-
26
- - ✨ **Initial release**
@@ -1,5 +0,0 @@
1
- const { Signale } = require("signale");
2
-
3
- const logger = new Signale({ scope: "extramark", interactive: true });
4
-
5
- module.exports = { logger };