Skip to content

Instantly share code, notes, and snippets.

@vhf
Forked from Mayeu/example.js
Created July 13, 2017 16:39
Show Gist options
  • Save vhf/cccaf5badd152f33d1a500a5a8e5e39e to your computer and use it in GitHub Desktop.
Save vhf/cccaf5badd152f33d1a500a5a8e5e39e to your computer and use it in GitHub Desktop.
Remark fix new lines for GitLab
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)
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