aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src
diff options
context:
space:
mode:
Diffstat (limited to 'nuldoc-src')
-rw-r--r--nuldoc-src/xml.ts23
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) {