Skip to content

Instantly share code, notes, and snippets.

@rafi
Created October 6, 2014 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafi/e3904cfce120f0eb45a2 to your computer and use it in GitHub Desktop.
Save rafi/e3904cfce120f0eb45a2 to your computer and use it in GitHub Desktop.
Atlassian JIRA markup to Markdown. Oh the horror! Inspiration: https://github.com/FokkeZB/J2M
function! s:convert_to_markdown(txt)
let txt = a:txt
let txt = substitute(txt, 'h\(\d\+\)\. ', '\=repeat("#", submatch(1))." "', 'g')
let txt = substitute(txt, '{code\(:\([a-z]\+\)\)\?}', '```\2', 'g')
let txt = substitute(txt, '{{\([^}\n]\+\)}}', '`\1`', 'g')
let txt = substitute(txt, '\*\([^\*\n]\{-}\)\*', '\*\*\1\*\*', 'g')
let txt = substitute(txt, '_\([^_\n]\{-}\)_', '\*\1\*', 'g')
let txt = substitute(txt, '\s\zs-\([^-\n]\{-}\)-', '~~~\1~~~', 'g')
let txt = substitute(txt, '+\([^+\n]\+\)+', '<ins>\1</ins>', 'g')
let txt = substitute(txt, '\^\([^\^\n]\+\)\^', '<sup>\1</sup>', 'g')
let txt = substitute(txt, '??\([^?\n]\+\)??', '<cite>\1</cite>', 'g')
let txt = substitute(txt, '\[\([^|\]\n]\+\)|\([^\]\n]\+\)\]', '[\1](\2)', 'g')
let txt = substitute(txt, '\[\([\([^\]\n]\+\)\]\([^(]*\)', '<\1>\2', 'g')
let txt = substitute(txt, "\r", '', 'g')
return txt
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment