@honkit/markup-it 3.6.17 → 3.7.2
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/README.md +7 -7
- package/lib/__tests__/syntax.js +72 -0
- package/lib/constants/defaultRules.js +3 -3
- package/lib/json/__tests__/decode.js +38 -0
- package/lib/json/__tests__/encode.js +26 -0
- package/lib/markup.js +2 -2
- package/lib/models/__tests__/token.js +18 -0
- package/lib/models/token.js +3 -3
- package/lib/parse/__tests__/mergeTokens.js +51 -0
- package/lib/parse/index.js +1 -1
- package/lib/parse/lex.js +3 -3
- package/lib/parse/state.js +2 -2
- package/lib/parse/textToUnstyledTokens.js +1 -1
- package/lib/render/state.js +1 -1
- package/lib/utils/walk.js +2 -2
- package/package.json +2 -2
- package/syntaxes/markdown/__tests__/specs/amps_and_angles_encoding.html +17 -0
- package/syntaxes/markdown/__tests__/specs/amps_and_angles_encoding.md +21 -0
- package/syntaxes/markdown/__tests__/specs/auto_links.html +18 -0
- package/syntaxes/markdown/__tests__/specs/auto_links.md +13 -0
- package/syntaxes/markdown/__tests__/specs/autolink_lines.html +3 -0
- package/syntaxes/markdown/__tests__/specs/autolink_lines.md +2 -0
- package/syntaxes/markdown/__tests__/specs/backslash_escapes.html +118 -0
- package/syntaxes/markdown/__tests__/specs/backslash_escapes.md +120 -0
- package/syntaxes/markdown/__tests__/specs/blockquote_list_item.html +3 -0
- package/syntaxes/markdown/__tests__/specs/blockquote_list_item.md +4 -0
- package/syntaxes/markdown/__tests__/specs/blockquotes_with_code_blocks.html +15 -0
- package/syntaxes/markdown/__tests__/specs/blockquotes_with_code_blocks.md +11 -0
- package/syntaxes/markdown/__tests__/specs/case_insensitive_refs.html +1 -0
- package/syntaxes/markdown/__tests__/specs/case_insensitive_refs.md +3 -0
- package/syntaxes/markdown/__tests__/specs/code_blocks.html +18 -0
- package/syntaxes/markdown/__tests__/specs/code_blocks.md +14 -0
- package/syntaxes/markdown/__tests__/specs/code_blocks_indent.html +13 -0
- package/syntaxes/markdown/__tests__/specs/code_blocks_indent.md +14 -0
- package/syntaxes/markdown/__tests__/specs/code_spans.html +6 -0
- package/syntaxes/markdown/__tests__/specs/code_spans.md +6 -0
- package/syntaxes/markdown/__tests__/specs/def_blocks.html +30 -0
- package/syntaxes/markdown/__tests__/specs/def_blocks.md +21 -0
- package/syntaxes/markdown/__tests__/specs/double_link.html +5 -0
- package/syntaxes/markdown/__tests__/specs/double_link.md +5 -0
- package/syntaxes/markdown/__tests__/specs/escaped_angles.html +1 -0
- package/syntaxes/markdown/__tests__/specs/escaped_angles.md +1 -0
- package/syntaxes/markdown/__tests__/specs/footnotes.html +4 -0
- package/syntaxes/markdown/__tests__/specs/footnotes.md +3 -0
- package/syntaxes/markdown/__tests__/specs/gfm_break.breaks.html +3 -0
- package/syntaxes/markdown/__tests__/specs/gfm_break.breaks.md +3 -0
- package/syntaxes/markdown/__tests__/specs/gfm_code.html +5 -0
- package/syntaxes/markdown/__tests__/specs/gfm_code.md +16 -0
- package/syntaxes/markdown/__tests__/specs/gfm_code_hr_list.html +52 -0
- package/syntaxes/markdown/__tests__/specs/gfm_code_hr_list.md +53 -0
- package/syntaxes/markdown/__tests__/specs/gfm_del.html +1 -0
- package/syntaxes/markdown/__tests__/specs/gfm_del.md +1 -0
- package/syntaxes/markdown/__tests__/specs/gfm_em.html +1 -0
- package/syntaxes/markdown/__tests__/specs/gfm_em.md +1 -0
- package/syntaxes/markdown/__tests__/specs/gfm_links.html +2 -0
- package/syntaxes/markdown/__tests__/specs/gfm_links.md +1 -0
- package/syntaxes/markdown/__tests__/specs/gfm_tables.html +37 -0
- package/syntaxes/markdown/__tests__/specs/gfm_tables.md +21 -0
- package/syntaxes/markdown/__tests__/specs/hard_wrapped_paragraphs_with_list_like_lines.nogfm.html +10 -0
- package/syntaxes/markdown/__tests__/specs/hard_wrapped_paragraphs_with_list_like_lines.nogfm.md +8 -0
- package/syntaxes/markdown/__tests__/specs/horizontal_rules.html +71 -0
- package/syntaxes/markdown/__tests__/specs/horizontal_rules.md +67 -0
- package/syntaxes/markdown/__tests__/specs/hr_list_break.html +10 -0
- package/syntaxes/markdown/__tests__/specs/hr_list_break.md +6 -0
- package/syntaxes/markdown/__tests__/specs/image.html +5 -0
- package/syntaxes/markdown/__tests__/specs/image.md +3 -0
- package/syntaxes/markdown/__tests__/specs/inline_html.html +6 -0
- package/syntaxes/markdown/__tests__/specs/inline_html.md +6 -0
- package/syntaxes/markdown/__tests__/specs/inline_html_advanced.html +15 -0
- package/syntaxes/markdown/__tests__/specs/inline_html_advanced.md +15 -0
- package/syntaxes/markdown/__tests__/specs/inline_html_comments.html +13 -0
- package/syntaxes/markdown/__tests__/specs/inline_html_comments.md +13 -0
- package/syntaxes/markdown/__tests__/specs/inline_html_script.html +3 -0
- package/syntaxes/markdown/__tests__/specs/inline_html_script.md +3 -0
- package/syntaxes/markdown/__tests__/specs/inline_html_simple.html +72 -0
- package/syntaxes/markdown/__tests__/specs/inline_html_simple.md +69 -0
- package/syntaxes/markdown/__tests__/specs/lazy_blockquotes.html +4 -0
- package/syntaxes/markdown/__tests__/specs/lazy_blockquotes.md +2 -0
- package/syntaxes/markdown/__tests__/specs/links_inline_style.html +15 -0
- package/syntaxes/markdown/__tests__/specs/links_inline_style.md +15 -0
- package/syntaxes/markdown/__tests__/specs/links_reference_style.html +52 -0
- package/syntaxes/markdown/__tests__/specs/links_reference_style.md +71 -0
- package/syntaxes/markdown/__tests__/specs/links_shortcut_references.html +9 -0
- package/syntaxes/markdown/__tests__/specs/links_shortcut_references.md +20 -0
- package/syntaxes/markdown/__tests__/specs/list_item_text.html +1 -0
- package/syntaxes/markdown/__tests__/specs/list_item_text.md +5 -0
- package/syntaxes/markdown/__tests__/specs/literal_quotes_in_titles.html +3 -0
- package/syntaxes/markdown/__tests__/specs/literal_quotes_in_titles.md +7 -0
- package/syntaxes/markdown/__tests__/specs/loose_lists.html +62 -0
- package/syntaxes/markdown/__tests__/specs/loose_lists.md +59 -0
- package/syntaxes/markdown/__tests__/specs/main.html +69 -0
- package/syntaxes/markdown/__tests__/specs/main.md +55 -0
- package/syntaxes/markdown/__tests__/specs/markdown_documentation_basics.html +314 -0
- package/syntaxes/markdown/__tests__/specs/markdown_documentation_basics.md +306 -0
- package/syntaxes/markdown/__tests__/specs/markdown_documentation_syntax.html +942 -0
- package/syntaxes/markdown/__tests__/specs/markdown_documentation_syntax.md +888 -0
- package/syntaxes/markdown/__tests__/specs/nested_blockquotes.html +9 -0
- package/syntaxes/markdown/__tests__/specs/nested_blockquotes.md +5 -0
- package/syntaxes/markdown/__tests__/specs/nested_code.html +1 -0
- package/syntaxes/markdown/__tests__/specs/nested_code.md +1 -0
- package/syntaxes/markdown/__tests__/specs/nested_em.html +3 -0
- package/syntaxes/markdown/__tests__/specs/nested_em.md +3 -0
- package/syntaxes/markdown/__tests__/specs/nested_square_link.html +1 -0
- package/syntaxes/markdown/__tests__/specs/nested_square_link.md +1 -0
- package/syntaxes/markdown/__tests__/specs/not_a_link.html +1 -0
- package/syntaxes/markdown/__tests__/specs/not_a_link.md +1 -0
- package/syntaxes/markdown/__tests__/specs/ordered_and_unordered_lists.html +148 -0
- package/syntaxes/markdown/__tests__/specs/ordered_and_unordered_lists.md +131 -0
- package/syntaxes/markdown/__tests__/specs/ref_paren.html +1 -0
- package/syntaxes/markdown/__tests__/specs/ref_paren.md +3 -0
- package/syntaxes/markdown/__tests__/specs/same_bullet.html +5 -0
- package/syntaxes/markdown/__tests__/specs/same_bullet.md +3 -0
- package/syntaxes/markdown/__tests__/specs/simple_paragraph.html +1 -0
- package/syntaxes/markdown/__tests__/specs/simple_paragraph.md +1 -0
- package/syntaxes/markdown/__tests__/specs/strong_and_em_together.html +7 -0
- package/syntaxes/markdown/__tests__/specs/strong_and_em_together.md +7 -0
- package/syntaxes/markdown/__tests__/specs/table_pipe.html +5 -0
- package/syntaxes/markdown/__tests__/specs/table_pipe.md +4 -0
- package/syntaxes/markdown/__tests__/specs/tabs.html +25 -0
- package/syntaxes/markdown/__tests__/specs/tabs.md +21 -0
- package/syntaxes/markdown/__tests__/specs/tidyness.html +8 -0
- package/syntaxes/markdown/__tests__/specs/tidyness.md +5 -0
- package/syntaxes/markdown/__tests__/specs/toplevel_paragraphs.gfm.html +34 -0
- package/syntaxes/markdown/__tests__/specs/toplevel_paragraphs.gfm.md +37 -0
- package/syntaxes/markdown/__tests__/specs/tricky_list.html +23 -0
- package/syntaxes/markdown/__tests__/specs/tricky_list.md +15 -0
- package/syntaxes/markdown/__tests__/specs.js +74 -0
- package/syntaxes/markdown/re/inline.js +1 -1
- package/CHANGELOG.md +0 -121
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @honkit/markup-it
|
|
2
2
|
|
|
3
|
-
`@
|
|
3
|
+
`@honkit/markup-it` is a JavaScript library to parse and modify markuped content (for example Markdown) using an intermediate format backed by an immutable model.
|
|
4
4
|
|
|
5
|
-
`@
|
|
5
|
+
`@honkit/markup-it` is fork of [markup-it](https://github.com/GitbookIO/markup-it)@2.2.0
|
|
6
6
|
|
|
7
7
|
- Less dependency
|
|
8
8
|
- For stability
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
### Installation
|
|
11
11
|
|
|
12
12
|
```
|
|
13
|
-
$ npm i @
|
|
13
|
+
$ npm i @honkit/markup-it --save
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
### Usage
|
|
@@ -18,9 +18,9 @@ $ npm i @honkite/markup-it --save
|
|
|
18
18
|
Initialize a syntax:
|
|
19
19
|
|
|
20
20
|
```js
|
|
21
|
-
var MarkupIt = require('@
|
|
22
|
-
var markdownSyntax = require('@
|
|
23
|
-
var htmlSyntax = require('@
|
|
21
|
+
var MarkupIt = require('@honkit/markup-it');
|
|
22
|
+
var markdownSyntax = require('@honkit/markup-it/syntaxes/markdown');
|
|
23
|
+
var htmlSyntax = require('@honkit/markup-it/syntaxes/html');
|
|
24
24
|
|
|
25
25
|
var markdown = new MarkupIt(markdownSyntax);
|
|
26
26
|
var html = new MarkupIt(htmlSyntax);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
const __1 = __importDefault(require(".."));
|
|
8
|
+
describe("Custom Syntax", () => {
|
|
9
|
+
const syntax = __1.default.Syntax("mysyntax", {
|
|
10
|
+
inline: [
|
|
11
|
+
__1.default.Rule(__1.default.STYLES.BOLD)
|
|
12
|
+
.regExp(/^\*\*([\s\S]+?)\*\*/, (state, match) => {
|
|
13
|
+
return {
|
|
14
|
+
text: match[1],
|
|
15
|
+
};
|
|
16
|
+
})
|
|
17
|
+
.toText("**%s**"),
|
|
18
|
+
],
|
|
19
|
+
});
|
|
20
|
+
const markup = new __1.default(syntax);
|
|
21
|
+
describe(".toContent", () => {
|
|
22
|
+
it("should return correct syntax name", () => {
|
|
23
|
+
const content = markup.toContent("Hello");
|
|
24
|
+
content.getSyntax().should.equal("mysyntax");
|
|
25
|
+
});
|
|
26
|
+
it("should parse as unstyled", () => {
|
|
27
|
+
const content = markup.toContent("Hello World");
|
|
28
|
+
const doc = content.getToken();
|
|
29
|
+
const blocks = doc.getTokens();
|
|
30
|
+
blocks.size.should.equal(1);
|
|
31
|
+
const p = blocks.get(0);
|
|
32
|
+
p.getType().should.equal(__1.default.BLOCKS.TEXT);
|
|
33
|
+
p.getAsPlainText().should.equal("Hello World");
|
|
34
|
+
});
|
|
35
|
+
it("should parse inline", () => {
|
|
36
|
+
const content = markup.toContent("Hello **World**");
|
|
37
|
+
const doc = content.getToken();
|
|
38
|
+
const blocks = doc.getTokens();
|
|
39
|
+
blocks.size.should.equal(1);
|
|
40
|
+
const p = blocks.get(0);
|
|
41
|
+
p.getType().should.equal(__1.default.BLOCKS.TEXT);
|
|
42
|
+
p.getAsPlainText().should.equal("Hello World");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe(".toText", () => {
|
|
46
|
+
it("should output correct string", () => {
|
|
47
|
+
const content = __1.default.JSONUtils.decode({
|
|
48
|
+
syntax: "mysyntax",
|
|
49
|
+
token: {
|
|
50
|
+
type: __1.default.BLOCKS.DOCUMENT,
|
|
51
|
+
tokens: [
|
|
52
|
+
{
|
|
53
|
+
type: __1.default.BLOCKS.PARAGRAPH,
|
|
54
|
+
tokens: [
|
|
55
|
+
{
|
|
56
|
+
type: __1.default.STYLES.TEXT,
|
|
57
|
+
text: "Hello ",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: __1.default.STYLES.BOLD,
|
|
61
|
+
text: "World",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
const text = markup.toText(content);
|
|
69
|
+
text.should.equal("Hello **World**\n");
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const rule_1 = __importDefault(require("../models/rule"));
|
|
7
7
|
const blocks_1 = __importDefault(require("./blocks"));
|
|
8
8
|
const styles_1 = __importDefault(require("./styles"));
|
|
9
|
-
const defaultDocumentRule = rule_1.default(blocks_1.default.DOCUMENT)
|
|
9
|
+
const defaultDocumentRule = (0, rule_1.default)(blocks_1.default.DOCUMENT)
|
|
10
10
|
.match((state, text) => {
|
|
11
11
|
return {
|
|
12
12
|
tokens: state.parseAsBlock(text),
|
|
@@ -15,14 +15,14 @@ const defaultDocumentRule = rule_1.default(blocks_1.default.DOCUMENT)
|
|
|
15
15
|
.toText((state, token) => {
|
|
16
16
|
return state.renderAsBlock(token);
|
|
17
17
|
});
|
|
18
|
-
const defaultBlockRule = rule_1.default(blocks_1.default.TEXT)
|
|
18
|
+
const defaultBlockRule = (0, rule_1.default)(blocks_1.default.TEXT)
|
|
19
19
|
.match((state, text) => {
|
|
20
20
|
return {
|
|
21
21
|
tokens: state.parseAsInline(text),
|
|
22
22
|
};
|
|
23
23
|
})
|
|
24
24
|
.toText("%s\n");
|
|
25
|
-
const defaultInlineRule = rule_1.default(styles_1.default.TEXT)
|
|
25
|
+
const defaultInlineRule = (0, rule_1.default)(styles_1.default.TEXT)
|
|
26
26
|
.match((state, text) => {
|
|
27
27
|
return {
|
|
28
28
|
text: text,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const decode_1 = __importDefault(require("../decode"));
|
|
7
|
+
const blocks_1 = __importDefault(require("../../constants/blocks"));
|
|
8
|
+
describe("decode", () => {
|
|
9
|
+
let content;
|
|
10
|
+
beforeAll(() => {
|
|
11
|
+
content = (0, decode_1.default)({
|
|
12
|
+
syntax: "mysyntax",
|
|
13
|
+
token: {
|
|
14
|
+
type: blocks_1.default.DOCUMENT,
|
|
15
|
+
tokens: [
|
|
16
|
+
{
|
|
17
|
+
type: blocks_1.default.PARAGRAPH,
|
|
18
|
+
text: "Hello World",
|
|
19
|
+
raw: "Hello World",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
it("should decode syntax name", () => {
|
|
26
|
+
content.getSyntax().should.equal("mysyntax");
|
|
27
|
+
});
|
|
28
|
+
it("should decode tokens tree", () => {
|
|
29
|
+
const doc = content.getToken();
|
|
30
|
+
const tokens = doc.getTokens();
|
|
31
|
+
tokens.size.should.equal(1);
|
|
32
|
+
const p = tokens.get(0);
|
|
33
|
+
p.getType().should.equal(blocks_1.default.PARAGRAPH);
|
|
34
|
+
p.getText().should.equal("Hello World");
|
|
35
|
+
p.getRaw().should.equal("Hello World");
|
|
36
|
+
p.getTokens().size.should.equal(0);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const encode_1 = __importDefault(require("../encode"));
|
|
7
|
+
const blocks_1 = __importDefault(require("../../constants/blocks"));
|
|
8
|
+
describe("encode", () => {
|
|
9
|
+
let json;
|
|
10
|
+
beforeAll(() => {
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
json = (0, encode_1.default)(mock.paragraph);
|
|
13
|
+
});
|
|
14
|
+
it("should encode syntax name", () => {
|
|
15
|
+
json.syntax.should.equal("mysyntax");
|
|
16
|
+
});
|
|
17
|
+
it("should encode tokens", () => {
|
|
18
|
+
json.should.have.property("token");
|
|
19
|
+
const doc = json.token;
|
|
20
|
+
doc.tokens.should.have.lengthOf(1);
|
|
21
|
+
const p = doc.tokens[0];
|
|
22
|
+
p.type.should.equal(blocks_1.default.PARAGRAPH);
|
|
23
|
+
p.text.should.equal("Hello World");
|
|
24
|
+
p.tokens.should.be.an.Array().with.lengthOf(2);
|
|
25
|
+
});
|
|
26
|
+
});
|
package/lib/markup.js
CHANGED
|
@@ -22,7 +22,7 @@ function DraftMarkup(syntax) {
|
|
|
22
22
|
* @return {ContentState}
|
|
23
23
|
*/
|
|
24
24
|
DraftMarkup.prototype.toContent = function toContent(text, options) {
|
|
25
|
-
return parse_1.default(this.syntax, text, options);
|
|
25
|
+
return (0, parse_1.default)(this.syntax, text, options);
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
28
|
* Convert a text into an inline parsed content
|
|
@@ -40,7 +40,7 @@ DraftMarkup.prototype.toInlineContent = function toInlineContent(text) {
|
|
|
40
40
|
* @return {string}
|
|
41
41
|
*/
|
|
42
42
|
DraftMarkup.prototype.toText = function toText(content, options) {
|
|
43
|
-
return render_1.default(this.syntax, content, options);
|
|
43
|
+
return (0, render_1.default)(this.syntax, content, options);
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
46
|
* Convert a content to text
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const token_1 = __importDefault(require("../token"));
|
|
7
|
+
const styles_1 = __importDefault(require("../../constants/styles"));
|
|
8
|
+
describe("Token", () => {
|
|
9
|
+
describe(".mergeWith", () => {
|
|
10
|
+
it("should merge text and raw", () => {
|
|
11
|
+
const base = token_1.default.createText("Hello ");
|
|
12
|
+
const other = token_1.default.createText("world");
|
|
13
|
+
const token = base.mergeWith(other);
|
|
14
|
+
token.getType().should.equal(styles_1.default.TEXT);
|
|
15
|
+
token.getText().should.equal("Hello world");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
});
|
package/lib/models/token.js
CHANGED
|
@@ -57,7 +57,7 @@ Token.prototype.getTokens = function () {
|
|
|
57
57
|
* @return {boolean}
|
|
58
58
|
*/
|
|
59
59
|
Token.prototype.isBlock = function () {
|
|
60
|
-
return isBlock_1.default(this);
|
|
60
|
+
return (0, isBlock_1.default)(this);
|
|
61
61
|
};
|
|
62
62
|
/**
|
|
63
63
|
* Return true if is an inline token
|
|
@@ -71,14 +71,14 @@ Token.prototype.isInline = function () {
|
|
|
71
71
|
* @return {boolean}
|
|
72
72
|
*/
|
|
73
73
|
Token.prototype.isStyle = function () {
|
|
74
|
-
return isStyle_1.default(this);
|
|
74
|
+
return (0, isStyle_1.default)(this);
|
|
75
75
|
};
|
|
76
76
|
/**
|
|
77
77
|
* Return true if is an inline entity
|
|
78
78
|
* @return {boolean}
|
|
79
79
|
*/
|
|
80
80
|
Token.prototype.isEntity = function () {
|
|
81
|
-
return isEntity_1.default(this);
|
|
81
|
+
return (0, isEntity_1.default)(this);
|
|
82
82
|
};
|
|
83
83
|
/**
|
|
84
84
|
* Merge this token with another one
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
const token_1 = __importDefault(require("../../models/token"));
|
|
8
|
+
const styles_1 = __importDefault(require("../../constants/styles"));
|
|
9
|
+
const mergeTokens_1 = __importDefault(require("../mergeTokens"));
|
|
10
|
+
describe("mergeTokens", () => {
|
|
11
|
+
it("should merge two tokens", () => {
|
|
12
|
+
const tokens = immutable_1.default.List([token_1.default.createText("Hello "), token_1.default.createText("world")]);
|
|
13
|
+
const merged = (0, mergeTokens_1.default)(tokens, [styles_1.default.TEXT]);
|
|
14
|
+
merged.size.should.equal(1);
|
|
15
|
+
const resultToken = merged.get(0);
|
|
16
|
+
resultToken.getType().should.equal(styles_1.default.TEXT);
|
|
17
|
+
resultToken.getText().should.equal("Hello world");
|
|
18
|
+
});
|
|
19
|
+
it("should merge three tokens", () => {
|
|
20
|
+
const tokens = immutable_1.default.List([token_1.default.createText("Hello "), token_1.default.createText("world"), token_1.default.createText("!")]);
|
|
21
|
+
const merged = (0, mergeTokens_1.default)(tokens, [styles_1.default.TEXT]);
|
|
22
|
+
merged.size.should.equal(1);
|
|
23
|
+
const resultToken = merged.get(0);
|
|
24
|
+
resultToken.getType().should.equal(styles_1.default.TEXT);
|
|
25
|
+
resultToken.getText().should.equal("Hello world!");
|
|
26
|
+
});
|
|
27
|
+
it("should merge 2x2 tokens", () => {
|
|
28
|
+
const tokens = immutable_1.default.List([
|
|
29
|
+
token_1.default.createText("Hello "),
|
|
30
|
+
token_1.default.createText("world"),
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
new token_1.default({
|
|
33
|
+
type: styles_1.default.BOLD,
|
|
34
|
+
text: ", right?",
|
|
35
|
+
}),
|
|
36
|
+
token_1.default.createText("!"),
|
|
37
|
+
token_1.default.createText("!"),
|
|
38
|
+
]);
|
|
39
|
+
const merged = (0, mergeTokens_1.default)(tokens, [styles_1.default.TEXT]);
|
|
40
|
+
merged.size.should.equal(3);
|
|
41
|
+
const first = merged.get(0);
|
|
42
|
+
const bold = merged.get(1);
|
|
43
|
+
const second = merged.get(2);
|
|
44
|
+
first.getType().should.equal(styles_1.default.TEXT);
|
|
45
|
+
first.getText().should.equal("Hello world");
|
|
46
|
+
bold.getType().should.equal(styles_1.default.BOLD);
|
|
47
|
+
bold.getText().should.equal(", right?");
|
|
48
|
+
second.getType().should.equal(styles_1.default.TEXT);
|
|
49
|
+
second.getText().should.equal("!!");
|
|
50
|
+
});
|
|
51
|
+
});
|
package/lib/parse/index.js
CHANGED
|
@@ -16,7 +16,7 @@ function parse(syntax, text, options) {
|
|
|
16
16
|
const entryRule = syntax.getEntryRule();
|
|
17
17
|
// @ts-ignore
|
|
18
18
|
const state = new state_1.default(syntax, options);
|
|
19
|
-
const tokens = matchRule_1.default(state, entryRule, text);
|
|
19
|
+
const tokens = (0, matchRule_1.default)(state, entryRule, text);
|
|
20
20
|
return content_1.default.createFromToken(syntax.getName(), tokens.first());
|
|
21
21
|
}
|
|
22
22
|
/**
|
package/lib/parse/lex.js
CHANGED
|
@@ -21,10 +21,10 @@ function lex(state, rules, isInline, text, nonParsed) {
|
|
|
21
21
|
let matchedTokens;
|
|
22
22
|
nonParsed = nonParsed || "";
|
|
23
23
|
if (!text) {
|
|
24
|
-
return tokens.concat(textToUnstyledTokens_1.default(state, isInline, nonParsed));
|
|
24
|
+
return tokens.concat((0, textToUnstyledTokens_1.default)(state, isInline, nonParsed));
|
|
25
25
|
}
|
|
26
26
|
rules.forEach((rule) => {
|
|
27
|
-
matchedTokens = matchRule_1.default(state, rule, text);
|
|
27
|
+
matchedTokens = (0, matchRule_1.default)(state, rule, text);
|
|
28
28
|
if (!matchedTokens) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
@@ -39,7 +39,7 @@ function lex(state, rules, isInline, text, nonParsed) {
|
|
|
39
39
|
return result.substring(token.getRaw().length);
|
|
40
40
|
}, text);
|
|
41
41
|
// Keep parsing
|
|
42
|
-
tokens = textToUnstyledTokens_1.default(state, isInline, nonParsed)
|
|
42
|
+
tokens = (0, textToUnstyledTokens_1.default)(state, isInline, nonParsed)
|
|
43
43
|
.concat(matchedTokens)
|
|
44
44
|
// @ts-ignore
|
|
45
45
|
.concat(lex(state, rules, isInline, newText));
|
package/lib/parse/state.js
CHANGED
|
@@ -85,9 +85,9 @@ ParsingState.prototype.parse = function (rulesSet, isInline, text) {
|
|
|
85
85
|
this.depth++;
|
|
86
86
|
const rules = rulesSet.getRules();
|
|
87
87
|
// @ts-ignore
|
|
88
|
-
let tokens = lex_1.default(this, rules, isInline, text);
|
|
88
|
+
let tokens = (0, lex_1.default)(this, rules, isInline, text);
|
|
89
89
|
if (isInline) {
|
|
90
|
-
tokens = mergeTokens_1.default(tokens, [styles_1.default.TEXT]);
|
|
90
|
+
tokens = (0, mergeTokens_1.default)(tokens, [styles_1.default.TEXT]);
|
|
91
91
|
}
|
|
92
92
|
this.depth--;
|
|
93
93
|
return tokens;
|
|
@@ -16,7 +16,7 @@ const matchRule_1 = __importDefault(require("./matchRule"));
|
|
|
16
16
|
*/
|
|
17
17
|
function createTextToken(state, isInline, text) {
|
|
18
18
|
const rule = isInline ? defaultRules_1.default.inlineRule : defaultRules_1.default.blockRule;
|
|
19
|
-
return matchRule_1.default(state, rule, text).get(0);
|
|
19
|
+
return (0, matchRule_1.default)(state, rule, text).get(0);
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Convert a normal text into a list of unstyled tokens (block or inline)
|
package/lib/render/state.js
CHANGED
|
@@ -11,7 +11,7 @@ function RenderingState(syntax, options) {
|
|
|
11
11
|
return new RenderingState(syntax);
|
|
12
12
|
}
|
|
13
13
|
this.syntax = syntax;
|
|
14
|
-
this.options = options_1.default(options || {});
|
|
14
|
+
this.options = (0, options_1.default)(options || {});
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Render a token using a set of rules
|
package/lib/utils/walk.js
CHANGED
|
@@ -18,7 +18,7 @@ function walk(base, iter) {
|
|
|
18
18
|
let offset = 0;
|
|
19
19
|
const tokens = base.getTokens();
|
|
20
20
|
if (tokens.size === 0) {
|
|
21
|
-
iter(base, range_utils_1.default(0, base.getText().length));
|
|
21
|
+
iter(base, (0, range_utils_1.default)(0, base.getText().length));
|
|
22
22
|
return base.getText();
|
|
23
23
|
}
|
|
24
24
|
return tokens.reduce((output, token) => {
|
|
@@ -29,7 +29,7 @@ function walk(base, iter) {
|
|
|
29
29
|
const realRange = range_utils_1.default.moveBy(range, offset);
|
|
30
30
|
iter(tok, realRange);
|
|
31
31
|
});
|
|
32
|
-
iter(token, range_utils_1.default(offset, innerText.length));
|
|
32
|
+
iter(token, (0, range_utils_1.default)(offset, innerText.length));
|
|
33
33
|
offset += innerText.length;
|
|
34
34
|
return output + innerText;
|
|
35
35
|
}, "");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@honkit/markup-it",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.2",
|
|
4
4
|
"description": "Pipeline for working with markup input (for example Markdown)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"draft-js",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "89e4ff9d86596d7c650c5e83e2d768435d6eef20"
|
|
57
57
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<p>AT&T has an ampersand in their name.</p>
|
|
2
|
+
|
|
3
|
+
<p>AT&T is another way to write it.</p>
|
|
4
|
+
|
|
5
|
+
<p>This & that.</p>
|
|
6
|
+
|
|
7
|
+
<p>4 < 5.</p>
|
|
8
|
+
|
|
9
|
+
<p>6 > 5.</p>
|
|
10
|
+
|
|
11
|
+
<p>Here's a <a href="http://example.com/?foo=1&bar=2">link</a> with an ampersand in the URL.</p>
|
|
12
|
+
|
|
13
|
+
<p>Here's a link with an amersand in the link text: <a href="http://att.com/" title="AT&T">AT&T</a>.</p>
|
|
14
|
+
|
|
15
|
+
<p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
|
|
16
|
+
|
|
17
|
+
<p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
AT&T has an ampersand in their name.
|
|
2
|
+
|
|
3
|
+
AT&T is another way to write it.
|
|
4
|
+
|
|
5
|
+
This & that.
|
|
6
|
+
|
|
7
|
+
4 < 5.
|
|
8
|
+
|
|
9
|
+
6 > 5.
|
|
10
|
+
|
|
11
|
+
Here's a [link] [1] with an ampersand in the URL.
|
|
12
|
+
|
|
13
|
+
Here's a link with an amersand in the link text: [AT&T] [2].
|
|
14
|
+
|
|
15
|
+
Here's an inline [link](/script?foo=1&bar=2).
|
|
16
|
+
|
|
17
|
+
Here's an inline [link](</script?foo=1&bar=2>).
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
[1]: http://example.com/?foo=1&bar=2
|
|
21
|
+
[2]: http://att.com/ "AT&T"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<p>Link: <a href="http://example.com/">http://example.com/</a>.</p>
|
|
2
|
+
|
|
3
|
+
<p>With an ampersand: <a href="http://example.com/?foo=1&bar=2">http://example.com/?foo=1&bar=2</a></p>
|
|
4
|
+
|
|
5
|
+
<ul>
|
|
6
|
+
<li>In a list?</li>
|
|
7
|
+
<li><a href="http://example.com/">http://example.com/</a></li>
|
|
8
|
+
<li>It should.</li>
|
|
9
|
+
</ul>
|
|
10
|
+
|
|
11
|
+
<blockquote>
|
|
12
|
+
<p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
|
|
13
|
+
</blockquote>
|
|
14
|
+
|
|
15
|
+
<p>Auto-links should not occur here: <code><http://example.com/></code></p>
|
|
16
|
+
|
|
17
|
+
<pre><code>or here: <http://example.com/>
|
|
18
|
+
</code></pre>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Link: <http://example.com/>.
|
|
2
|
+
|
|
3
|
+
With an ampersand: <http://example.com/?foo=1&bar=2>
|
|
4
|
+
|
|
5
|
+
* In a list?
|
|
6
|
+
* <http://example.com/>
|
|
7
|
+
* It should.
|
|
8
|
+
|
|
9
|
+
> Blockquoted: <http://example.com/>
|
|
10
|
+
|
|
11
|
+
Auto-links should not occur here: `<http://example.com/>`
|
|
12
|
+
|
|
13
|
+
or here: <http://example.com/>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
<p>These should all get escaped:</p>
|
|
2
|
+
|
|
3
|
+
<p>Backslash: \</p>
|
|
4
|
+
|
|
5
|
+
<p>Backtick: `</p>
|
|
6
|
+
|
|
7
|
+
<p>Asterisk: *</p>
|
|
8
|
+
|
|
9
|
+
<p>Underscore: _</p>
|
|
10
|
+
|
|
11
|
+
<p>Left brace: {</p>
|
|
12
|
+
|
|
13
|
+
<p>Right brace: }</p>
|
|
14
|
+
|
|
15
|
+
<p>Left bracket: [</p>
|
|
16
|
+
|
|
17
|
+
<p>Right bracket: ]</p>
|
|
18
|
+
|
|
19
|
+
<p>Left paren: (</p>
|
|
20
|
+
|
|
21
|
+
<p>Right paren: )</p>
|
|
22
|
+
|
|
23
|
+
<p>Greater-than: ></p>
|
|
24
|
+
|
|
25
|
+
<p>Hash: #</p>
|
|
26
|
+
|
|
27
|
+
<p>Period: .</p>
|
|
28
|
+
|
|
29
|
+
<p>Bang: !</p>
|
|
30
|
+
|
|
31
|
+
<p>Plus: +</p>
|
|
32
|
+
|
|
33
|
+
<p>Minus: -</p>
|
|
34
|
+
|
|
35
|
+
<p>These should not, because they occur within a code block:</p>
|
|
36
|
+
|
|
37
|
+
<pre><code>Backslash: \\
|
|
38
|
+
|
|
39
|
+
Backtick: \`
|
|
40
|
+
|
|
41
|
+
Asterisk: \*
|
|
42
|
+
|
|
43
|
+
Underscore: \_
|
|
44
|
+
|
|
45
|
+
Left brace: \{
|
|
46
|
+
|
|
47
|
+
Right brace: \}
|
|
48
|
+
|
|
49
|
+
Left bracket: \[
|
|
50
|
+
|
|
51
|
+
Right bracket: \]
|
|
52
|
+
|
|
53
|
+
Left paren: \(
|
|
54
|
+
|
|
55
|
+
Right paren: \)
|
|
56
|
+
|
|
57
|
+
Greater-than: \>
|
|
58
|
+
|
|
59
|
+
Hash: \#
|
|
60
|
+
|
|
61
|
+
Period: \.
|
|
62
|
+
|
|
63
|
+
Bang: \!
|
|
64
|
+
|
|
65
|
+
Plus: \+
|
|
66
|
+
|
|
67
|
+
Minus: \-
|
|
68
|
+
</code></pre>
|
|
69
|
+
|
|
70
|
+
<p>Nor should these, which occur in code spans:</p>
|
|
71
|
+
|
|
72
|
+
<p>Backslash: <code>\\</code></p>
|
|
73
|
+
|
|
74
|
+
<p>Backtick: <code>\`</code></p>
|
|
75
|
+
|
|
76
|
+
<p>Asterisk: <code>\*</code></p>
|
|
77
|
+
|
|
78
|
+
<p>Underscore: <code>\_</code></p>
|
|
79
|
+
|
|
80
|
+
<p>Left brace: <code>\{</code></p>
|
|
81
|
+
|
|
82
|
+
<p>Right brace: <code>\}</code></p>
|
|
83
|
+
|
|
84
|
+
<p>Left bracket: <code>\[</code></p>
|
|
85
|
+
|
|
86
|
+
<p>Right bracket: <code>\]</code></p>
|
|
87
|
+
|
|
88
|
+
<p>Left paren: <code>\(</code></p>
|
|
89
|
+
|
|
90
|
+
<p>Right paren: <code>\)</code></p>
|
|
91
|
+
|
|
92
|
+
<p>Greater-than: <code>\></code></p>
|
|
93
|
+
|
|
94
|
+
<p>Hash: <code>\#</code></p>
|
|
95
|
+
|
|
96
|
+
<p>Period: <code>\.</code></p>
|
|
97
|
+
|
|
98
|
+
<p>Bang: <code>\!</code></p>
|
|
99
|
+
|
|
100
|
+
<p>Plus: <code>\+</code></p>
|
|
101
|
+
|
|
102
|
+
<p>Minus: <code>\-</code></p>
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
<p>These should get escaped, even though they're matching pairs for
|
|
106
|
+
other Markdown constructs:</p>
|
|
107
|
+
|
|
108
|
+
<p>*asterisks*</p>
|
|
109
|
+
|
|
110
|
+
<p>_underscores_</p>
|
|
111
|
+
|
|
112
|
+
<p>`backticks`</p>
|
|
113
|
+
|
|
114
|
+
<p>This is a code span with a literal backslash-backtick sequence: <code>\`</code></p>
|
|
115
|
+
|
|
116
|
+
<p>This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.</p>
|
|
117
|
+
|
|
118
|
+
<p>This is a tag with backslashes <span attr='\\backslashes\\'>bar</span>.</p>
|