Skip to content

Instantly share code, notes, and snippets.

@masnick masnick/md2jira.js
Created May 26, 2016

Embed
What would you like to do?
Convert Markdown to JIRA markup
// 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
You can’t perform that action at this time.