forked from doctrine/jira-github-issues
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjira_markdown.php
35 lines (27 loc) · 1.5 KB
/
jira_markdown.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
function toMarkdown($text) {
$converted = $text;
$converted = preg_replace_callback('/^h([0-6])\.(.*)$/m', function ($matches) {
return str_repeat('#', $matches[1]) . $matches[2];
}, $converted);
$converted = preg_replace_callback('/([*_])(.*)\1/', function ($matches) {
list ($match, $wrapper, $content) = $matches;
$to = ($wrapper === '*') ? '**' : '*';
return $to . $content . $to;
}, $converted);
$converted = preg_replace('/\{\{([^}]+)\}\}/', '`$1`', $converted);
$converted = preg_replace('/\?\?((?:.[^?]|[^?].)+)\?\?/', '<cite>$1</cite>', $converted);
$converted = preg_replace('/\+([^+]*)\+/', '<ins>$1</ins>', $converted);
$converted = preg_replace('/\^([^^]*)\^/', '<sup>$1</sup>', $converted);
$converted = preg_replace('/~([^~]*)~/', '<sub>$1</sub>', $converted);
$converted = preg_replace('/-([^-]*)-/', '-$1-', $converted);
$converted = preg_replace('/{code(:([a-z]+))?}/', '```$2', $converted);
$converted = preg_replace('/{code(:([^}]+))?}/', '```', $converted);
$converted = preg_replace('/\[(.+?)\|(.+?)\]/', '[$1]($2)', $converted);
//$converted = preg_replace('/\[(.+?)\]([^\(]*)/', '<$1>$2', $converted);
$converted = preg_replace('/{noformat}/', '```', $converted);
$converted = preg_replace_callback('/((AGATE|OPAL|MK)+-([0-9]+))/', function ($matches) {
return '[' . $matches[1] . ']('. $_SERVER['JIRA_URL'] . '/jira/browse/' . $matches[1] . ')';
}, $converted);
return $converted;
}