-
-
Save vhf/cccaf5badd152f33d1a500a5a8e5e39e to your computer and use it in GitHub Desktop.
Remark fix new lines for GitLab
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 fixNewLine = require('./index.js') | |
const remark = require('remark') | |
text = "lol\nlol\n```\nlol\nlol\n```\n> lol\n> lol" | |
processed = remark() | |
.use(fixNewLine) | |
.processSync(text) | |
console.log(processed) |
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
var visit = require('unist-util-visit'); | |
var toString = require('mdast-util-to-string') | |
module.exports = fixNewLine | |
function fixNewLine () { | |
return function fixNewLineTransformer (root, file) { | |
var pattern = /.+ \n.+/m | |
visit(root, 'text', (node, index, parent) => { | |
if (parent.type === 'paragraph') { | |
if (!pattern.test(node.value)) { | |
node.value = (node.value.replace(/(\S)\n/mg, '$1 \n')); | |
} | |
} | |
}); | |
return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment