Extract direct text nodes only when parsing directive

This commit is contained in:
Kim Biesbjerg 2016-12-07 16:30:24 +01:00
parent e26d522604
commit 2c3b5e580d

View File

@ -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));
}
});