@markuplint/html-parser
Advanced tools
Comparing version 3.0.0-dev.186 to 3.0.0-dev.290
@@ -1,9 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const parser_utils_1 = require("@markuplint/parser-utils"); | ||
import { tokenizer, uuid } from '@markuplint/parser-utils'; | ||
const reAttrsInStartTag = | ||
// eslint-disable-next-line no-control-regex | ||
/(\s*)([^\x00-\x1f\x7f-\x9f "'>/=]+)(?:(\s*)(=)(\s*)(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s]*)))?/; | ||
function attrTokenizer(raw, line, col, startOffset) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
export default function attrTokenizer(raw, line, col, startOffset) { | ||
const attrMatchedMap = raw.match(reAttrsInStartTag); | ||
@@ -13,49 +10,49 @@ if (!attrMatchedMap) { | ||
} | ||
const spacesBeforeAttrString = (_a = attrMatchedMap[1]) !== null && _a !== void 0 ? _a : ''; | ||
const nameChars = (_b = attrMatchedMap[2]) !== null && _b !== void 0 ? _b : ''; | ||
const spacesBeforeEqualChars = (_c = attrMatchedMap[3]) !== null && _c !== void 0 ? _c : ''; | ||
const equalChars = (_d = attrMatchedMap[4]) !== null && _d !== void 0 ? _d : null; | ||
const spacesAfterEqualChars = (_e = attrMatchedMap[5]) !== null && _e !== void 0 ? _e : ''; | ||
const spacesBeforeAttrString = attrMatchedMap[1] ?? ''; | ||
const nameChars = attrMatchedMap[2] ?? ''; | ||
const spacesBeforeEqualChars = attrMatchedMap[3] ?? ''; | ||
const equalChars = attrMatchedMap[4] ?? null; | ||
const spacesAfterEqualChars = attrMatchedMap[5] ?? ''; | ||
const quoteChars = attrMatchedMap[6] != null ? '"' : attrMatchedMap[7] != null ? "'" : null; | ||
const valueChars = (_h = (_g = (_f = attrMatchedMap[6]) !== null && _f !== void 0 ? _f : attrMatchedMap[7]) !== null && _g !== void 0 ? _g : attrMatchedMap[8]) !== null && _h !== void 0 ? _h : (quoteChars ? '' : null); | ||
const valueChars = attrMatchedMap[6] ?? attrMatchedMap[7] ?? attrMatchedMap[8] ?? (quoteChars ? '' : null); | ||
let offset = startOffset; | ||
const spacesBeforeName = (0, parser_utils_1.tokenizer)(spacesBeforeAttrString, line, col, offset); | ||
const spacesBeforeName = tokenizer(spacesBeforeAttrString, line, col, offset); | ||
line = spacesBeforeName.endLine; | ||
col = spacesBeforeName.endCol; | ||
offset = spacesBeforeName.endOffset; | ||
const name = (0, parser_utils_1.tokenizer)(nameChars, line, col, offset); | ||
const name = tokenizer(nameChars, line, col, offset); | ||
line = name.endLine; | ||
col = name.endCol; | ||
offset = name.endOffset; | ||
const spacesBeforeEqual = (0, parser_utils_1.tokenizer)(spacesBeforeEqualChars, line, col, offset); | ||
const spacesBeforeEqual = tokenizer(spacesBeforeEqualChars, line, col, offset); | ||
line = spacesBeforeEqual.endLine; | ||
col = spacesBeforeEqual.endCol; | ||
offset = spacesBeforeEqual.endOffset; | ||
const equal = (0, parser_utils_1.tokenizer)(equalChars, line, col, offset); | ||
const equal = tokenizer(equalChars, line, col, offset); | ||
line = equal.endLine; | ||
col = equal.endCol; | ||
offset = equal.endOffset; | ||
const spacesAfterEqual = (0, parser_utils_1.tokenizer)(spacesAfterEqualChars, line, col, offset); | ||
const spacesAfterEqual = tokenizer(spacesAfterEqualChars, line, col, offset); | ||
line = spacesAfterEqual.endLine; | ||
col = spacesAfterEqual.endCol; | ||
offset = spacesAfterEqual.endOffset; | ||
const startQuote = (0, parser_utils_1.tokenizer)(quoteChars, line, col, offset); | ||
const startQuote = tokenizer(quoteChars, line, col, offset); | ||
line = startQuote.endLine; | ||
col = startQuote.endCol; | ||
offset = startQuote.endOffset; | ||
const value = (0, parser_utils_1.tokenizer)(valueChars, line, col, offset); | ||
const value = tokenizer(valueChars, line, col, offset); | ||
line = value.endLine; | ||
col = value.endCol; | ||
offset = value.endOffset; | ||
const endQuote = (0, parser_utils_1.tokenizer)(quoteChars, line, col, offset); | ||
const attrToken = (0, parser_utils_1.tokenizer)(nameChars + | ||
const endQuote = tokenizer(quoteChars, line, col, offset); | ||
const attrToken = tokenizer(nameChars + | ||
spacesBeforeEqualChars + | ||
(equalChars !== null && equalChars !== void 0 ? equalChars : '') + | ||
(equalChars ?? '') + | ||
spacesAfterEqualChars + | ||
(quoteChars !== null && quoteChars !== void 0 ? quoteChars : '') + | ||
(valueChars !== null && valueChars !== void 0 ? valueChars : '') + | ||
(quoteChars !== null && quoteChars !== void 0 ? quoteChars : ''), name.startLine, name.startCol, name.startOffset); | ||
(quoteChars ?? '') + | ||
(valueChars ?? '') + | ||
(quoteChars ?? ''), name.startLine, name.startCol, name.startOffset); | ||
return { | ||
type: 'html-attr', | ||
uuid: (0, parser_utils_1.uuid)(), | ||
uuid: uuid(), | ||
raw: attrToken.raw, | ||
@@ -85,2 +82,1 @@ startOffset: attrToken.startOffset, | ||
} | ||
exports.default = attrTokenizer; |
import type { MLASTNode } from '@markuplint/ml-ast'; | ||
export declare function createTree( | ||
rawCode: string, | ||
isFragment: boolean, | ||
offsetOffset: number, | ||
offsetLine: number, | ||
offsetColumn: number, | ||
): MLASTNode[]; | ||
export declare function createTree(rawCode: string, isFragment: boolean, offsetOffset: number, offsetLine: number, offsetColumn: number): MLASTNode[]; |
@@ -1,8 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createTree = void 0; | ||
const tslib_1 = require("tslib"); | ||
const parser_utils_1 = require("@markuplint/parser-utils"); | ||
const parse5_1 = require("parse5"); | ||
const parse_raw_tag_1 = tslib_1.__importDefault(require("./parse-raw-tag")); | ||
// @ts-nocheck TODO: Parse5(https://github.com/inikulin/parse5) supports to expose type definitions as submodules. | ||
import { detectElementType, getEndCol, getEndLine, sliceFragment, uuid } from '@markuplint/parser-utils'; | ||
import { parse, parseFragment } from 'parse5'; | ||
import parseRawTag from './parse-raw-tag.js'; | ||
const P5_OPTIONS = { | ||
@@ -12,7 +9,6 @@ scriptingEnabled: false, | ||
}; | ||
function createTree(rawCode, isFragment, offsetOffset, offsetLine, offsetColumn) { | ||
const doc = isFragment ? (0, parse5_1.parseFragment)(rawCode, P5_OPTIONS) : (0, parse5_1.parse)(rawCode, P5_OPTIONS); | ||
export function createTree(rawCode, isFragment, offsetOffset, offsetLine, offsetColumn) { | ||
const doc = isFragment ? parseFragment(rawCode, P5_OPTIONS) : parse(rawCode, P5_OPTIONS); | ||
return createTreeRecursive(doc, null, rawCode, offsetOffset, offsetLine, offsetColumn); | ||
} | ||
exports.createTree = createTree; | ||
function createTreeRecursive(rootNode, | ||
@@ -45,7 +41,6 @@ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
parentNode, rawHtml, offsetOffset, offsetLine, offsetColumn) { | ||
var _a, _b, _c; | ||
const nextNode = null; | ||
const location = getLocation(originNode); | ||
if (!location) { | ||
const prevToken = prevNode !== null && prevNode !== void 0 ? prevNode : parentNode; | ||
const prevToken = prevNode ?? parentNode; | ||
const startOffset = prevToken ? prevToken.endOffset : 0; | ||
@@ -58,3 +53,3 @@ const endOffset = prevToken ? prevToken.endOffset : 0; | ||
const node = { | ||
uuid: (0, parser_utils_1.uuid)(), | ||
uuid: uuid(), | ||
raw: '', | ||
@@ -86,14 +81,14 @@ startOffset: startOffset + offsetOffset, | ||
const { startOffset, endOffset, startLine, endLine, startCol, endCol } = location; | ||
const raw = rawHtml.slice(startOffset, endOffset !== null && endOffset !== void 0 ? endOffset : startOffset); | ||
const raw = rawHtml.slice(startOffset, endOffset ?? startOffset); | ||
switch (originNode.nodeName) { | ||
case '#documentType': { | ||
return { | ||
uuid: (0, parser_utils_1.uuid)(), | ||
uuid: uuid(), | ||
raw, | ||
// @ts-ignore | ||
name: (_a = originNode.name) !== null && _a !== void 0 ? _a : '', | ||
name: originNode.name ?? '', | ||
// @ts-ignore | ||
publicId: (_b = originNode.publicId) !== null && _b !== void 0 ? _b : '', | ||
publicId: originNode.publicId ?? '', | ||
// @ts-ignore | ||
systemId: (_c = originNode.systemId) !== null && _c !== void 0 ? _c : '', | ||
systemId: originNode.systemId ?? '', | ||
startOffset: startOffset + offsetOffset, | ||
@@ -117,3 +112,3 @@ endOffset: endOffset + offsetOffset, | ||
const node = { | ||
uuid: (0, parser_utils_1.uuid)(), | ||
uuid: uuid(), | ||
raw, | ||
@@ -138,3 +133,3 @@ startOffset: startOffset + offsetOffset, | ||
return { | ||
uuid: (0, parser_utils_1.uuid)(), | ||
uuid: uuid(), | ||
raw, | ||
@@ -160,4 +155,4 @@ startOffset: startOffset + offsetOffset, | ||
? rawHtml.slice(tagLoc.startOffset, tagLoc.endOffset) | ||
: rawHtml.slice(startOffset, endOffset !== null && endOffset !== void 0 ? endOffset : startOffset); | ||
const tagTokens = (0, parse_raw_tag_1.default)(startTagRaw, startLine, startCol, startOffset, offsetOffset, offsetLine, offsetColumn); | ||
: rawHtml.slice(startOffset, endOffset ?? startOffset); | ||
const tagTokens = parseRawTag(startTagRaw, startLine, startCol, startOffset, offsetOffset, offsetLine, offsetColumn); | ||
const tagName = tagTokens.tagName; | ||
@@ -177,3 +172,3 @@ let endTag = null; | ||
if (endTag) { | ||
endTagLoc = (0, parser_utils_1.sliceFragment)(rawHtml, location.endOffset, location.endOffset + endTag.length); | ||
endTagLoc = sliceFragment(rawHtml, location.endOffset, location.endOffset + endTag.length); | ||
} | ||
@@ -184,6 +179,6 @@ } | ||
const endTagRaw = rawHtml.slice(startOffset, endOffset); | ||
const endTagTokens = (0, parse_raw_tag_1.default)(endTagRaw, startLine, startCol, startOffset, offsetOffset, offsetLine, offsetColumn); | ||
const endTagTokens = parseRawTag(endTagRaw, startLine, startCol, startOffset, offsetOffset, offsetLine, offsetColumn); | ||
const endTagName = endTagTokens.tagName; | ||
endTag = { | ||
uuid: (0, parser_utils_1.uuid)(), | ||
uuid: uuid(), | ||
raw: endTagRaw, | ||
@@ -211,6 +206,6 @@ startOffset: startOffset + offsetOffset, | ||
const _endOffset = startOffset + startTagRaw.length; | ||
const _endLine = (0, parser_utils_1.getEndLine)(startTagRaw, startLine); | ||
const _endCol = (0, parser_utils_1.getEndCol)(startTagRaw, startCol); | ||
const _endLine = getEndLine(startTagRaw, startLine); | ||
const _endCol = getEndCol(startTagRaw, startCol); | ||
const startTag = { | ||
uuid: (0, parser_utils_1.uuid)(), | ||
uuid: uuid(), | ||
raw: startTagRaw, | ||
@@ -226,3 +221,3 @@ startOffset: startOffset + offsetOffset, | ||
namespace: getNamespace(originNode), | ||
elementType: (0, parser_utils_1.detectElementType)(tagName), | ||
elementType: detectElementType(tagName), | ||
attributes: tagTokens.attrs, | ||
@@ -255,4 +250,3 @@ hasSpreadAttr: false, | ||
function getChildNodes(rootNode) { | ||
var _a; | ||
return rootNode.content ? rootNode.content.childNodes : (_a = rootNode.childNodes) !== null && _a !== void 0 ? _a : []; | ||
return rootNode.content ? rootNode.content.childNodes : rootNode.childNodes ?? []; | ||
} | ||
@@ -259,0 +253,0 @@ function hasLocation(node) { |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getNamespace = void 0; | ||
const parse5_1 = require("parse5"); | ||
import { parse, parseFragment } from 'parse5'; | ||
const DEFAULT_NAMESPACE = 'http://www.w3.org/1999/xhtml'; | ||
function getNamespace(tagName, parentNamespace = DEFAULT_NAMESPACE) { | ||
export function getNamespace(tagName, parentNamespace = DEFAULT_NAMESPACE) { | ||
switch (parentNamespace) { | ||
@@ -12,3 +9,3 @@ case 'http://www.w3.org/2000/svg': | ||
const tag = `<${parent}><${tagName}></${parent}>`; | ||
const frag = (0, parse5_1.parseFragment)(tag); | ||
const frag = parseFragment(tag); | ||
const node = frag.childNodes[0]; | ||
@@ -25,6 +22,6 @@ if (!node) { | ||
const tag = `<${tagName}>`; | ||
const frag = (0, parse5_1.parseFragment)(tag); | ||
const frag = parseFragment(tag); | ||
let node = frag.childNodes[0]; | ||
if (!node) { | ||
const doc = (0, parse5_1.parse)(tag); | ||
const doc = parse(tag); | ||
node = doc.childNodes[0]; | ||
@@ -37,2 +34,1 @@ } | ||
} | ||
exports.getNamespace = getNamespace; |
@@ -1,6 +0,6 @@ | ||
export { default as attrTokenizer } from './attr-tokenizer'; | ||
export { default as isDocumentFragment } from './is-document-fragment'; | ||
export { default as parseRawTag } from './parse-raw-tag'; | ||
export { getNamespace } from './get-namespace'; | ||
export { parse } from './parse'; | ||
export { createTree } from './create-tree'; | ||
export { default as attrTokenizer } from './attr-tokenizer.js'; | ||
export { default as isDocumentFragment } from './is-document-fragment.js'; | ||
export { default as parseRawTag } from './parse-raw-tag.js'; | ||
export { getNamespace } from './get-namespace.js'; | ||
export { parse } from './parse.js'; | ||
export { createTree } from './create-tree.js'; |
@@ -1,18 +0,6 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createTree = exports.parse = exports.getNamespace = exports.parseRawTag = exports.isDocumentFragment = exports.attrTokenizer = void 0; | ||
var attr_tokenizer_1 = require("./attr-tokenizer"); | ||
Object.defineProperty(exports, "attrTokenizer", { enumerable: true, get: function () { return __importDefault(attr_tokenizer_1).default; } }); | ||
var is_document_fragment_1 = require("./is-document-fragment"); | ||
Object.defineProperty(exports, "isDocumentFragment", { enumerable: true, get: function () { return __importDefault(is_document_fragment_1).default; } }); | ||
var parse_raw_tag_1 = require("./parse-raw-tag"); | ||
Object.defineProperty(exports, "parseRawTag", { enumerable: true, get: function () { return __importDefault(parse_raw_tag_1).default; } }); | ||
var get_namespace_1 = require("./get-namespace"); | ||
Object.defineProperty(exports, "getNamespace", { enumerable: true, get: function () { return get_namespace_1.getNamespace; } }); | ||
var parse_1 = require("./parse"); | ||
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.parse; } }); | ||
var create_tree_1 = require("./create-tree"); | ||
Object.defineProperty(exports, "createTree", { enumerable: true, get: function () { return create_tree_1.createTree; } }); | ||
export { default as attrTokenizer } from './attr-tokenizer.js'; | ||
export { default as isDocumentFragment } from './is-document-fragment.js'; | ||
export { default as parseRawTag } from './parse-raw-tag.js'; | ||
export { getNamespace } from './get-namespace.js'; | ||
export { parse } from './parse.js'; | ||
export { createTree } from './create-tree.js'; |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function isDocumentFragment(html) { | ||
export default function isDocumentFragment(html) { | ||
return !/^\s*(<!doctype html(?:\s*.+)?>|<html(?:\s|>))/im.test(html); | ||
} | ||
exports.default = isDocumentFragment; |
import type { MLASTNode } from '@markuplint/ml-ast'; | ||
export declare function isStartsHeadTagOrBodyTag(rawCode: string): boolean; | ||
export declare function optimizeStartsHeadTagOrBodyTagSetup(rawCode: string): { | ||
code: string; | ||
heads: string[]; | ||
bodies: string[]; | ||
code: string; | ||
heads: string[]; | ||
bodies: string[]; | ||
}; | ||
export declare function optimizeStartsHeadTagOrBodyTagResume( | ||
nodeList: MLASTNode[], | ||
replacements: ReturnType<typeof optimizeStartsHeadTagOrBodyTagSetup>, | ||
): void; | ||
export declare function optimizeStartsHeadTagOrBodyTagResume(nodeList: MLASTNode[], replacements: ReturnType<typeof optimizeStartsHeadTagOrBodyTagSetup>): void; |
@@ -1,10 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.optimizeStartsHeadTagOrBodyTagResume = exports.optimizeStartsHeadTagOrBodyTagSetup = exports.isStartsHeadTagOrBodyTag = void 0; | ||
const UNDUPLICATED_CHAR = '\uFFFD'; | ||
function isStartsHeadTagOrBodyTag(rawCode) { | ||
export function isStartsHeadTagOrBodyTag(rawCode) { | ||
return /^\s*<(?:head|body)>/i.test(rawCode); | ||
} | ||
exports.isStartsHeadTagOrBodyTag = isStartsHeadTagOrBodyTag; | ||
function optimizeStartsHeadTagOrBodyTagSetup(rawCode) { | ||
export function optimizeStartsHeadTagOrBodyTagSetup(rawCode) { | ||
const heads = []; | ||
@@ -36,4 +32,3 @@ const bodies = []; | ||
} | ||
exports.optimizeStartsHeadTagOrBodyTagSetup = optimizeStartsHeadTagOrBodyTagSetup; | ||
function optimizeStartsHeadTagOrBodyTagResume( | ||
export function optimizeStartsHeadTagOrBodyTagResume( | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
@@ -58,2 +53,1 @@ nodeList, | ||
} | ||
exports.optimizeStartsHeadTagOrBodyTagResume = optimizeStartsHeadTagOrBodyTagResume; |
import type { MLASTAttr, MLToken } from '@markuplint/ml-ast'; | ||
type TagTokens = { | ||
tagName: string; | ||
attrs: MLASTAttr[]; | ||
selfClosingSolidus: MLToken; | ||
endSpace: MLToken; | ||
tagName: string; | ||
attrs: MLASTAttr[]; | ||
selfClosingSolidus: MLToken; | ||
endSpace: MLToken; | ||
}; | ||
export default function parseRawTag( | ||
raw: string, | ||
startLine: number, | ||
startCol: number, | ||
startOffset: number, | ||
offsetOffset?: number, | ||
offsetLine?: number, | ||
offsetColumn?: number, | ||
): TagTokens; | ||
export default function parseRawTag(raw: string, startLine: number, startCol: number, startOffset: number, offsetOffset?: number, offsetLine?: number, offsetColumn?: number): TagTokens; | ||
export {}; |
@@ -1,16 +0,12 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const parser_utils_1 = require("@markuplint/parser-utils"); | ||
const attr_tokenizer_1 = tslib_1.__importDefault(require("./attr-tokenizer")); | ||
import { reTag, reTagName, isPotentialCustomElementName, tokenizer } from '@markuplint/parser-utils'; | ||
import attrTokenizer from './attr-tokenizer.js'; | ||
// eslint-disable-next-line no-control-regex | ||
const reAttrsInStartTag = /\s*[^\x00-\x1f\x7f-\x9f "'>/=]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^\s]*))?/; | ||
const reEndTokens = /(\s*\/)?(\s*)>$/; | ||
function parseRawTag(raw, startLine, startCol, startOffset, offsetOffset = 0, offsetLine = 0, offsetColumn = 0) { | ||
var _a, _b; | ||
export default function parseRawTag(raw, startLine, startCol, startOffset, offsetOffset = 0, offsetLine = 0, offsetColumn = 0) { | ||
let offset = startOffset + offsetOffset; | ||
let line = startLine + offsetLine; | ||
let col = startCol + (startLine === 1 ? offsetColumn : 0); | ||
const matches = raw.match(parser_utils_1.reTag); | ||
const tagWithAttrs = matches === null || matches === void 0 ? void 0 : matches[1]; | ||
const matches = raw.match(reTag); | ||
const tagWithAttrs = matches?.[1]; | ||
if (!tagWithAttrs) { | ||
@@ -22,3 +18,3 @@ throw new SyntaxError(`Invalid tag syntax: "${raw}"`); | ||
const tagName = tagNameSplitted[0] || tagNameSplitted[1]; | ||
if (!tagName || (!parser_utils_1.reTagName.test(tagName) && !(0, parser_utils_1.isPotentialCustomElementName)(tagName))) { | ||
if (!tagName || (!reTagName.test(tagName) && !isPotentialCustomElementName(tagName))) { | ||
throw new SyntaxError(`Invalid tag name: "${tagName}" in <${tagWithAttrs}>`); | ||
@@ -36,3 +32,3 @@ } | ||
const rawAttr = attrMatchedMap[0]; | ||
const attr = (0, attr_tokenizer_1.default)(rawAttr, line, col, offset); | ||
const attr = attrTokenizer(rawAttr, line, col, offset); | ||
line = attr.endLine; | ||
@@ -46,7 +42,7 @@ col = attr.endCol; | ||
const endTokens = reEndTokens.exec(raw); | ||
const selfClosingSolidus = (0, parser_utils_1.tokenizer)((_a = endTokens === null || endTokens === void 0 ? void 0 : endTokens[1]) !== null && _a !== void 0 ? _a : '', line, col, offset); | ||
const selfClosingSolidus = tokenizer(endTokens?.[1] ?? '', line, col, offset); | ||
line = selfClosingSolidus.endLine; | ||
col = selfClosingSolidus.endCol; | ||
offset = selfClosingSolidus.endOffset; | ||
const endSpace = (0, parser_utils_1.tokenizer)((_b = endTokens === null || endTokens === void 0 ? void 0 : endTokens[2]) !== null && _b !== void 0 ? _b : '', line, col, offset); | ||
const endSpace = tokenizer(endTokens?.[2] ?? '', line, col, offset); | ||
return { | ||
@@ -59,2 +55,1 @@ tagName, | ||
} | ||
exports.default = parseRawTag; |
@@ -1,23 +0,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parse = void 0; | ||
const tslib_1 = require("tslib"); | ||
const parser_utils_1 = require("@markuplint/parser-utils"); | ||
const create_tree_1 = require("./create-tree"); | ||
const is_document_fragment_1 = tslib_1.__importDefault(require("./is-document-fragment")); | ||
const optimize_starts_head_or_body_1 = require("./optimize-starts-head-or-body"); | ||
const parse = (rawCode, options) => { | ||
var _a, _b, _c; | ||
if (options === null || options === void 0 ? void 0 : options.ignoreFrontMatter) { | ||
rawCode = (0, parser_utils_1.ignoreFrontMatter)(rawCode); | ||
import { ignoreFrontMatter, flattenNodes } from '@markuplint/parser-utils'; | ||
import { createTree } from './create-tree.js'; | ||
import isDocumentFragment from './is-document-fragment.js'; | ||
import { isStartsHeadTagOrBodyTag, optimizeStartsHeadTagOrBodyTagResume, optimizeStartsHeadTagOrBodyTagSetup, } from './optimize-starts-head-or-body.js'; | ||
export const parse = (rawCode, options) => { | ||
if (options?.ignoreFrontMatter) { | ||
rawCode = ignoreFrontMatter(rawCode); | ||
} | ||
const isFragment = (0, is_document_fragment_1.default)(rawCode); | ||
const data = (0, optimize_starts_head_or_body_1.isStartsHeadTagOrBodyTag)(rawCode) ? (0, optimize_starts_head_or_body_1.optimizeStartsHeadTagOrBodyTagSetup)(rawCode) : null; | ||
if (data === null || data === void 0 ? void 0 : data.code) { | ||
const isFragment = isDocumentFragment(rawCode); | ||
const data = isStartsHeadTagOrBodyTag(rawCode) ? optimizeStartsHeadTagOrBodyTagSetup(rawCode) : null; | ||
if (data?.code) { | ||
rawCode = data.code; | ||
} | ||
const nodeTree = (0, create_tree_1.createTree)(rawCode, isFragment, (_a = options === null || options === void 0 ? void 0 : options.offsetOffset) !== null && _a !== void 0 ? _a : 0, (_b = options === null || options === void 0 ? void 0 : options.offsetLine) !== null && _b !== void 0 ? _b : 0, (_c = options === null || options === void 0 ? void 0 : options.offsetColumn) !== null && _c !== void 0 ? _c : 0); | ||
const nodeList = (0, parser_utils_1.flattenNodes)(nodeTree, rawCode); | ||
const nodeTree = createTree(rawCode, isFragment, options?.offsetOffset ?? 0, options?.offsetLine ?? 0, options?.offsetColumn ?? 0); | ||
const nodeList = flattenNodes(nodeTree, rawCode); | ||
if (data) { | ||
(0, optimize_starts_head_or_body_1.optimizeStartsHeadTagOrBodyTagResume)(nodeList, data); | ||
optimizeStartsHeadTagOrBodyTagResume(nodeList, data); | ||
} | ||
@@ -29,2 +24,1 @@ return { | ||
}; | ||
exports.parse = parse; |
{ | ||
"name": "@markuplint/html-parser", | ||
"version": "3.0.0-dev.186+37ceba57", | ||
"version": "3.0.0-dev.290+af676442", | ||
"description": "HTML parser for markuplint", | ||
@@ -9,3 +9,8 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
"private": false, | ||
"main": "lib/index.js", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./lib/index.js" | ||
} | ||
}, | ||
"types": "lib/index.d.ts", | ||
@@ -24,9 +29,9 @@ "publishConfig": { | ||
"dependencies": { | ||
"@markuplint/ml-ast": "3.0.0-dev.186+37ceba57", | ||
"@markuplint/parser-utils": "3.0.0-dev.186+37ceba57", | ||
"@markuplint/ml-ast": "3.0.0-dev.290+af676442", | ||
"@markuplint/parser-utils": "3.0.0-dev.290+af676442", | ||
"parse5": "7.1.2", | ||
"tslib": "^2.4.1", | ||
"type-fest": "^3.8.0" | ||
"tslib": "^2.6.2", | ||
"type-fest": "^4.3.1" | ||
}, | ||
"gitHead": "37ceba578aff49e0326c5e374cef3da6be303b25" | ||
"gitHead": "af6764422feecb56d1d84659028f53daf685bb78" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Yes
24392
19
532
2
+ Addedtype-fest@4.30.2(transitive)
- Removedtype-fest@3.13.1(transitive)
Updatedtslib@^2.6.2
Updatedtype-fest@^4.3.1