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 package gov.nist.secauto.metaschema.core.datatype.markup.flexmark;
28
29 import com.vladsch.flexmark.formatter.Formatter;
30 import com.vladsch.flexmark.html.HtmlRenderer;
31 import com.vladsch.flexmark.html2md.converter.FlexmarkHtmlConverter;
32 import com.vladsch.flexmark.parser.ListOptions;
33 import com.vladsch.flexmark.parser.Parser;
34 import com.vladsch.flexmark.util.data.DataHolder;
35
36 import edu.umd.cs.findbugs.annotations.NonNull;
37
38 public class FlexmarkFactory {
39 @NonNull
40 private static final FlexmarkFactory SINGLETON = new FlexmarkFactory();
41
42 @NonNull
43 private final DataHolder configuration;
44 @NonNull
45 private final Parser markdownParser;
46 @NonNull
47 private final HtmlRenderer htmlRenderer;
48 @NonNull
49 private final Formatter formatter;
50 @NonNull
51 private final FlexmarkHtmlConverter htmlConverter;
52 @NonNull
53 final ListOptions listOptions;
54
55 @NonNull
56 public static FlexmarkFactory instance() {
57 return SINGLETON;
58 }
59
60 public FlexmarkFactory() {
61 this(FlexmarkConfiguration.FLEXMARK_CONFIG);
62 }
63
64 @SuppressWarnings("null")
65 public FlexmarkFactory(@NonNull DataHolder config) {
66 this.configuration = config;
67 this.markdownParser = Parser.builder(config)
68 .customDelimiterProcessor(new FixedEmphasisDelimiterProcessor(Parser.STRONG_WRAPS_EMPHASIS.get(config)))
69 .build();
70 this.htmlRenderer = HtmlRenderer.builder(config).build();
71 this.formatter = Formatter.builder(config).build();
72 this.htmlConverter = FlexmarkHtmlConverter.builder(config).build();
73 this.listOptions = ListOptions.get(config);
74 }
75
76 @NonNull
77 public DataHolder getConfiguration() {
78 return configuration;
79 }
80
81 @NonNull
82 public ListOptions getListOptions() {
83 return listOptions;
84 }
85
86 @NonNull
87 public Parser getMarkdownParser() {
88 return markdownParser;
89 }
90
91 @NonNull
92 public HtmlRenderer getHtmlRenderer() {
93 return htmlRenderer;
94 }
95
96 @NonNull
97 public Formatter getFormatter() {
98 return formatter;
99 }
100
101 @NonNull
102 public FlexmarkHtmlConverter getFlexmarkHtmlConverter() {
103 return htmlConverter;
104 }
105 }