Created
August 23, 2020 12:54
-
-
Save ahmadawais/a70c8f1280a253aa3847df7244e267f8 to your computer and use it in GitHub Desktop.
remark-widow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const visit = require('unist-util-visit') | |
module.exports = () => (tree, file) => { | |
visit(tree, 'heading', node => { | |
console.log('node: ', node); | |
visit(node, 'text', textNode => { | |
console.log('textNode: ', textNode); | |
const text = textNode.value ? textNode.value.trim() : '' | |
// const textNoWidows = text.replace(/\s+([\S]*)(\s*)$/gm, "\xA0$1$2"); | |
// const textNoWidows = text.replace(/\s([^\s]*)(\s+)?$/, ' $1'); | |
const textNoWidows = text.replace(/\s([^\s]*)(\s+)?$/, '\xA0$1'); | |
console.log('textNoWidows: ', textNoWidows); | |
// const textNoWidows = text.replace(/\s([^\s]*)(\s+)?$/, ' $1'); | |
textNode.value = textNoWidows | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment