@markuplint/parser-utils 4.0.0-dev.0 → 4.0.0-dev.12

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.
Files changed (47) hide show
  1. package/LICENSE +1 -1
  2. package/lib/attr-tokenizer.d.ts +16 -4
  3. package/lib/attr-tokenizer.js +164 -70
  4. package/lib/const.d.ts +2 -1
  5. package/lib/const.js +2 -1
  6. package/lib/debugger.d.ts +3 -2
  7. package/lib/debugger.js +35 -19
  8. package/lib/enums.d.ts +16 -0
  9. package/lib/enums.js +18 -0
  10. package/lib/get-location.d.ts +4 -13
  11. package/lib/get-location.js +10 -21
  12. package/lib/ignore-block.d.ts +3 -2
  13. package/lib/ignore-block.js +62 -124
  14. package/lib/ignore-front-matter.d.ts +4 -1
  15. package/lib/ignore-front-matter.js +12 -3
  16. package/lib/index.d.ts +3 -16
  17. package/lib/index.js +3 -16
  18. package/lib/parser-error.d.ts +1 -0
  19. package/lib/parser-error.js +1 -0
  20. package/lib/parser.d.ts +108 -0
  21. package/lib/parser.js +1076 -0
  22. package/lib/script-parser.d.ts +1 -1
  23. package/lib/script-parser.js +1 -1
  24. package/lib/sort-nodes.d.ts +2 -0
  25. package/lib/sort-nodes.js +18 -0
  26. package/lib/types.d.ts +34 -0
  27. package/package.json +9 -5
  28. package/lib/attr-parser.d.ts +0 -25
  29. package/lib/attr-parser.js +0 -188
  30. package/lib/create-token.d.ts +0 -4
  31. package/lib/create-token.js +0 -29
  32. package/lib/flatten-nodes.d.ts +0 -2
  33. package/lib/flatten-nodes.js +0 -247
  34. package/lib/get-space-before.d.ts +0 -1
  35. package/lib/get-space-before.js +0 -8
  36. package/lib/parse-attr.d.ts +0 -24
  37. package/lib/parse-attr.js +0 -144
  38. package/lib/remove-deprecated-node.d.ts +0 -7
  39. package/lib/remove-deprecated-node.js +0 -39
  40. package/lib/siblings-correction.d.ts +0 -9
  41. package/lib/siblings-correction.js +0 -21
  42. package/lib/tag-parser.d.ts +0 -10
  43. package/lib/tag-parser.js +0 -152
  44. package/lib/tag-splitter.d.ts +0 -7
  45. package/lib/tag-splitter.js +0 -96
  46. package/lib/walker.d.ts +0 -2
  47. package/lib/walker.js +0 -18
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2023 Yusuke Hirao
3
+ Copyright (c) 2017-2024 Yusuke Hirao
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,18 @@
1
1
  import type { QuoteSet } from './types.js';
