Extract direct text nodes only when parsing directive
This commit is contained in:
parent
e26d522604
commit
2c3b5e580d
@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user