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) => {
|
.each((i: number, element: CheerioElement) => {
|
||||||
const $element = $(element);
|
const $element = $(element);
|
||||||
const attr = $element.attr('translate');
|
const attr = $element.attr('translate');
|
||||||
const text = $element.html().trim();
|
|
||||||
|
|
||||||
if (attr) {
|
if (attr) {
|
||||||
results.push(attr);
|
results.push(attr);
|
||||||
} else if (text) {
|
} else {
|
||||||
results.push(text);
|
$element
|
||||||
|
.contents()
|
||||||
|
.toArray()
|
||||||
|
.filter(textNode => textNode.type === 'text')
|
||||||
|
.map(textNode => textNode.nodeValue.trim())
|
||||||
|
.filter(text => text.length > 0)
|
||||||
|
.forEach(text => results.push(text));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user