AsciiDocToHtml.java

1
package pro.verron.officestamper.asciidoc;
2
3
import java.util.List;
4
import java.util.Map;
5
import java.util.function.Function;
6
import java.util.stream.Collectors;
7
8
import static pro.verron.officestamper.asciidoc.AsciiDocModel.*;
9
10
public final class AsciiDocToHtml
11
        implements Function<AsciiDocModel, String> {
12
13
    private static String renderBlock(Block block) {
14
        switch (block) {
15 1 1. renderBlock : negated conditional → NO_COVERAGE
            case Heading(_, int level, List<Inline> inlines) -> {
16 1 1. renderBlock : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE
                return String.format("<h%d>%s</h%d>\n", level, renderInlines(inlines), level);
17
            }
18
            case Paragraph(List<String> header, List<Inline> inlines) -> {
19 2 1. renderBlock : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE
2. renderBlock : negated conditional → NO_COVERAGE
                if (header.isEmpty()) return String.format("<p>%s</p>\n", renderInlines(inlines));
20 1 1. renderBlock : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE
                else return String.format("<p class=\"%s\">%s</p>\n", header.getFirst(), renderInlines(inlines));
21
            }
22
            case UnorderedList(List<ListItem> items) -> {
23 1 1. renderBlock : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE
                return "<ul>\n" + items.stream()
24 1 1. lambda$renderBlock$0 : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::lambda$renderBlock$0 → NO_COVERAGE
                                       .map(item -> "  <li>" + renderInlines(item.inlines()) + "</li>\n")
25
                                       .collect(Collectors.joining()) + "</ul>\n";
26
            }
27
            case OrderedList(List<ListItem> items) -> {
28 1 1. renderBlock : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE
                return "<ol>\n" + items.stream()
29 1 1. lambda$renderBlock$1 : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::lambda$renderBlock$1 → NO_COVERAGE
                                       .map(item -> "  <li>" + renderInlines(item.inlines()) + "</li>\n")
30
                                       .collect(Collectors.joining()) + "</ol>\n";
31
            }
32
            case Table(List<Row> rows) -> {
33
                StringBuilder sb = new StringBuilder("<table>\n");
34
                for (Row row : rows) {
35
                    sb.append("  <tr>\n");
36
                    for (Cell cell : row.cells()) {
37
                        sb.append("    <td>")
38
                          .append(cell.blocks()
39
                                      .stream()
40
                                      .map(AsciiDocToHtml::renderBlock)
41
                                      .collect(Collectors.joining()))
42
                          .append("</td>\n");
43
                    }
44
                    sb.append("  </tr>\n");
45
                }
46
                sb.append("</table>\n");
47 1 1. renderBlock : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE
                return sb.toString();
48
            }
49
            case Blockquote(List<Inline> inlines) -> {
50 1 1. renderBlock : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE
                return "<blockquote>" + renderInlines(inlines) + "</blockquote>\n";
51
            }
52
            case CodeBlock(String language, String content) -> {
53 1 1. renderBlock : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE
                return String.format("<pre><code class=\"language-%s\">%s</code></pre>\n", language, content);
54
            }
55
            case ImageBlock(String url, String altText) -> {
56 1 1. renderBlock : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE
                return String.format("<img src=\"%s\" alt=\"%s\">\n", url, altText);
57
            }
58
            default -> { /* DO NOTHING */ }
59
        }
60
        return "";
61
    }
62
63
    private static String renderInlines(List<Inline> inlines) {
64
        StringBuilder sb = new StringBuilder();
65
        for (Inline inline : inlines) {
66
            switch (inline) {
67
                case Text(String text1) -> sb.append(text1);
68
                case Bold(List<Inline> children1) -> sb.append("<b>")
69
                                                       .append(renderInlines(children1))
70
                                                       .append("</b>");
71
                case Italic(List<Inline> children) -> sb.append("<i>")
72
                                                        .append(renderInlines(children))
73
                                                        .append("</i>");
74
                case Tab _ -> sb.append("&nbsp;&nbsp;&nbsp;&nbsp;");
75
                case Link(String url1, String text) -> sb.append(String.format("<a href=\"%s\">%s</a>", url1, text));
76
                case InlineImage(String url, Map<String, String> map) ->
77
                        sb.append(String.format("<img src=\"%s\" alt=\"%s\">", url, map.get("title")));
78
                default -> { /* DO NOTHING */ }
79
            }
80
        }
81 1 1. renderInlines : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderInlines → NO_COVERAGE
        return sb.toString();
82
    }
83
84
    public String apply(AsciiDocModel model) {
85
        StringBuilder html = new StringBuilder();
86
        html.append("<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n</head>\n<body>\n");
87
        for (Block block : model.getBlocks()) {
88
            html.append(renderBlock(block));
89
        }
90
        html.append("</body>\n</html>");
91 1 1. apply : replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::apply → NO_COVERAGE
        return html.toString();
92
    }
93
}

Mutations

15

1.1
Location : renderBlock
Killed by : none
negated conditional → NO_COVERAGE

16

1.1
Location : renderBlock
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE

19

1.1
Location : renderBlock
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE

2.2
Location : renderBlock
Killed by : none
negated conditional → NO_COVERAGE

20

1.1
Location : renderBlock
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE

23

1.1
Location : renderBlock
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE

24

1.1
Location : lambda$renderBlock$0
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::lambda$renderBlock$0 → NO_COVERAGE

28

1.1
Location : renderBlock
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE

29

1.1
Location : lambda$renderBlock$1
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::lambda$renderBlock$1 → NO_COVERAGE

47

1.1
Location : renderBlock
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE

50

1.1
Location : renderBlock
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE

53

1.1
Location : renderBlock
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE

56

1.1
Location : renderBlock
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderBlock → NO_COVERAGE

81

1.1
Location : renderInlines
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::renderInlines → NO_COVERAGE

91

1.1
Location : apply
Killed by : none
replaced return value with "" for pro/verron/officestamper/asciidoc/AsciiDocToHtml::apply → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.22.1