Skip to content

Commit

Permalink
Fix for ident of xml and json.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbellus committed Mar 6, 2017
1 parent e6513a5 commit edb35b6
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private String IdentXml(String content) {

try {

Source xmlInput = new StreamSource(new StringReader(compact(content, false, false)));
Source xmlInput = new StreamSource(new StringReader(compact(content, false, false, false)));
StringWriter stringWriter = new StringWriter();
StreamResult xmlOutput = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Expand Down Expand Up @@ -181,7 +181,7 @@ private static SymbolType closeType(char beginner) {
: beginner == '{' ? SymbolType.CloseBrace : SymbolType.CloseParenthesis;
}

private String compact(String input, Boolean keepNewLines, Boolean keepSpaces) {
private String compact(String input, Boolean keepNewLines, Boolean keepSpaces, Boolean transforToQuotString) {
BufferedReader reader = new BufferedReader(new StringReader(input));
StringBuffer result = new StringBuffer();

Expand All @@ -193,8 +193,10 @@ private String compact(String input, Boolean keepNewLines, Boolean keepSpaces) {
line = line.trim();
}

line = line.replaceAll("&", "&");
line = line.replaceAll("\"", """);
if (transforToQuotString) {
line = line.replaceAll("&", "&");
line = line.replaceAll("\"", """);
}

if (keepNewLines) {
line += "&\\n;";
Expand Down Expand Up @@ -232,7 +234,7 @@ public String toTarget(Translator translator, Symbol symbol) {
keepSpaces = false;
}

String originalContent = compact(symbol.getProperty("content"), keepNewLines, keepSpaces);
String originalContent = compact(symbol.getProperty("content"), keepNewLines, keepSpaces, true);
listingSection.addAttribute("originalcontent", originalContent);
listingSection.add(new RawHtml(
"<script src=\"/files/fitnesse/code-prettify/run_prettify.js\" type=\"text/javascript\"></script>"));
Expand Down

0 comments on commit edb35b6

Please sign in to comment.