diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-03-20 21:22:45 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-03-20 21:22:45 -0300 |
commit | e3c4b80685417365344ff8705f2b72d4cb8408b8 (patch) | |
tree | 8c59e593bf1cb68ffd4da90b06afe1d59e35ea06 /src/content/dependencies | |
parent | 67a7db56e287ba0bd2b71c51225f20604bc74045 (diff) |
content: transformContent: factor out absorbFollowingPunctuation
Diffstat (limited to 'src/content/dependencies')
-rw-r--r-- | src/content/dependencies/transformContent.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index 48e20f94..f61865bb 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -258,6 +258,20 @@ export default { data.nodes.map((node, index) => { const nextNode = data.nodes[index + 1]; + const absorbFollowingPunctuation = template => { + if (nextNode?.type !== 'text') { + return; + } + + const text = nextNode.data; + const match = text.match(/^[.,;:?!…]+/); + const suffix = match?.[0]; + if (suffix) { + template.setSlot('suffixNormalContent', suffix); + offsetTextNode = suffix.length; + } + }; + switch (node.type) { case 'text': { const text = node.data.slice(offsetTextNode); @@ -458,14 +472,8 @@ export default { fromContent: true, }); - if (slots.absorbPunctuationFollowingExternalLinks && nextNode?.type === 'text') { - const text = nextNode.data; - const match = text.match(/^[.,;:?!…]+/); - const suffix = match?.[0]; - if (suffix) { - externalLink.setSlot('suffixNormalContent', suffix); - offsetTextNode = suffix.length; - } + if (slots.absorbPunctuationFollowingExternalLinks) { + absorbFollowingPunctuation(externalLink); } if (slots.indicateExternalLinks) { |