Skip to content

Instantly share code, notes, and snippets.

@Mayeu
Last active July 13, 2017 16:39
Show Gist options
  • Save Mayeu/011b3f8c0fe50f526cea3c208d1a2aaf to your computer and use it in GitHub Desktop.
Save Mayeu/011b3f8c0fe50f526cea3c208d1a2aaf 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