@markuplint/html-parser 3.2.0 → 3.3.1
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/lib/create-tree.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import type { MLASTNode } from '@markuplint/ml-ast';
|
|
2
|
-
export declare function createTree(
|
|
2
|
+
export declare function createTree(
|
|
3
|
+
rawCode: string,
|
|
4
|
+
isFragment: boolean,
|
|
5
|
+
offsetOffset: number,
|
|
6
|
+
offsetLine: number,
|
|
7
|
+
offsetColumn: number,
|
|
8
|
+
): MLASTNode[];
|
package/lib/create-tree.js
CHANGED
|
@@ -5,7 +5,10 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const parser_utils_1 = require("@markuplint/parser-utils");
|
|
6
6
|
const parse5_1 = require("parse5");
|
|
7
7
|
const parse_raw_tag_1 = tslib_1.__importDefault(require("./parse-raw-tag"));
|
|
8
|
-
const P5_OPTIONS = {
|
|
8
|
+
const P5_OPTIONS = {
|
|
9
|
+
scriptingEnabled: false,
|
|
10
|
+
sourceCodeLocationInfo: true,
|
|
11
|
+
};
|
|
9
12
|
function createTree(rawCode, isFragment, offsetOffset, offsetLine, offsetColumn) {
|
|
10
13
|
const doc = isFragment
|
|
11
14
|
? (0, parse5_1.parseFragment)(rawCode, P5_OPTIONS)
|
|
@@ -231,28 +234,8 @@ function nodeize(originNode, prevNode, parentNode, rawHtml, offsetOffset, offset
|
|
|
231
234
|
* getChildNodes
|
|
232
235
|
*
|
|
233
236
|
* - If node has "content" property then parse as document fragment.
|
|
234
|
-
* - If node is <noscript> then that childNodes is a TextNode. But parse as document fragment it for disabled script.
|
|
235
237
|
*/
|
|
236
238
|
function getChildNodes(rootNode) {
|
|
237
|
-
if (rootNode.nodeName === 'noscript') {
|
|
238
|
-
const textNode = rootNode.childNodes[0];
|
|
239
|
-
if (!textNode || textNode.nodeName !== '#text') {
|
|
240
|
-
return [];
|
|
241
|
-
}
|
|
242
|
-
// @ts-ignore
|
|
243
|
-
const html = textNode.value;
|
|
244
|
-
// @ts-ignore
|
|
245
|
-
const { startOffset, startLine, startCol } = textNode.sourceCodeLocation;
|
|
246
|
-
const breakCount = startLine - 1;
|
|
247
|
-
const indentWidth = startCol - 1;
|
|
248
|
-
const offsetSpaces = ' '.repeat(startOffset - Math.max(breakCount, 0) - Math.max(indentWidth, 0)) +
|
|
249
|
-
'\n'.repeat(breakCount) +
|
|
250
|
-
' '.repeat(indentWidth);
|
|
251
|
-
const fragment = (0, parse5_1.parseFragment)(`${offsetSpaces}${html}`, P5_OPTIONS);
|
|
252
|
-
const childNodes = fragment.childNodes.slice(offsetSpaces ? 1 : 0);
|
|
253
|
-
// const childNodes = ('childNodes' in _childNodes && _childNodes.childNodes) || [];
|
|
254
|
-
return childNodes;
|
|
255
|
-
}
|
|
256
239
|
return rootNode.content ? rootNode.content.childNodes : rootNode.childNodes || [];
|
|
257
240
|
}
|
|
258
241
|
function hasLocation(node) {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { MLASTNode } from '@markuplint/ml-ast';
|
|
2
2
|
export declare function isStartsHeadTagOrBodyTag(rawCode: string): boolean;
|
|
3
3
|
export declare function optimizeStartsHeadTagOrBodyTagSetup(rawCode: string): {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
code: string;
|
|
5
|
+
heads: string[];
|
|
6
|
+
bodies: string[];
|
|
7
7
|
};
|
|
8
|
-
export declare function optimizeStartsHeadTagOrBodyTagResume(
|
|
8
|
+
export declare function optimizeStartsHeadTagOrBodyTagResume(
|
|
9
|
+
nodeList: MLASTNode[],
|
|
10
|
+
replacements: ReturnType<typeof optimizeStartsHeadTagOrBodyTagSetup>,
|
|
11
|
+
): void;
|
package/lib/parse-raw-tag.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { MLASTAttr, MLToken } from '@markuplint/ml-ast';
|
|
2
2
|
type TagTokens = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
tagName: string;
|
|
4
|
+
attrs: MLASTAttr[];
|
|
5
|
+
selfClosingSolidus: MLToken;
|
|
6
|
+
endSpace: MLToken;
|
|
7
7
|
};
|
|
8
|
-
export default function parseRawTag(
|
|
8
|
+
export default function parseRawTag(
|
|
9
|
+
raw: string,
|
|
10
|
+
startLine: number,
|
|
11
|
+
startCol: number,
|
|
12
|
+
startOffset: number,
|
|
13
|
+
offsetOffset?: number,
|
|
14
|
+
offsetLine?: number,
|
|
15
|
+
offsetColumn?: number,
|
|
16
|
+
): TagTokens;
|
|
9
17
|
export {};
|
package/lib/tag-splitter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export interface N {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
type: 'text' | 'starttag' | 'endtag' | 'comment' | 'boguscomment';
|
|
3
|
+
raw: string;
|
|
4
|
+
line: number;
|
|
5
|
+
col: number;
|
|
6
6
|
}
|
|
7
7
|
export default function tagSplitter(raw: string, line: number, col: number): N[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/html-parser",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "HTML parser for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -11,16 +11,19 @@
|
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
|
+
"typedoc": {
|
|
15
|
+
"entryPoint": "./src/index.ts"
|
|
16
|
+
},
|
|
14
17
|
"scripts": {
|
|
15
18
|
"build": "tsc",
|
|
16
19
|
"dev": "tsc --build --watch",
|
|
17
20
|
"clean": "tsc --build --clean"
|
|
18
21
|
},
|
|
19
22
|
"dependencies": {
|
|
20
|
-
"@markuplint/ml-ast": "3.0.0
|
|
21
|
-
"@markuplint/parser-utils": "3.
|
|
23
|
+
"@markuplint/ml-ast": "3.0.0",
|
|
24
|
+
"@markuplint/parser-utils": "3.3.0",
|
|
22
25
|
"parse5": "7.1.2",
|
|
23
26
|
"tslib": "^2.4.1"
|
|
24
27
|
},
|
|
25
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "f19e7de726cf01d53342bc5513c30da75d28da63"
|
|
26
29
|
}
|