diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-03-20 21:20:21 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-03-20 21:20:21 +0900 |
| commit | b0cb51367d8c68eabafaa57c2967587007aa79bd (patch) | |
| tree | 1589fde77179c50cb29c74e99f9bb4cca30fe3ab /nuldoc-src | |
| parent | ab4c36fa056fcf0d1dc1f7c2301630cd88f783fe (diff) | |
| download | blog.nsfisis.dev-b0cb51367d8c68eabafaa57c2967587007aa79bd.tar.gz blog.nsfisis.dev-b0cb51367d8c68eabafaa57c2967587007aa79bd.tar.zst blog.nsfisis.dev-b0cb51367d8c68eabafaa57c2967587007aa79bd.zip | |
feat(nuldoc): support XML comments
Diffstat (limited to 'nuldoc-src')
| -rw-r--r-- | nuldoc-src/xml.ts | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/nuldoc-src/xml.ts b/nuldoc-src/xml.ts index f07161f..13ec5d6 100644 --- a/nuldoc-src/xml.ts +++ b/nuldoc-src/xml.ts @@ -56,12 +56,19 @@ function parseChildNodes(p: Parser): Node[] { const nodes = []; while (true) { const c = peek(p); - const c2 = peek2(p); + const c2 = peekN(p, 2); + const c3 = peekN(p, 3); if (c === "<") { if (c2 === "/") { break; } else if (c2 === "!") { - nodes.push(parseCdata(p)); + if (c3 === "[") { + // <![CDATA[ + nodes.push(parseCdata(p)); + } else { + // <!-- + skipComment(p); + } } else { nodes.push(parseXmlElement(p)); } @@ -92,6 +99,12 @@ function parseCdata(p: Parser): Text { }; } +function skipComment(p: Parser) { + expect(p, "<!--"); + skipTo(p, "-->"); + next(p, "-->".length); +} + function formatCdata(s: string): string { // <![CDATA[ // foo @@ -218,11 +231,11 @@ function skipWhitespaces(p: Parser) { } function peek(p: Parser): string | null { - return (p.index < p.source.length) ? p.source[p.index] : null; + return peekN(p, 1); } -function peek2(p: Parser): string | null { - return (p.index + 1 < p.source.length) ? p.source[p.index + 1] : null; +function peekN(p: Parser, n: number): string | null { + return (p.index + n - 1 < p.source.length) ? p.source[p.index + n - 1] : null; } function next(p: Parser, n = 1) { |
