]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/documentation/Preformatted.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / parsing / documentation / Preformatted.java
1 package org.simantics.scl.compiler.internal.parsing.documentation;
2
3 public class Preformatted extends DocumentationElement {
4
5     String[] lines;
6     
7     public Preformatted(String content) {
8         lines = content.split("\n");
9         int indentation = Integer.MAX_VALUE;
10         for(int i=0;i<lines.length;++i) {
11             String line = lines[i];
12             for(int j=line.length();j>0;--j) {
13                 char c = line.charAt(j-1);
14                 if(c != '\n' && c != '\r' && c != ' ') {
15                     line = line.substring(0, j);
16                     break;
17                 }
18             }
19             lines[i] = line;
20         }
21         for(String line : lines) {
22             for(int i=1;i<line.length()&&i<indentation;++i)
23                 if(line.charAt(i) != ' ') {
24                     indentation = i;
25                     break;
26                 }
27         }
28         for(int i=0;i<lines.length;++i) {
29             String line = lines[i];
30             lines[i] = indentation > line.length() ? "" : line.substring(indentation);
31         }
32     }
33
34     @Override
35     public void toHtml(HtmlUnparsingContext context) {
36         context.clear();
37         StringBuilder b = context.getStringBuilder();
38         b.append("<pre>\n");
39         for(String line : lines)
40             b.append(line).append('\n');
41         b.append("</pre>\n");
42     }
43
44 }