Skip to content

Commit

Permalink
feat(gcc-facade): Respect indents by spaces
Browse files Browse the repository at this point in the history
As the HTML instructions would just ignore leading spaces, we make them
non-breaking-spaces instead, now.
  • Loading branch information
mmichaelis committed Jan 23, 2025
1 parent 2718440 commit 1d8b9f3
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public enum TextType {
* Signals HTML content.
*/
HTML {
private static final String SPACE_INDENT = " ";
private static final String TAB_INDENT = "    ";
private static final Pattern NEWLINE_PATTERN = Pattern.compile("\\R");
private static final Pattern LEADING_SPACES = Pattern.compile("(?m)^\\s+");

/**
* Transforms the given plain-text to the expected HTML.
Expand All @@ -41,6 +43,9 @@ public String transformText(@NonNull String text) {
.replace(">", ">")
.replace("\"", """)
.replace("\t", TAB_INDENT);
// For all leading spaces in each line, replace with non-breaking spaces.
// This is meant to keep the indentation.
result = LEADING_SPACES.matcher(result).replaceAll(SPACE_INDENT);
return NEWLINE_PATTERN.matcher(result).replaceAll("<br>");
}
},
Expand Down

0 comments on commit 1d8b9f3

Please sign in to comment.