Skip to content

Commit 2410758

Browse files
authored
Merge pull request #73 from DesignLiquido/skip-dtd-elements
HTML input with `<!DOCTYPE html>` defined returns empty output.
2 parents 6b75062 + 79a1cf3 commit 2410758

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/xpath/match-resolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class MatchResolver {
9696
* @returns The list of found nodes.
9797
*/
9898
private absoluteXsltMatch(expression: LocationExpr, context: ExprContext): XNode[] {
99-
const firstChildOfRoot = context.root.childNodes[0];
99+
const firstChildOfRoot = context.root.childNodes.find(c => c.nodeName !== '#dtd-section');
100100
const clonedContext = context.clone([firstChildOfRoot], undefined, 0, undefined);
101101
const matchedNodes = expression.evaluate(clonedContext).nodeSetValue();
102102
const finalList = [];
@@ -105,7 +105,7 @@ export class MatchResolver {
105105
// considered.
106106
let nodeList: XNode[];
107107
if (context.nodeList.length === 1 && context.nodeList[0].nodeName === '#document') {
108-
nodeList = [context.nodeList[0].childNodes[0]];
108+
nodeList = [context.nodeList[0].childNodes.find(c => c.nodeName !== '#dtd-section')];
109109
} else {
110110
nodeList = context.nodeList;
111111
}

src/xslt/xslt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ export class Xslt {
710710
let node: XNode;
711711
let elementContext = context;
712712
if (context.nodeList[context.position].nodeName === '#document') {
713-
node = context.nodeList[context.position].firstChild;
713+
node = context.nodeList[context.position].childNodes.find(c => c.nodeName !== '#dtd-section');
714714
elementContext = context.clone([node]);
715715
} else {
716716
node = context.nodeList[context.position];

tests/html-to-lmht.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,8 @@ describe('HTML to LMHT', () => {
14651465
</xsl:transform>
14661466
);
14671467

1468-
const xmlString = (
1468+
const xmlString = '<!DOCTYPE html>' +
1469+
(
14691470
<html>
14701471
<head>
14711472
<title>Teste</title>

0 commit comments

Comments
 (0)