diff --git a/src/main/java/com/github/rjeschke/txtmark/Block.java b/src/main/java/com/github/rjeschke/txtmark/Block.java index ab3819b..2f8be98 100644 --- a/src/main/java/com/github/rjeschke/txtmark/Block.java +++ b/src/main/java/com/github/rjeschke/txtmark/Block.java @@ -17,25 +17,25 @@ package com.github.rjeschke.txtmark; /** * This class represents a block of lines. - * + * * @author René Jeschke */ class Block { /** This block's type. */ - public BlockType type = BlockType.NONE; + public BlockType type = BlockType.NONE; /** Head and tail of linked lines. */ - public Line lines = null, lineTail = null; + public Line lines = null, lineTail = null; /** Head and tail of child blocks. */ - public Block blocks = null, blockTail = null; + public Block blocks = null, blockTail = null; /** Next block. */ - public Block next = null; + public Block next = null; /** Depth of headline BlockType. */ - public int hlDepth = 0; + public int hlDepth = 0; /** ID for headlines and list items */ - public String id = null; + public String id = null; /** Block meta information */ - public String meta = ""; + public String meta = ""; /** Constructor. */ public Block() @@ -56,7 +56,7 @@ class Block */ public void removeSurroundingEmptyLines() { - if(this.lines != null) + if (this.lines != null) { this.removeTrailingEmptyLines(); this.removeLeadingEmptyLines(); @@ -68,31 +68,41 @@ class Block */ public void transfromHeadline() { - if(this.hlDepth > 0) + if (this.hlDepth > 0) + { return; + } int level = 0; final Line line = this.lines; - if(line.isEmpty) + if (line.isEmpty) + { return; + } int start = line.leading; - while(start < line.value.length() && line.value.charAt(start) == '#') + while (start < line.value.length() && line.value.charAt(start) == '#') { level++; start++; } - while(start < line.value.length() && line.value.charAt(start) == ' ') + while (start < line.value.length() && line.value.charAt(start) == ' ') + { start++; - if(start >= line.value.length()) + } + if (start >= line.value.length()) { line.setEmpty(); } else { int end = line.value.length() - line.trailing - 1; - while(line.value.charAt(end) == '#') + while (line.value.charAt(end) == '#') + { end--; - while(line.value.charAt(end) == ' ') + } + while (line.value.charAt(end) == ' ') + { end--; + } line.value = line.value.substring(start, end + 1); line.leading = line.trailing = 0; } @@ -101,18 +111,19 @@ class Block /** * Used for nested lists. Removes list markers and up to 4 leading spaces. - * - * @param extendedMode - * Whether extended profile ist activated or not + * + * @param configuration + * txtmark configuration + * */ - public void removeListIndent(boolean extendedMode) + public void removeListIndent(final Configuration configuration) { Line line = this.lines; - while(line != null) + while (line != null) { - if(!line.isEmpty) + if (!line.isEmpty) { - switch(line.getLineType(extendedMode)) + switch (line.getLineType(configuration)) { case ULIST: line.value = line.value.substring(line.leading + 2); @@ -136,15 +147,17 @@ class Block public void removeBlockQuotePrefix() { Line line = this.lines; - while(line != null) + while (line != null) { - if(!line.isEmpty) + if (!line.isEmpty) { - if(line.value.charAt(line.leading) == '>') + if (line.value.charAt(line.leading) == '>') { int rem = line.leading + 1; - if(line.leading + 1 < line.value.length() && line.value.charAt(line.leading + 1) == ' ') + if (line.leading + 1 < line.value.length() && line.value.charAt(line.leading + 1) == ' ') + { rem++; + } line.value = line.value.substring(rem); line.initLeading(); } @@ -155,14 +168,14 @@ class Block /** * Removes leading empty lines. - * + * * @return true if an empty line was removed. */ public boolean removeLeadingEmptyLines() { boolean wasEmpty = false; Line line = this.lines; - while(line != null && line.isEmpty) + while (line != null && line.isEmpty) { this.removeLine(line); line = this.lines; @@ -177,7 +190,7 @@ class Block public void removeTrailingEmptyLines() { Line line = this.lineTail; - while(line != null && line.isEmpty) + while (line != null && line.isEmpty) { this.removeLine(line); line = this.lineTail; @@ -187,7 +200,7 @@ class Block /** * Splits this block's lines, creating a new child block having 'line' as * it's lineTail. - * + * * @param line * The line to split from. * @return The newly created Block. @@ -200,13 +213,19 @@ class Block block.lineTail = line; this.lines = line.next; line.next = null; - if(this.lines == null) + if (this.lines == null) + { this.lineTail = null; + } else + { this.lines.previous = null; + } - if(this.blocks == null) + if (this.blocks == null) + { this.blocks = this.blockTail = block; + } else { this.blockTail.next = block; @@ -218,33 +237,43 @@ class Block /** * Removes the given line from this block. - * + * * @param line * Line to remove. */ public void removeLine(final Line line) { - if(line.previous == null) + if (line.previous == null) + { this.lines = line.next; + } else + { line.previous.next = line.next; - if(line.next == null) + } + if (line.next == null) + { this.lineTail = line.previous; + } else + { line.next.previous = line.previous; + } line.previous = line.next = null; } /** * Appends the given line to this block. - * + * * @param line * Line to append. */ public void appendLine(final Line line) { - if(this.lineTail == null) + if (this.lineTail == null) + { this.lines = this.lineTail = line; + } else { this.lineTail.nextEmpty = line.isEmpty; @@ -261,20 +290,20 @@ class Block */ public void expandListParagraphs() { - if(this.type != BlockType.ORDERED_LIST && this.type != BlockType.UNORDERED_LIST) + if (this.type != BlockType.ORDERED_LIST && this.type != BlockType.UNORDERED_LIST) { return; } Block outer = this.blocks, inner; boolean hasParagraph = false; - while(outer != null && !hasParagraph) + while (outer != null && !hasParagraph) { - if(outer.type == BlockType.LIST_ITEM) + if (outer.type == BlockType.LIST_ITEM) { inner = outer.blocks; - while(inner != null && !hasParagraph) + while (inner != null && !hasParagraph) { - if(inner.type == BlockType.PARAGRAPH) + if (inner.type == BlockType.PARAGRAPH) { hasParagraph = true; } @@ -283,17 +312,17 @@ class Block } outer = outer.next; } - if(hasParagraph) + if (hasParagraph) { outer = this.blocks; - while(outer != null) + while (outer != null) { - if(outer.type == BlockType.LIST_ITEM) + if (outer.type == BlockType.LIST_ITEM) { inner = outer.blocks; - while(inner != null) + while (inner != null) { - if(inner.type == BlockType.NONE) + if (inner.type == BlockType.NONE) { inner.type = BlockType.PARAGRAPH; } diff --git a/src/main/java/com/github/rjeschke/txtmark/Configuration.java b/src/main/java/com/github/rjeschke/txtmark/Configuration.java index 17984bb..b2bdbb6 100644 --- a/src/main/java/com/github/rjeschke/txtmark/Configuration.java +++ b/src/main/java/com/github/rjeschke/txtmark/Configuration.java @@ -17,25 +17,26 @@ package com.github.rjeschke.txtmark; /** * Txtmark configuration. - * + * * @author René Jeschke <rene_jeschke@yahoo.de> * @since 0.7 */ public class Configuration { - final boolean safeMode; - final String encoding; - final Decorator decorator; - final BlockEmitter codeBlockEmitter; - final boolean forceExtendedProfile; - final SpanEmitter specialLinkEmitter; + final boolean safeMode; + final String encoding; + final Decorator decorator; + final BlockEmitter codeBlockEmitter; + final boolean forceExtendedProfile; + final boolean allowSpacesInFencedDelimiters; + final SpanEmitter specialLinkEmitter; /** *

* This is the default configuration for txtmark's process * methods *

- * + * * */ - public final static Configuration DEFAULT = Configuration.builder().build(); + public final static Configuration DEFAULT = Configuration.builder().build(); /** *

* Default safe configuration *

- * + * *