diff options
author | Robin Appelman <robin@icewind.nl> | 2018-02-26 19:15:34 +0300 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2018-02-26 19:15:34 +0300 |
commit | d6d35b248c8b64756da548e084e6462caf6e689c (patch) | |
tree | e27624d94814192ad0c133b74e078b5d1ea1f100 | |
parent | 041f45ea08f104cfeeaff072db2741853d4a1496 (diff) |
better tracking of line numbers for checkboxes
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | js/CheckboxPlugin.ts | 16 | ||||
-rw-r--r-- | package-lock.json | 46 |
2 files changed, 34 insertions, 28 deletions
diff --git a/js/CheckboxPlugin.ts b/js/CheckboxPlugin.ts index 0bb6800..c83ba06 100644 --- a/js/CheckboxPlugin.ts +++ b/js/CheckboxPlugin.ts @@ -45,7 +45,7 @@ export function CheckBoxReplacer(md: MarkdownIt.MarkdownIt, userOptions: Partial } /** - * <input type="checkbox" id="checkbox{n}" checked="true"> + * <input type="checkbox" id="checkbox{n}" checked="true data-line="{n}"> */ const id = options.idPrefix + lastId; lastId += 1; @@ -102,9 +102,15 @@ export function CheckBoxReplacer(md: MarkdownIt.MarkdownIt, userOptions: Partial return function (state: CheckboxReplacerState) { for (const token of state.tokens) { if (token.type === "inline") { - token.children = ([] as Token[]).concat.apply([], - token.children.map(childToken => splitTextToken(childToken, state.Token, token.map ? token.map[0] : 0)) - ); + let currentLine = token.map ? token.map[0] : 0; + let newChildren: Token[] = []; + for (const childToken of token.children) { + if (childToken.type === 'hardbreak' || childToken.type === 'softbreak') { + currentLine++; + } + newChildren = newChildren.concat(splitTextToken(childToken, state.Token, currentLine)) + } + token.children = newChildren; } } }; @@ -112,4 +118,4 @@ export function CheckBoxReplacer(md: MarkdownIt.MarkdownIt, userOptions: Partial export function CheckboxPlugin(md: MarkdownIt.MarkdownIt, options: CheckboxPluginOptions) { md.core.ruler.push("checkbox", CheckBoxReplacer(md, options)); -}
\ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index 47db9cc..c502152 100644 --- a/package-lock.json +++ b/package-lock.json @@ -91,6 +91,16 @@ "integrity": "sha1-MEQ4FkfhHulzxa8uklMjkw9pHYA=", "dev": true }, + "JSONStream": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.1.tgz", + "integrity": "sha1-cH92HgHa6eFvG8+TcDt4xwlmV5o=", + "dev": true, + "requires": { + "jsonparse": "1.3.1", + "through": "2.3.8" + } + }, "acorn": { "version": "4.0.13", "resolved": "https://registry.npmjs.org/acorn/-/acorn-4.0.13.tgz", @@ -914,9 +924,9 @@ "integrity": "sha1-+GzWzvT1MAyOY+B6TVEvZfv/RTE=", "dev": true, "requires": { + "JSONStream": "1.3.1", "combine-source-map": "0.7.2", "defined": "1.0.0", - "JSONStream": "1.3.1", "through2": "2.0.3", "umd": "3.0.1" } @@ -944,6 +954,7 @@ "integrity": "sha1-CJo0Y69Y0OSNjNQHCz90ZU1avKk=", "dev": true, "requires": { + "JSONStream": "1.3.1", "assert": "1.4.1", "browser-pack": "6.0.2", "browser-resolve": "1.11.2", @@ -965,7 +976,6 @@ "https-browserify": "1.0.0", "inherits": "2.0.3", "insert-module-globals": "7.0.1", - "JSONStream": "1.3.1", "labeled-stream-splicer": "2.0.0", "module-deps": "4.1.1", "os-browserify": "0.1.2", @@ -2329,10 +2339,10 @@ "integrity": "sha1-wDv04BywhtW15azorQr+eInWOMM=", "dev": true, "requires": { + "JSONStream": "1.3.1", "combine-source-map": "0.7.2", "concat-stream": "1.5.2", "is-buffer": "1.1.5", - "JSONStream": "1.3.1", "lexical-scope": "1.2.0", "process": "0.11.10", "through2": "2.0.3", @@ -2579,16 +2589,6 @@ "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=", "dev": true }, - "JSONStream": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.1.tgz", - "integrity": "sha1-cH92HgHa6eFvG8+TcDt4xwlmV5o=", - "dev": true, - "requires": { - "jsonparse": "1.3.1", - "through": "2.3.8" - } - }, "katex": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/katex/-/katex-0.8.2.tgz", @@ -3027,6 +3027,7 @@ "integrity": "sha1-IyFYM/HaE/1gbMuAh7RIUty4If0=", "dev": true, "requires": { + "JSONStream": "1.3.1", "browser-resolve": "1.11.2", "cached-path-relative": "1.0.1", "concat-stream": "1.5.2", @@ -3034,7 +3035,6 @@ "detective": "4.5.0", "duplexer2": "0.1.4", "inherits": "2.0.3", - "JSONStream": "1.3.1", "parents": "1.0.1", "readable-stream": "2.3.3", "resolve": "1.4.0", @@ -4411,15 +4411,6 @@ "resolved": "https://registry.npmjs.org/string/-/string-3.3.3.tgz", "integrity": "sha1-XqIRzZLSKOGEKUmQpsyXs2anfLA=" }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "dev": true, - "requires": { - "safe-buffer": "5.1.1" - } - }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -4453,6 +4444,15 @@ } } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "dev": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, "strip-ansi": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", |