-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathMarkdownToYouTrack.java
75 lines (67 loc) · 2.86 KB
/
MarkdownToYouTrack.java
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.vladsch.flexmark.java.samples;
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension;
import com.vladsch.flexmark.ext.tables.TablesExtension;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.data.DataHolder;
import com.vladsch.flexmark.util.data.MutableDataSet;
import com.vladsch.flexmark.youtrack.converter.YouTrackConverterExtension;
import java.util.Arrays;
public class MarkdownToYouTrack {
static final DataHolder OPTIONS = new MutableDataSet()
.set(Parser.EXTENSIONS, Arrays.asList(
TablesExtension.create(),
StrikethroughExtension.create(),
YouTrackConverterExtension.create()
));
static final Parser PARSER = Parser.builder(OPTIONS).build();
static final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build();
// use the PARSER to parse and RENDERER to parse pegdown indentation rules and render CommonMark
public static void main(String[] args) {
String markdown = "Heading\n" +
"-----\n" +
"paragraph text \n" +
"lazy continuation\n" +
"\n" +
"* list item\n" +
" > block quote\n" +
" lazy continuation\n" +
"\n" +
"~~~info\n" +
" with uneven indent\n" +
" with uneven indent\n" +
" indented code\n" +
"~~~ \n" +
"\n" +
" with uneven indent\n" +
" with uneven indent\n" +
" indented code\n" +
"1. numbered item 1 \n" +
"1. numbered item 2 \n" +
"1. numbered item 3 \n" +
" - bullet item 1 \n" +
" - bullet item 2 \n" +
" - bullet item 3 \n" +
" 1. numbered sub-item 1 \n" +
" 1. numbered sub-item 2 \n" +
" 1. numbered sub-item 3 \n" +
" \n" +
" ~~~info\n" +
" with uneven indent\n" +
" with uneven indent\n" +
" indented code\n" +
" ~~~ \n" +
" \n" +
" with uneven indent\n" +
" with uneven indent\n" +
" indented code\n" +
"";
System.out.println("markdown\n");
System.out.println(markdown);
Node document = PARSER.parse(markdown);
String text = RENDERER.render(document);
System.out.println("\n\nYouTrack\n");
System.out.println(text);
}
}