2
- import type { MLASTHTMLAttr } from '@markuplint/ml-ast';
3
- import { AttrState } from './attr-parser.js';
4
- export declare function attrTokenizer(raw: string, line: number, col: number, startOffset: number, quoteSet?: ReadonlyArray<QuoteSet>, startState?: AttrState, quoteInValueChars?: ReadonlyArray<QuoteSet>, spaces?: ReadonlyArray<string>): MLASTHTMLAttr & {
5
- __leftover?: string;
2
+ import { AttrState } from './enums.js';
3
+ /**
4
+ * @see https://html.spec.whatwg.org/multipage/parsing.html#tag-name-state
5
+ * @see https://html.spec.whatwg.org/multipage/parsing.html#before-attribute-name-state
6
+ * @see https://html.spec.whatwg.org/multipage/parsing.html#attribute-name-state
7
+ */
8
+ export declare function attrTokenizer(raw: string, quoteSet?: readonly QuoteSet[], startState?: AttrState, quoteInValueChars?: ReadonlyArray<QuoteSet>, endOfUnquotedValueChars?: ReadonlyArray<string>): {
9
+ spacesBeforeAttrName: string;
10
+ attrName: string;
11
+ spacesBeforeEqual: string;
12
+ equal: string;
13
+ spacesAfterEqual: string;
14
+ quoteStart: string;
15
+ attrValue: string;
16
+ quoteEnd: string;
17
+ leftover: string;
6
18
  };
@@ -1,75 +1,169 @@
1
- import { AttrState, attrParser } from './attr-parser.js';
2
- import { tokenizer, uuid } from './create-token.js';
3
- export function attrTokenizer(raw, line, col, startOffset, quoteSet, startState = AttrState.BeforeName, quoteInValueChars, spaces) {
4
- const parsed = attrParser(raw, quoteSet, startState, quoteInValueChars, spaces);
5
- let offset = startOffset;
6
- const spacesBeforeName = tokenizer(parsed.spacesBeforeAttrName, line, col, offset);
7
- line = spacesBeforeName.endLine;
8
- col = spacesBeforeName.endCol;
9
- offset = spacesBeforeName.endOffset;
10
- const name = tokenizer(parsed.attrName, line, col, offset);
11
- line = name.endLine;
12
- col = name.endCol;
13
- offset = name.endOffset;
14
- const spacesBeforeEqual = tokenizer(parsed.spacesBeforeEqual, line, col, offset);
15
- line = spacesBeforeEqual.endLine;
16
- col = spacesBeforeEqual.endCol;
17
- offset = spacesBeforeEqual.endOffset;
18
- const equal = tokenizer(parsed.equal, line, col, offset);
19
- line = equal.endLine;
20
- col = equal.endCol;
21
- offset = equal.endOffset;
22
- const spacesAfterEqual = tokenizer(parsed.spacesAfterEqual, line, col, offset);
23
- line = spacesAfterEqual.endLine;
24
- col = spacesAfterEqual.endCol;
25
- offset = spacesAfterEqual.endOffset;
26
- const startQuote = tokenizer(parsed.quoteStart, line, col, offset);
27
- line = startQuote.endLine;
28
- col = startQuote.endCol;
29
- offset = startQuote.endOffset;
30
- const value = tokenizer(parsed.attrValue, line, col, offset);
31
- line = value.endLine;
32
- col = value.endCol;
33
- offset = value.endOffset;
34
- const endQuote = tokenizer(parsed.quoteEnd, line, col, offset);
35
- const attrToken = tokenizer(parsed.attrName +
36
- parsed.spacesBeforeEqual +
37
- parsed.equal +
38
- parsed.spacesAfterEqual +
39
- parsed.quoteStart +
40
- parsed.attrValue +
41
- parsed.quoteEnd, name.startLine, name.startCol, name.startOffset);
42
- const result = {
43
- type: 'html-attr',
44
- uuid: uuid(),
45
- raw: attrToken.raw,
46
- startOffset: attrToken.startOffset,
47
- endOffset: attrToken.endOffset,
48
- startLine: attrToken.startLine,
49
- endLine: attrToken.endLine,
50
- startCol: attrToken.startCol,
51
- endCol: attrToken.endCol,
52
- spacesBeforeName,
53
- name,
1
+ import { defaultSpaces } from './const.js';
2
+ import { AttrState } from './enums.js';
3
+ const defaultQuoteSet = [
4
+ { start: '"', end: '"' },
5
+ { start: "'", end: "'" },
6
+ ];
7
+ const defaultQuoteInValueChars = [];
8
+ const spaces = defaultSpaces;
9
+ const EQUAL = '=';
10
+ /**
11
+ * @see https://html.spec.whatwg.org/multipage/parsing.html#tag-name-state
12
+ * @see https://html.spec.whatwg.org/multipage/parsing.html#before-attribute-name-state
13
+ * @see https://html.spec.whatwg.org/multipage/parsing.html#attribute-name-state
14
+ */
15
+ export function attrTokenizer(raw, quoteSet = defaultQuoteSet, startState = AttrState.BeforeName, quoteInValueChars = defaultQuoteInValueChars, endOfUnquotedValueChars = [...defaultSpaces, '/', '>']) {
16
+ let state = startState;
17
+ let spacesBeforeAttrName = '';
18
+ let attrName = '';
19
+ let spacesBeforeEqual = '';
20
+ let equal = '';
21
+ let spacesAfterEqual = '';
22
+ let quoteTypeIndex = -1;
23
+ let quoteStart = '';
24
+ let attrValue = '';
25
+ let quoteEnd = '';
26
+ const isBeforeValueStarted = startState === AttrState.BeforeValue;
27
+ const quoteModeStack = [];
28
+ const chars = [...raw];
29
+ while (chars.length > 0) {
30
+ if (state === AttrState.AfterValue) {
31
+ break;
32
+ }
33
+ const char = chars.shift();
34
+ switch (state) {
35
+ case AttrState.BeforeName: {
36
+ if (char === '>') {
37
+ chars.unshift(char);
38
+ state = AttrState.AfterValue;
39
+ break;
40
+ }
41
+ if (char === '/') {
42
+ chars.unshift(char);
43
+ state = AttrState.AfterValue;
44
+ break;
45
+ }
46
+ if (spaces.includes(char)) {
47
+ spacesBeforeAttrName += char;
48
+ break;
49
+ }
50
+ attrName += char;
51
+ state = AttrState.Name;
52
+ break;
53
+ }
54
+ case AttrState.Name: {
55
+ if (char === '>') {
56
+ chars.unshift(char);
57
+ state = AttrState.AfterValue;
58
+ break;
59
+ }
60
+ if (char === '/') {
61
+ chars.unshift(char);
62
+ state = AttrState.AfterValue;
63
+ break;
64
+ }
65
+ if (spaces.includes(char)) {
66
+ spacesBeforeEqual += char;
67
+ state = AttrState.Equal;
68
+ break;
69
+ }
70
+ if (char === EQUAL) {
71
+ equal += char;
72
+ state = AttrState.BeforeValue;
73
+ break;
74
+ }
75
+ attrName += char;
76
+ break;
77
+ }
78
+ case AttrState.Equal: {
79
+ if (spaces.includes(char)) {
80
+ spacesBeforeEqual += char;
81
+ break;
82
+ }
83
+ if (char === EQUAL) {
84
+ equal += char;
85
+ state = AttrState.BeforeValue;
86
+ break;
87
+ }
88
+ // End of attribute
89
+ chars.unshift(spacesBeforeEqual, char);
90
+ spacesBeforeEqual = '';
91
+ state = AttrState.AfterValue;
92
+ break;
93
+ }
94
+ case AttrState.BeforeValue: {
95
+ if (endOfUnquotedValueChars.includes(char) && spaces.includes(char)) {
96
+ if (isBeforeValueStarted) {
97
+ spacesBeforeAttrName += char;
98
+ break;
99
+ }
100
+ spacesAfterEqual += char;
101
+ break;
102
+ }
103
+ quoteTypeIndex = quoteSet.findIndex(quote => quote.start === char);
104
+ const quote = quoteSet[quoteTypeIndex];
105
+ if (quote) {
106
+ quoteStart = quote.start;
107
+ state = AttrState.Value;
108
+ break;
109
+ }
110
+ const raw = char + chars.join('');
111
+ const inQuote = quoteInValueChars.find(quote => raw.startsWith(quote.start));
112
+ if (inQuote) {
113
+ quoteModeStack.push(inQuote);
114
+ attrValue += inQuote.start;
115
+ chars.splice(0, inQuote.start.length - 1);
116
+ state = AttrState.Value;
117
+ break;
118
+ }
119
+ chars.unshift(char);
120
+ state = AttrState.Value;
121
+ break;
122
+ }
123
+ case AttrState.Value: {
124
+ if (!quoteSet[quoteTypeIndex] && endOfUnquotedValueChars.includes(char)) {
125
+ chars.unshift(char);
126
+ state = AttrState.AfterValue;
127
+ break;
128
+ }
129
+ if (quoteModeStack.length === 0 && char === quoteSet[quoteTypeIndex]?.end) {
130
+ quoteEnd = char;
131
+ state = AttrState.AfterValue;
132
+ break;
133
+ }
134
+ const raw = char + chars.join('');
135
+ const inQuoteEnd = quoteModeStack.at(-1);
136
+ if (inQuoteEnd && raw.startsWith(inQuoteEnd.end)) {
137
+ quoteModeStack.pop();
138
+ attrValue += inQuoteEnd.end;
139
+ chars.splice(0, inQuoteEnd.end.length - 1);
140
+ break;
141
+ }
142
+ const inQuoteStart = quoteInValueChars.find(quote => raw.startsWith(quote.start));
143
+ if (inQuoteStart) {
144
+ quoteModeStack.push(inQuoteStart);
145
+ attrValue += inQuoteStart.start;
146
+ chars.splice(0, inQuoteStart.start.length - 1);
147
+ break;
148
+ }
149
+ attrValue += char;
150
+ break;
151
+ }
152
+ }
153
+ }
154
+ if (state === AttrState.Value && quoteTypeIndex !== -1) {
155
+ throw new SyntaxError(`Unclosed attribute value: ${raw}`);
156
+ }
157
+ const leftover = chars.join('');
158
+ return {
159
+ spacesBeforeAttrName,
160
+ attrName,
54
161
  spacesBeforeEqual,
55
162
  equal,
56
163
  spacesAfterEqual,
57
- startQuote,
58
- value,
59
- endQuote,
60
- isDuplicatable: false,
61
- nodeName: name.raw,
62
- parentNode: null,
63
- prevNode: null,
64
- nextNode: null,
65
- isFragment: false,
66
- isGhost: false,
164
+ quoteStart,
165
+ attrValue,
166
+ quoteEnd,
167
+ leftover,
67
168
  };
68
- if (parsed.leftover) {
69
- return {
70
- ...result,
71
- __leftover: parsed.leftover,
72
- };
73
- }
74
- return result;
75
169
  }
package/lib/const.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare const reSplitterTag: RegExp;
11
11
  * - U+0009 CHARACTER TABULATION (tab) => `\t`
12
12
  * - U+000A LINE FEED (LF) => `\n`
13
13
  * - U+000C FORM FEED (FF) => `\f`
14
+ * - U+000D CARRIAGE RETURN (CR) => `\r`
14
15
  * - U+0020 SPACE => ` `
15
16
  */
16
- export declare const defaultSpaces: readonly ["\t", "\n", "\f", " "];
17
+ export declare const defaultSpaces: readonly ["\t", "\n", "\f", "\r", " "];
package/lib/const.js CHANGED
@@ -100,6 +100,7 @@ export const reSplitterTag = /<[^>]+>/g;
100
100
  * - U+0009 CHARACTER TABULATION (tab) => `\t`
101
101
  * - U+000A LINE FEED (LF) => `\n`
102
102
  * - U+000C FORM FEED (FF) => `\f`
103
+ * - U+000D CARRIAGE RETURN (CR) => `\r`
103
104
  * - U+0020 SPACE => ` `
104
105
  */
105
- export const defaultSpaces = ['\t', '\n', '\f', ' '];
106
+ export const defaultSpaces = ['\t', '\n', '\f', '\r', ' '];
package/lib/debugger.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import type { MLASTAttr, MLASTNode } from '@markuplint/ml-ast';
2
- export declare function nodeListToDebugMaps(nodeList: MLASTNode[], withAttr?: boolean): string[];
3
- export declare function attributesToDebugMaps(attributes: MLASTAttr[]): string[][];
2
+ export declare function nodeListToDebugMaps(nodeList: readonly (MLASTNode | null)[], withAttr?: boolean): string[];
3
+ export declare function attributesToDebugMaps(attributes: readonly MLASTAttr[]): string[][];
4
+ export declare function nodeTreeDebugView(nodeTree: readonly MLASTNode[]): (string | undefined)[];
package/lib/debugger.js CHANGED
@@ -1,46 +1,62 @@
1
- export function nodeListToDebugMaps(
2
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
3
- nodeList, withAttr = false) {
1
+ export function nodeListToDebugMaps(nodeList, withAttr = false) {
4
2
  return nodeList.flatMap(n => {
5
3
  const r = [];
6
- if (n.isGhost) {
7
- r.push(`[N/A]>[N/A](N/A)${n.nodeName}: ${visibleWhiteSpace(n.raw)}`);
8
- }
9
- else {
10
- r.push(tokenDebug(n));
11
- if (withAttr && 'attributes' in n) {
12
- r.push(...attributesToDebugMaps(n.attributes).flat());
13
- }
4
+ r.push(tokenDebug(n));
5
+ if (withAttr && n && n.type === 'starttag') {
6
+ r.push(...attributesToDebugMaps(n.attributes).flat());
14
7
  }
15
8
  return r;
16
9
  });
17
10
  }
18
- export function attributesToDebugMaps(
19
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
20
- attributes) {
11
+ export function attributesToDebugMaps(attributes) {
21
12
  return attributes.map(n => {
22
13
  const r = [
23
14
  tokenDebug({
24
15
  ...n,
25
- name: n.type === 'html-attr' ? n.name.raw : n.raw,
16
+ name: n.type === 'attr' ? n.name.raw : n.raw,
26
17
  }),
27
18
  ];
28
- if (n.type === 'html-attr') {
29
- r.push(` ${tokenDebug(n.spacesBeforeName, 'bN')}`, ` ${tokenDebug(n.name, 'name')}`, ` ${tokenDebug(n.spacesBeforeEqual, 'bE')}`, ` ${tokenDebug(n.equal, 'equal')}`, ` ${tokenDebug(n.spacesAfterEqual, 'aE')}`, ` ${tokenDebug(n.startQuote, 'sQ')}`, ` ${tokenDebug(n.value, 'value')}`, ` ${tokenDebug(n.endQuote, 'eQ')}`, ` isDirective: ${!!n.isDirective}`, ` isDynamicValue: ${!!n.isDynamicValue}`);
19
+ if (n.type === 'spread') {
20
+ r.push(` #spread: ${visibleWhiteSpace(n.raw)}`);
21
+ return r;
30
22
  }
23
+ r.push(` ${tokenDebug(n.spacesBeforeName, 'bN')}`, ` ${tokenDebug(n.name, 'name')}`, ` ${tokenDebug(n.spacesBeforeEqual, 'bE')}`, ` ${tokenDebug(n.equal, 'equal')}`, ` ${tokenDebug(n.spacesAfterEqual, 'aE')}`, ` ${tokenDebug(n.startQuote, 'sQ')}`, ` ${tokenDebug(n.value, 'value')}`, ` ${tokenDebug(n.endQuote, 'eQ')}`, ` isDirective: ${!!n.isDirective}`, ` isDynamicValue: ${!!n.isDynamicValue}`);
31
24
  if (n.potentialName != null) {
32
25
  r.push(` potentialName: ${visibleWhiteSpace(n.potentialName)}`);
33
26
  }
34
- if (n.type === 'html-attr' && n.candidate) {
27
+ if (n.candidate) {
35
28
  r.push(` candidate: ${visibleWhiteSpace(n.candidate)}`);
36
29
  }
37
30
  return r;
38
31
  });
39
32
  }
33
+ export function nodeTreeDebugView(nodeTree) {
34
+ return nodeTree
35
+ .map((n, i) => {
36
+ const lines = [];
37
+ if (n.type === 'attr' || n.type === 'spread') {
38
+ return;
39
+ }
40
+ lines.push(`${i.toString().padStart(3, '0')}: [${n.uuid.slice(0, 8)}] ${' '.repeat(Math.max(n.depth, 0))}${n.type === 'endtag' ? '/' : ''}${n.nodeName}(${n.uuid.slice(0, 8)})${n.type === 'starttag' && n.isGhost ? '[👻]' : ''}${n.type === 'starttag'
41
+ ? ` => ${n.pairNode ? `/${n.pairNode.nodeName}(${n.pairNode.uuid.slice(0, 8)})` : '💀'}`
42
+ : ''}`);
43
+ if (n.type === 'starttag' || n.type === 'psblock') {
44
+ for (const c of n.childNodes ?? []) {
45
+ lines.push(`${' '.repeat(15)} ${' '.repeat(Math.max(n.depth, 0))}┗━ ${c.type === 'endtag' ? '/' : ''}${c.nodeName}(${c.uuid.slice(0, 8)})`);
46
+ }
47
+ }
48
+ return lines;
49
+ })
50
+ .filter(Boolean)
51
+ .flat();
52
+ }
40
53
  function tokenDebug(n, type = '') {
54
+ if (!n) {
55
+ return 'NULL';
56
+ }
41
57
  return `[${n.startLine}:${n.startCol}]>[${n.endLine}:${n.endCol}](${n.startOffset},${n.endOffset})${
42
58
  // @ts-ignore
43
- n.potentialName ?? n.nodeName ?? n.name ?? n.type ?? type}: ${visibleWhiteSpace(n.raw)}`;
59
+ n.potentialName ?? n.nodeName ?? n.name ?? n.type ?? type}${'isGhost' in n && n.isGhost ? '(👻)' : ''}${'isBogus' in n && n.isBogus ? '(👿)' : ''}: ${visibleWhiteSpace(n.raw)}`;
44
60
  }
45
61
  function visibleWhiteSpace(chars) {
46
62
  return chars.replaceAll('\n', '⏎').replaceAll('\t', '→').replaceAll(/\s/g, '␣');
package/lib/enums.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ export declare enum TagState {
2
+ BeforeOpenTag = 0,
3
+ FirstCharOfTagName = 1,
4
+ TagName = 2,
5
+ Attrs = 3,
6
+ AfterAttrs = 4,
7
+ AfterOpenTag = 5
8
+ }
9
+ export declare enum AttrState {
10
+ BeforeName = 0,
11
+ Name = 1,
12
+ Equal = 2,
13
+ BeforeValue = 3,
14
+ Value = 4,
15
+ AfterValue = 5
16
+ }
package/lib/enums.js ADDED
@@ -0,0 +1,18 @@
1
+ export var TagState;
2
+ (function (TagState) {
3
+ TagState[TagState["BeforeOpenTag"] = 0] = "BeforeOpenTag";
4
+ TagState[TagState["FirstCharOfTagName"] = 1] = "FirstCharOfTagName";
5
+ TagState[TagState["TagName"] = 2] = "TagName";
6
+ TagState[TagState["Attrs"] = 3] = "Attrs";
7
+ TagState[TagState["AfterAttrs"] = 4] = "AfterAttrs";
8
+ TagState[TagState["AfterOpenTag"] = 5] = "AfterOpenTag";
9
+ })(TagState || (TagState = {}));
10
+ export var AttrState;
11
+ (function (AttrState) {
12
+ AttrState[AttrState["BeforeName"] = 0] = "BeforeName";
13
+ AttrState[AttrState["Name"] = 1] = "Name";
14
+ AttrState[AttrState["Equal"] = 2] = "Equal";
15
+ AttrState[AttrState["BeforeValue"] = 3] = "BeforeValue";
16
+ AttrState[AttrState["Value"] = 4] = "Value";
17
+ AttrState[AttrState["AfterValue"] = 5] = "AfterValue";
18
+ })(AttrState || (AttrState = {}));
@@ -1,13 +1,4 @@
1
- export declare function getLine(html: string, startOffset: number): number;
2
- export declare function getCol(html: string, startOffset: number): number;
3
- export declare function getEndLine(html: string, line: number): number;
4
- export declare function getEndCol(html: string, col: number): number;
5
- export declare function sliceFragment(rawHtml: string, start: number, end: number): {
6
- startOffset: number;
7
- endOffset: number;
8
- startLine: number;
9
- endLine: number;
10
- startCol: number;
11
- endCol: number;
12
- raw: string;
13
- };
1
+ export declare function getLine(rawCodeFragment: string, startOffset: number): number;
2
+ export declare function getCol(rawCodeFragment: string, startOffset: number): number;
3
+ export declare function getEndLine(rawCodeFragment: string, startLine: number): number;
4
+ export declare function getEndCol(rawCodeFragment: string, startCol: number): number;
@@ -1,28 +1,17 @@
1
- export function getLine(html, startOffset) {
2
- return html.slice(0, startOffset).split(/\n/).length;
1
+ const LINE_BREAK = '\n';
2
+ export function getLine(rawCodeFragment, startOffset) {
3
+ return rawCodeFragment.slice(0, startOffset).split(LINE_BREAK).length;
3
4
  }
4
- export function getCol(html, startOffset) {
5
- const lines = html.slice(0, startOffset).split(/\n/);
5
+ export function getCol(rawCodeFragment, startOffset) {
6
+ const lines = rawCodeFragment.slice(0, startOffset).split(LINE_BREAK);
6
7
  return (lines.at(-1) ?? '').length + 1;
7
8
  }
8
- export function getEndLine(html, line) {
9
- return html.split(/\r?\n/).length - 1 + line;
9
+ export function getEndLine(rawCodeFragment, startLine) {
10
+ return rawCodeFragment.split(LINE_BREAK).length - 1 + startLine;
10
11
  }
11
- export function getEndCol(html, col) {
12
- const lines = html.split(/\r?\n/);
12
+ export function getEndCol(rawCodeFragment, startCol) {
13
+ const lines = rawCodeFragment.split(LINE_BREAK);
13
14
  const lineCount = lines.length;
14
15
  const lastLine = lines.pop();
15
- return lineCount > 1 ? lastLine.length + 1 : col + html.length;
16
- }
17
- export function sliceFragment(rawHtml, start, end) {
18
- const raw = rawHtml.slice(start, end);
19
- return {
20
- startOffset: start,
21
- endOffset: end,
22
- startLine: getLine(rawHtml, start),
23
- endLine: getLine(rawHtml, end),
24
- startCol: getCol(rawHtml, start),
25
- endCol: getCol(rawHtml, end),
26
- raw,
27
- };
16
+ return lineCount > 1 ? lastLine.length + 1 : startCol + rawCodeFragment.length;
28
17
  }
@@ -1,4 +1,5 @@
1
+ import type { Parser } from './parser.js';
1
2
  import type { IgnoreBlock, IgnoreTag } from './types.js';
2
- import type { MLASTNode } from '@markuplint/ml-ast';
3
+ import type { MLASTNodeTreeItem } from '@markuplint/ml-ast';
3
4
  export declare function ignoreBlock(source: string, tags: readonly IgnoreTag[], maskChar?: string): IgnoreBlock;
4
- export declare function restoreNode(nodeList: MLASTNode[], ignoreBlock: IgnoreBlock): MLASTNode[];
5
+ export declare function restoreNode(parser: Parser<any, any>, nodeList: readonly MLASTNodeTreeItem[], ignoreBlock: IgnoreBlock, throwErrorWhenTagHasUnresolved?: boolean): MLASTNodeTreeItem[];