From 2c3b5e580dd45ff80172543590f21d562d61ef16 Mon Sep 17 00:00:00 2001 From: Kim Biesbjerg Date: Wed, 7 Dec 2016 16:30:24 +0100 Subject: [PATCH] Extract direct text nodes only when parsing directive --- src/parsers/directive.parser.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/parsers/directive.parser.ts b/src/parsers/directive.parser.ts index 21d0fde..bbb4baf 100644 --- a/src/parsers/directive.parser.ts +++ b/src/parsers/directive.parser.ts @@ -22,12 +22,17 @@ export class DirectiveParser extends AbstractTemplateParser implements ParserInt .each((i: number, element: CheerioElement) => { const $element = $(element); const attr = $element.attr('translate'); - const text = $element.html().trim(); if (attr) { results.push(attr); - } else if (text) { - results.push(text); + } else { + $element + .contents() + .toArray() + .filter(textNode => textNode.type === 'text') + .map(textNode => textNode.nodeValue.trim()) + .filter(text => text.length > 0) + .forEach(text => results.push(text)); } });