diff options
author | Stephan Wahlbrink | 2015-07-10 19:28:36 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2015-07-10 20:14:42 +0000 |
commit | e5418f47bfa5a02e15078d7f31819c30578af890 (patch) | |
tree | 02928ce2cc7247c7482f72e95b1a260b7be09bc8 | |
parent | 42af2d8e1f54279f565696db58fd5a77022c2e5a (diff) | |
download | org.eclipse.mylyn.docs-e5418f47bfa5a02e15078d7f31819c30578af890.tar.gz org.eclipse.mylyn.docs-e5418f47bfa5a02e15078d7f31819c30578af890.tar.xz org.eclipse.mylyn.docs-e5418f47bfa5a02e15078d7f31819c30578af890.zip |
472395: [CommonMark] Fix pattern for IndentedCodeBlock
Task-Url: https://bugs.eclipse.org/472395
Change-Id: I5c0aeebcd2df4c6e4b319059420cbeb6a3c5efda
Signed-off-by: Stephan Wahlbrink <sw@wahlbrink.eu>
2 files changed, 11 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.wikitext.commonmark.tests/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/IndentedCodeBlockTest.java b/org.eclipse.mylyn.wikitext.commonmark.tests/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/IndentedCodeBlockTest.java index e69bfefaa..0260d5a3a 100644 --- a/org.eclipse.mylyn.wikitext.commonmark.tests/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/IndentedCodeBlockTest.java +++ b/org.eclipse.mylyn.wikitext.commonmark.tests/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/IndentedCodeBlockTest.java @@ -42,9 +42,13 @@ public class IndentedCodeBlockTest { assertContent("<pre><code>code\n</code></pre>", " code"); assertContent("<pre><code>code\n</code></pre>", "\tcode"); assertContent("<pre><code> code\n</code></pre>", "\t code"); + assertContent("<pre><code>code \n</code></pre>", "\tcode "); assertContent("<pre><code>\tcode\n</code></pre>", " \tcode"); assertContent("<pre><code>one\ntwo\n</code></pre><p>three</p>", " one\n two\n three"); assertContent("<pre><code>one\n\nthree\n</code></pre>", " one\n\n three"); assertContent("<pre><code>one\n \nthree\n</code></pre>", " one\n \n three"); + + // Bug 472395: + assertContent("<pre><code>\t\tcode\n</code></pre>", "\t\t\tcode"); } } diff --git a/org.eclipse.mylyn.wikitext.commonmark/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/IndentedCodeBlock.java b/org.eclipse.mylyn.wikitext.commonmark/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/IndentedCodeBlock.java index 09f4de5c6..3f05cde28 100644 --- a/org.eclipse.mylyn.wikitext.commonmark/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/IndentedCodeBlock.java +++ b/org.eclipse.mylyn.wikitext.commonmark/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/IndentedCodeBlock.java @@ -30,7 +30,7 @@ import com.google.common.base.Predicates; public class IndentedCodeBlock extends SourceBlock { - private final Pattern linePattern = Pattern.compile("(?:\\s{0,2}\t|(\\s{4}))(.*)"); + private static final Pattern PATTERN = Pattern.compile("(?: {0,3}\t| {4})(.*)"); @Override public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) { @@ -38,18 +38,18 @@ public class IndentedCodeBlock extends SourceBlock { builder.beginBlock(BlockType.CODE, new Attributes()); boolean blockHasContent = false; - Iterator<Line> iterator = lineSequence.with( - Predicates.or(LinePredicates.matches(linePattern), LinePredicates.empty())).iterator(); + Iterator<Line> iterator = lineSequence + .with(Predicates.or(LinePredicates.matches(PATTERN), LinePredicates.empty())).iterator(); while (iterator.hasNext()) { Line line = iterator.next(); - Matcher matcher = linePattern.matcher(line.getText()); + Matcher matcher = PATTERN.matcher(line.getText()); if (!matcher.matches()) { checkState(line.isEmpty()); if (iterator.hasNext()) { builder.characters("\n"); } } else { - String content = matcher.group(2); + String content = matcher.group(1); if (!content.isEmpty() || (blockHasContent && iterator.hasNext())) { blockHasContent = true; builder.characters(content); @@ -63,6 +63,7 @@ public class IndentedCodeBlock extends SourceBlock { @Override public boolean canStart(LineSequence lineSequence) { Line line = lineSequence.getCurrentLine(); - return line != null && linePattern.matcher(line.getText()).matches(); + return line != null && PATTERN.matcher(line.getText()).matches(); } + } |