}
private void updateCursorPosition(int character) {
+ //see Java Language Specification : http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.4
if (character == LF || character == CR) {
if ((lastChar != LF && lastChar != CR) || lastChar == character || lastChar == LF) {
cursor.line++;
private static final String CSS_PATH = "/sonar-colorizer.css";
private HtmlOptions options;
- private int lineId = 1;
+ private int lineId;
private static final int LF = (int) '\n';
private static final int CR = (int) '\r';
@Override
public boolean consume(CodeReader code, HtmlCodeBuilder codeBuilder) {
- int currentChar = code.peek();
-
- if (currentChar == LF) {
- codeBuilder.appendWithoutTransforming(getTagAfter());
- codeBuilder.appendWithoutTransforming(getTagBefore());
- }
-
- if (currentChar == LF || currentChar == CR) {
+ int lineNumber = code.getLinePosition();
+ if (code.peek() == LF || code.peek() == CR) {
code.pop();
+ if (lineNumber != code.getLinePosition()) {
+ codeBuilder.appendWithoutTransforming(getTagAfter());
+ codeBuilder.appendWithoutTransforming(getTagBefore());
+ }
return true;
}
-
return false;
}
public void shouldAddTagsBetweenEachLine() {
HtmlOptions options = new HtmlOptions().setGenerateTable(true).setGenerateHtmlHeader(false);
HtmlDecorator decorator = new HtmlDecorator(options);
- CodeReader code = new CodeReader("\n\r\n");
+ CodeReader code = new CodeReader("\r\n\r");
HtmlCodeBuilder output = new HtmlCodeBuilder();
output.appendWithoutTransforming(decorator.getTagBeginOfFile());