Skip to content

Commit

Permalink
Fixing textarea markers
Browse files Browse the repository at this point in the history
  • Loading branch information
Lcfvs committed Mar 7, 2022
1 parent 4fdb0db commit 7f6d61d
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 163 deletions.
18 changes: 16 additions & 2 deletions lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const tokenize = node => {
} else if (nodeName === 'SCRIPT') {
const tokens = identify(attribute, current.textContent)

if (tokens.length) {
map.set(key, { tokens })
}
} else if (nodeName === 'TEXTAREA') {
const tokens = identify(attribute, current.value)

if (tokens.length) {
map.set(key, { tokens })
}
Expand Down Expand Up @@ -181,7 +187,7 @@ const value = (tokens, node, name, template) => {

const content = (tokens, node, template) => {
const nodes = []
let [target, content] = pick(node)
let [target, content, asValue] = pick(node)

for (const { identifier, key, optional } of tokens) {
const [prefix] = content.split(identifier)
Expand All @@ -196,7 +202,11 @@ const content = (tokens, node, template) => {
content = content.replace(`${prefix}${identifier}`, '')
}

target.replaceWith(...nodes, content)
if (asValue) {
target.textContent = nodes.join('')
} else {
target.replaceWith(...nodes, content)
}
}

const pick = node => {
Expand All @@ -210,6 +220,10 @@ const pick = node => {
return [node.firstChild, node.textContent]
}

if (nodeName === 'TEXTAREA') {
return [node, node.value, true]
}

return [node, node.nodeValue]
}

Expand Down
Loading

0 comments on commit 7f6d61d

Please sign in to comment.