|
10 | 10 | import java.util.List; |
11 | 11 |
|
12 | 12 | public class GeneratorUtils { |
13 | | - public static String getTextFromTextNode(SemanticTextNode textNode, String strikethroughTextOpening, String strikethroughTextClosing) { |
| 13 | + protected static final String strikethroughTextMD = "~~"; |
| 14 | + protected static final String strikethroughTextHtmlOpeningTag = "<del>"; |
| 15 | + protected static final String strikethroughTextHtmlClosingTag = "</del>";; |
| 16 | + |
| 17 | + public static String getTextFromTextNode(SemanticTextNode textNode, OutputType outputType) { |
14 | 18 | StringBuilder stringBuilder = new StringBuilder(); |
15 | 19 | for (TextColumn column : textNode.getColumns()) { |
16 | | - for (TextBlock block : column.getBlocks()) { |
17 | | - stringBuilder.append(getTextFromLines(block.getLines(), strikethroughTextOpening, strikethroughTextClosing)); |
| 20 | + List<TextBlock> blocks = column.getBlocks(); |
| 21 | + for (int i = 0; i < blocks.size() - 1; i++) { |
| 22 | + TextBlock block = blocks.get(i); |
| 23 | + stringBuilder.append(getTextFromLines(block.getLines(), outputType)); |
| 24 | + TextChunkUtils.formatLineEnd(stringBuilder); |
18 | 25 | } |
| 26 | + stringBuilder.append(getTextFromLines(blocks.get(blocks.size() - 1).getLines(), outputType)); |
19 | 27 | } |
20 | 28 | return stringBuilder.toString(); |
21 | 29 | } |
22 | 30 |
|
23 | | - public static String getTextFromLines(List<TextLine> textLines, String strikethroughTextOpening, String strikethroughTextClosing) { |
| 31 | + public static String getTextFromLines(List<TextLine> textLines, OutputType outputType) { |
24 | 32 | StringBuilder stringBuilder = new StringBuilder(); |
25 | 33 | for (int i = 0; i < textLines.size() - 1; i++) { |
26 | 34 | TextLine line = textLines.get(i); |
27 | | - getTextFromLine(line, stringBuilder, strikethroughTextOpening, strikethroughTextClosing); |
| 35 | + switch (outputType) { |
| 36 | + case MD: |
| 37 | + getTextFromLineForMarkdown(line, stringBuilder); |
| 38 | + break; |
| 39 | + case HTML: |
| 40 | + getTextFromLineForHTML(line, stringBuilder); |
| 41 | + break; |
| 42 | + } |
28 | 43 | TextChunkUtils.formatLineEnd(stringBuilder); |
29 | 44 | } |
30 | | - getTextFromLine(textLines.get(textLines.size() - 1), stringBuilder, strikethroughTextOpening, strikethroughTextClosing); |
| 45 | + switch (outputType) { |
| 46 | + case MD: |
| 47 | + getTextFromLineForMarkdown(textLines.get(textLines.size() - 1), stringBuilder); |
| 48 | + break; |
| 49 | + case HTML: |
| 50 | + getTextFromLineForHTML(textLines.get(textLines.size() - 1), stringBuilder); |
| 51 | + break; |
| 52 | + } |
31 | 53 | return stringBuilder.toString(); |
32 | 54 | } |
33 | 55 |
|
34 | | - public static void getTextFromLine(TextLine line, StringBuilder stringBuilder, String strikethroughTextOpening, String strikethroughTextClosing) { |
| 56 | + public static void getTextFromLineForMarkdown(TextLine line, StringBuilder stringBuilder) { |
| 57 | + for (TextChunk chunk : line.getTextChunks()) { |
| 58 | + if (chunk.getIsStrikethroughText()) { |
| 59 | + stringBuilder.append(strikethroughTextMD); |
| 60 | + } |
| 61 | + stringBuilder.append(chunk.getValue()); |
| 62 | + if (chunk.getIsStrikethroughText()) { |
| 63 | + stringBuilder.append(strikethroughTextMD); |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + public static void getTextFromLineForHTML(TextLine line, StringBuilder stringBuilder) { |
35 | 69 | for (TextChunk chunk : line.getTextChunks()) { |
36 | 70 | if (chunk.getIsStrikethroughText()) { |
37 | | - stringBuilder.append(strikethroughTextOpening); |
| 71 | + stringBuilder.append(strikethroughTextHtmlOpeningTag); |
38 | 72 | } |
39 | 73 | stringBuilder.append(chunk.getValue()); |
40 | 74 | if (chunk.getIsStrikethroughText()) { |
41 | | - stringBuilder.append(strikethroughTextClosing); |
| 75 | + stringBuilder.append(strikethroughTextHtmlClosingTag); |
42 | 76 | } |
43 | 77 | } |
44 | 78 | } |
|
0 commit comments