Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Wahlbrink2015-07-10 19:06:16 +0000
committerGerrit Code Review @ Eclipse.org2015-07-10 20:12:37 +0000
commit42af2d8e1f54279f565696db58fd5a77022c2e5a (patch)
treee0d825f396b9e622eafdd112aedfe82b2f544f6e
parent6d7d07d455f67dc88c2c22ec4fcb7f98bc116f31 (diff)
downloadorg.eclipse.mylyn.docs-42af2d8e1f54279f565696db58fd5a77022c2e5a.tar.gz
org.eclipse.mylyn.docs-42af2d8e1f54279f565696db58fd5a77022c2e5a.tar.xz
org.eclipse.mylyn.docs-42af2d8e1f54279f565696db58fd5a77022c2e5a.zip
472386: [CommonMark] Fix pattern for AtxHeader
Task-Url: https://bugs.eclipse.org/472386 Change-Id: I16d404e9fca32dffee05108e3acb37463f657de9 Signed-off-by: Stephan Wahlbrink <sw@wahlbrink.eu>
-rw-r--r--org.eclipse.mylyn.wikitext.commonmark.tests/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/AtxHeaderBlockTest.java8
-rw-r--r--org.eclipse.mylyn.wikitext.commonmark/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/AtxHeaderBlock.java6
2 files changed, 11 insertions, 3 deletions
diff --git a/org.eclipse.mylyn.wikitext.commonmark.tests/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/AtxHeaderBlockTest.java b/org.eclipse.mylyn.wikitext.commonmark.tests/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/AtxHeaderBlockTest.java
index 513c8798f..0f9bd2b83 100644
--- a/org.eclipse.mylyn.wikitext.commonmark.tests/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/AtxHeaderBlockTest.java
+++ b/org.eclipse.mylyn.wikitext.commonmark.tests/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/AtxHeaderBlockTest.java
@@ -37,6 +37,12 @@ public class AtxHeaderBlockTest {
assertTrue(block.canStart(LineSequence.create("###### Y")));
assertFalse(block.canStart(LineSequence.create("####### Y")));
assertTrue(block.canStart(LineSequence.create("# Y#")));
+ assertFalse(block.canStart(LineSequence.create("#Y")));
+
+ // Bug 472386:
+ assertTrue(block.canStart(LineSequence.create("# #Y")));
+ assertTrue(block.canStart(LineSequence.create(" # Y")));
+ assertFalse(block.canStart(LineSequence.create("\t# Y")));
}
@Test
@@ -44,6 +50,7 @@ public class AtxHeaderBlockTest {
assertContent("<h2 id=\"one-two\">One Two</h2>", "## One Two");
assertContent("<h2 id=\"one-two\">One Two</h2>", "## One Two ##### ");
assertContent("<h2 id=\"one-two\">One Two#</h2>", "## One Two#");
+ assertContent("<h2 id=\"one-two\">#One #Two</h2>", "## #One #Two");
assertContent("<p>One</p><h1 id=\"two\">two</h1><p>Three</p>", "One\n# two\nThree");
assertContent("<h2></h2>", "##");
assertContent("<h2></h2>", "## ##");
@@ -54,4 +61,5 @@ public class AtxHeaderBlockTest {
assertContent("<h2 id=\"one-two-three\">One <em>Two</em> \\<strong>three</strong></h2>",
"## One *Two* \\\\__three__ ##");
}
+
}
diff --git a/org.eclipse.mylyn.wikitext.commonmark/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/AtxHeaderBlock.java b/org.eclipse.mylyn.wikitext.commonmark/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/AtxHeaderBlock.java
index 56c3f86df..9cd11bfd5 100644
--- a/org.eclipse.mylyn.wikitext.commonmark/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/AtxHeaderBlock.java
+++ b/org.eclipse.mylyn.wikitext.commonmark/src/org/eclipse/mylyn/internal/wikitext/commonmark/blocks/AtxHeaderBlock.java
@@ -28,12 +28,12 @@ import org.eclipse.mylyn.wikitext.core.parser.HeadingAttributes;
public class AtxHeaderBlock extends SourceBlock {
- private final Pattern pattern = Pattern.compile("\\s{0,3}(#{1,6})(?:\\s+([^#\\s].*?))?(\\s+#*)?\\s*");
+ private static final Pattern PATTERN = Pattern.compile(" {0,3}(#{1,6})(?:[ \t]+?(.+?))??(?:[ \t]+#+)?[ \t]*");
@Override
public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) {
Line currentLine = lineSequence.getCurrentLine();
- Matcher matcher = pattern.matcher(currentLine.getText());
+ Matcher matcher = PATTERN.matcher(currentLine.getText());
checkState(matcher.matches());
lineSequence.advance();
@@ -72,7 +72,7 @@ public class AtxHeaderBlock extends SourceBlock {
@Override
public boolean canStart(LineSequence lineSequence) {
Line line = lineSequence.getCurrentLine();
- return line != null && pattern.matcher(line.getText()).matches();
+ return line != null && PATTERN.matcher(line.getText()).matches();
}
}

Back to the top