From ddd7d571b2ce01c35a9926ae03225e3bb65322dd Mon Sep 17 00:00:00 2001 From: PBK-B Date: Thu, 3 Apr 2025 15:04:43 +0800 Subject: [PATCH] feat: html lexer supports DefaultValue obtained from innerText --- src/lexers/html-lexer.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lexers/html-lexer.js b/src/lexers/html-lexer.js index 2401f3b4..dff4bd49 100644 --- a/src/lexers/html-lexer.js +++ b/src/lexers/html-lexer.js @@ -7,6 +7,7 @@ export default class HTMLLexer extends BaseLexer { this.attr = options.attr || 'data-i18n' this.optionAttr = options.optionAttr || 'data-i18n-options' + this.innerTextDefaultValue = options.innerTextDefaultValue ?? false } extract(content) { @@ -26,6 +27,17 @@ export default class HTMLLexer extends BaseLexer { } } + // whether to fill the default value + if ( + (!options || options.defaultValue == undefined) && + that.innerTextDefaultValue && + $node.text() + ) { + if (!options) options = {} + const value = $node.text() + options.defaultValue = value + } + for (let key of keys) { // remove any leading [] in the key key = key.replace(/^\[[a-zA-Z0-9_-]*\]/, '')