Created
May 26, 2016 18:02
-
-
Save masnick/6de59a7a8cb7de8f6c0a2602c7c6b599 to your computer and use it in GitHub Desktop.
Convert Markdown to JIRA markup
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
// https://github.com/FokkeZB/J2M/blob/master/script.js | |
function toJ(converted) { | |
converted = converted.replace(/^(.*?)\n([=-])+$/gm, function (match,content,level) { | |
return 'h' + (level[0] === '=' ? 1 : 2) + '. ' + content; | |
}); | |
converted = converted.replace(/^([#]+)(.*?)$/gm, function (match,level,content) { | |
return 'h' + level.length + '.' + content; | |
}); | |
converted = converted.replace(/([*_]+)(.*?)\1/g, function (match,wrapper,content) { | |
var to = (wrapper.length === 1) ? '_' : '*'; | |
return to + content + to; | |
}); | |
// Make multi-level bulleted lists work | |
converted = converted.replace(/^(\s*)- (.*)$/gm, function (match,level,content) { | |
var len = 2; | |
if(level.length > 0) { | |
len = parseInt(level.length/4.0) + 2; | |
} | |
return Array(len).join("-") + ' ' + content; | |
}); | |
var map = { | |
cite: '??', | |
del: '-', | |
ins: '+', | |
sup: '^', | |
sub: '~' | |
}; | |
converted = converted.replace(new RegExp('<(' + Object.keys(map).join('|') + ')>(.*?)<\/\\1>', 'g'), function (match,from,content) { | |
console.log(from); | |
var to = map[from]; | |
return to + content + to; | |
}); | |
converted = converted.replace(/~~(.*?)~~/g, '-$1-'); | |
converted = converted.replace(/`{3,}(\w+)?((?:\n|[^`])+)`{3,}/g, function(match, synt, content) { | |
var code = '{code'; | |
if (synt) { | |
code += ':' + synt; | |
} | |
code += '}' + content + '{code}'; | |
return code; | |
}); | |
converted = converted.replace(/`([^`]+)`/g, '{{$1}}'); | |
converted = converted.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '[$1|$2]'); | |
converted = converted.replace(/<([^>]+)>/g, '[$1]'); | |
return converted; | |
} | |
toJ(document.kmvar.jira_markdown); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment