rapier-markdown-kit 1.2.21 → 1.2.23
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/dist/spec/md-engine.mjs +67 -0
- package/package.json +1 -1
package/dist/spec/md-engine.mjs
CHANGED
|
@@ -72,6 +72,72 @@ function cleanWebLink(url) {
|
|
|
72
72
|
return match !== null && match[1].length <= 255;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
function releasedState(state, md) {
|
|
76
|
+
for (const key of Object.keys(state)) {
|
|
77
|
+
const value = state[key];
|
|
78
|
+
if (typeof value === 'string') state[key] = '';
|
|
79
|
+
else if (typeof value === 'function') state[key] = released;
|
|
80
|
+
else if (value !== null && typeof value === 'object' && value !== md) state[key] = Array.isArray(value) ? [] : {};
|
|
81
|
+
}
|
|
82
|
+
return state;
|
|
83
|
+
}
|
|
84
|
+
function released() {}
|
|
85
|
+
function sampleTokens(tokens) {
|
|
86
|
+
const kept = new Map();
|
|
87
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
88
|
+
const token = tokens[index];
|
|
89
|
+
if (!kept.has(token.type)) kept.set(token.type, token);
|
|
90
|
+
const children = token.children;
|
|
91
|
+
if (children) for (let at = 0; at < children.length; at++) {
|
|
92
|
+
const child = children[at];
|
|
93
|
+
if (!kept.has(child.type)) kept.set(child.type, child);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return kept;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function keepClasses(md) {
|
|
100
|
+
const anchors = {core: null, block: null, inline: null, tokens: null};
|
|
101
|
+
const finish = (state, tokens) => {
|
|
102
|
+
anchors.core = releasedState(state, md);
|
|
103
|
+
if (anchors.block) releasedState(anchors.block, md);
|
|
104
|
+
if (anchors.inline) releasedState(anchors.inline, md);
|
|
105
|
+
anchors.tokens = sampleTokens(tokens);
|
|
106
|
+
};
|
|
107
|
+
const release = (owner, key) => Object.getPrototypeOf(owner)[key] === owner[key];
|
|
108
|
+
if (release(md, 'parse') && release(md, 'parseInline')) {
|
|
109
|
+
md.parse = function (src, env) {
|
|
110
|
+
if (typeof src !== 'string') throw new Error('Input data should be a String');
|
|
111
|
+
const state = new this.core.State(src, this, env);
|
|
112
|
+
this.core.process(state);
|
|
113
|
+
const tokens = state.tokens;
|
|
114
|
+
finish(state, tokens);
|
|
115
|
+
return tokens;
|
|
116
|
+
};
|
|
117
|
+
md.parseInline = function (src, env) {
|
|
118
|
+
const state = new this.core.State(src, this, env);
|
|
119
|
+
state.inlineMode = true;
|
|
120
|
+
this.core.process(state);
|
|
121
|
+
const tokens = state.tokens;
|
|
122
|
+
finish(state, tokens);
|
|
123
|
+
return tokens;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (release(md.block, 'parse')) md.block.parse = function (src, md, env, outTokens) {
|
|
127
|
+
if (!src) return;
|
|
128
|
+
const state = new this.State(src, md, env, outTokens);
|
|
129
|
+
this.tokenize(state, state.line, state.lineMax);
|
|
130
|
+
anchors.block = state;
|
|
131
|
+
};
|
|
132
|
+
if (release(md.inline, 'parse')) md.inline.parse = function (str, md, env, outTokens) {
|
|
133
|
+
const state = new this.State(str, md, env, outTokens);
|
|
134
|
+
this.tokenize(state);
|
|
135
|
+
const rules = this.ruler2.getRules(''), length = rules.length;
|
|
136
|
+
for (let index = 0; index < length; index++) rules[index](state);
|
|
137
|
+
anchors.inline = state;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
75
141
|
export function tuneMarkdownEngine(md) {
|
|
76
142
|
if (md.__rapierEngineTuned) return md;
|
|
77
143
|
md.__rapierEngineTuned = true;
|
|
@@ -86,5 +152,6 @@ export function tuneMarkdownEngine(md) {
|
|
|
86
152
|
md.inline.ruler.at('backticks', backticks);
|
|
87
153
|
const normalizeLink = md.normalizeLink;
|
|
88
154
|
md.normalizeLink = url => cleanWebLink(url) ? url : normalizeLink.call(md, url);
|
|
155
|
+
keepClasses(md);
|
|
89
156
|
return md;
|
|
90
157
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rapier-markdown-kit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.23",
|
|
4
4
|
"description": "Read, render and write Self-contained Markdown: one .md file that carries its pictures, drawings and layout, and that any Markdown app can read. HTML renderer, stylesheet, text layout, Will/1 agent permissions, and an edit history with authorship and offline merge. MIT, no dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|