Skip to content

Commit

Permalink
+ support for multiple markers into an attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Lcfvs committed Jun 8, 2021
1 parent ee68b88 commit c5c5298
Show file tree
Hide file tree
Showing 3 changed files with 418 additions and 445 deletions.
22 changes: 18 additions & 4 deletions lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,30 @@ const policy = {

function attribute (template, node) {
const { nodeValue } = node
const rules = identify(strip(nodeValue), nodeValue)
const value = resolve(template, rules)
const matches = nodeValue.match(identifier).map(identifyAll, template)

if (value === null) {
if (matches.every(isNullish)) {
node.ownerElement.removeAttribute(node.nodeName)
} else {
node.nodeValue = `${value}`
node.nodeValue = matches.reduce(replaceAll, nodeValue)
}
}

function identifyAll (match) {
return [
match,
resolve(this, identify(strip(match), match))
]
}

function isNullish ([, value = null]) {
return value === null
}

function replaceAll (text, [match, value]) {
return text.replaceAll(match, value ?? '')
}

function content (template, node) {
const { textContent } = node
const rules = identify(strip(textContent), textContent)
Expand Down
Loading

0 comments on commit c5c5298

Please sign in to comment.