Skip to content

Commit

Permalink
Merge pull request #308 from commonmark/spec-0.31
Browse files Browse the repository at this point in the history
Update spec to 0.31.2
  • Loading branch information
robinst authored Mar 9, 2024
2 parents 4db8bba + a8af670 commit 1209160
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 167 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.commonmark.integration;

import org.commonmark.Extension;
import org.commonmark.ext.autolink.AutolinkExtension;
import org.commonmark.ext.front.matter.YamlFrontMatterExtension;
import org.commonmark.ext.gfm.strikethrough.StrikethroughExtension;
import org.commonmark.ext.gfm.tables.TablesExtension;
import org.commonmark.ext.image.attributes.ImageAttributesExtension;
import org.commonmark.ext.ins.InsExtension;
import org.commonmark.ext.task.list.items.TaskListItemsExtension;

import java.util.Arrays;
import java.util.List;

public class Extensions {

static final List<Extension> ALL_EXTENSIONS = Arrays.asList(
AutolinkExtension.create(),
ImageAttributesExtension.create(),
InsExtension.create(),
StrikethroughExtension.create(),
TablesExtension.create(),
TaskListItemsExtension.create(),
YamlFrontMatterExtension.create());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.commonmark.integration;

import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.commonmark.testutil.RenderingTestCase;
import org.junit.Test;

/**
* Tests to ensure all extensions work well together.
*/
public class ExtensionsIntegrationTest extends RenderingTestCase {

protected static final Parser PARSER = Parser.builder()
.extensions(Extensions.ALL_EXTENSIONS)
.build();
protected static final HtmlRenderer RENDERER = HtmlRenderer.builder()
.extensions(Extensions.ALL_EXTENSIONS)
.percentEncodeUrls(true)
.build();

@Test
public void testImageAttributes() {
assertRendering("![text](/url.png){height=5 width=6}", "<p><img src=\"/url.png\" alt=\"text\" height=\"5\" width=\"6\" /></p>\n");
}

@Test
public void testTaskListItems() {
assertRendering("- [ ] task to do\n- [x] task done\n",
"<ul>\n<li><input type=\"checkbox\" disabled=\"\"> task to do</li>\n" +
"<li><input type=\"checkbox\" disabled=\"\" checked=\"\"> task done</li>\n</ul>\n");

}

protected String render(String source) {
return RENDERER.render(PARSER.parse(source));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class SourceSpanIntegrationTest extends SpecIntegrationTest {

protected static final Parser PARSER = Parser.builder()
.extensions(EXTENSIONS)
.extensions(Extensions.ALL_EXTENSIONS)
.includeSourceSpans(IncludeSourceSpans.BLOCKS)
.build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
package org.commonmark.integration;

import org.commonmark.Extension;
import org.commonmark.ext.autolink.AutolinkExtension;
import org.commonmark.ext.image.attributes.ImageAttributesExtension;
import org.commonmark.ext.ins.InsExtension;
import org.commonmark.ext.gfm.strikethrough.StrikethroughExtension;
import org.commonmark.ext.gfm.tables.TablesExtension;
import org.commonmark.ext.front.matter.YamlFrontMatterExtension;
import org.commonmark.ext.task.list.items.TaskListItemsExtension;
import org.commonmark.renderer.html.HtmlRenderer;
import org.commonmark.parser.Parser;
import org.commonmark.testutil.example.Example;
import org.commonmark.testutil.SpecTestCase;
import org.junit.Assert;
import org.junit.Test;

import java.util.*;
Expand All @@ -24,17 +15,9 @@
*/
public class SpecIntegrationTest extends SpecTestCase {

protected static final List<Extension> EXTENSIONS = Arrays.asList(
AutolinkExtension.create(),
ImageAttributesExtension.create(),
InsExtension.create(),
StrikethroughExtension.create(),
TablesExtension.create(),
TaskListItemsExtension.create(),
YamlFrontMatterExtension.create());
protected static final Parser PARSER = Parser.builder().extensions(EXTENSIONS).build();
protected static final Parser PARSER = Parser.builder().extensions(Extensions.ALL_EXTENSIONS).build();
// The spec says URL-escaping is optional, but the examples assume that it's enabled.
protected static final HtmlRenderer RENDERER = HtmlRenderer.builder().extensions(EXTENSIONS).percentEncodeUrls(true).build();
protected static final HtmlRenderer RENDERER = HtmlRenderer.builder().extensions(Extensions.ALL_EXTENSIONS).percentEncodeUrls(true).build();
protected static final Map<String, String> OVERRIDDEN_EXAMPLES = getOverriddenExamples();

public SpecIntegrationTest(Example example) {
Expand All @@ -59,7 +42,7 @@ private static Map<String, String> getOverriddenExamples() {
Map<String, String> m = new HashMap<>();

// Not a spec autolink because of space, but the resulting text contains a valid URL
m.put("<http://foo.bar/baz bim>\n", "<p>&lt;<a href=\"http://foo.bar/baz\">http://foo.bar/baz</a> bim&gt;</p>\n");
m.put("<https://foo.bar/baz bim>\n", "<p>&lt;<a href=\"https://foo.bar/baz\">https://foo.bar/baz</a> bim&gt;</p>\n");

// Not a spec autolink, but the resulting text contains a valid email
m.put("<foo\\[email protected]>\n", "<p>&lt;<a href=\"mailto:[email protected]\">[email protected]</a>&gt;</p>\n");
Expand All @@ -68,10 +51,10 @@ private static Map<String, String> getOverriddenExamples() {
m.put("<heck://bing.bong>\n", "<p>&lt;<a href=\"heck://bing.bong%3E\">heck://bing.bong&gt;</a></p>\n");

// Not a spec autolink because of spaces, but autolink extension doesn't limit schemes
m.put("< http://foo.bar >\n", "<p>&lt; <a href=\"http://foo.bar\">http://foo.bar</a> &gt;</p>\n");
m.put("< https://foo.bar >\n", "<p>&lt; <a href=\"https://foo.bar\">https://foo.bar</a> &gt;</p>\n");

// Plain autolink
m.put("http://example.com\n", "<p><a href=\"http://example.com\">http://example.com</a></p>\n");
m.put("https://example.com\n", "<p><a href=\"https://example.com\">https://example.com</a></p>\n");

// Plain autolink
m.put("[email protected]\n", "<p><a href=\"mailto:[email protected]\">[email protected]</a></p>\n");
Expand All @@ -80,13 +63,6 @@ private static Map<String, String> getOverriddenExamples() {
m.put("---\nFoo\n---\nBar\n---\nBaz\n", "<h2>Bar</h2>\n<p>Baz</p>\n");
m.put("---\n---\n", "");

// Image attributes
m.put("![text](/url.png){height=5 width=6}", "<img src=\"/url.png\" alt=\"text\" height=\"5\" width=\"6\" />");

// Task list items
m.put("- [ ] task to do\n- [x] task done\n", "<ul>\n<li><input type=\"checkbox\" disabled=\"\"> task to do</li>\n" +
"<li><input type=\"checkbox\" disabled=\"\" checked=\"\"> task done</li>\n</ul>\n");

return m;
}

Expand Down
66 changes: 26 additions & 40 deletions commonmark-test-util/src/main/resources/gfm-spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ questions it does not answer:
not require that. This is hardly a "corner case," and divergences
between implementations on this issue often lead to surprises for
users in real documents. (See [this comment by John
Gruber](http://article.gmane.org/gmane.text.markdown.general/1997).)
Gruber](https://web.archive.org/web/20170611172104/http://article.gmane.org/gmane.text.markdown.general/1997).)

2. Is a blank line needed before a block quote or heading?
Most implementations do not require the blank line. However,
this can lead to unexpected results in hard-wrapped text, and
also to ambiguities in parsing (note that some implementations
put the heading inside the blockquote, while others do not).
(John Gruber has also spoken [in favor of requiring the blank
lines](http://article.gmane.org/gmane.text.markdown.general/2146).)
lines](https://web.archive.org/web/20170611172104/http://article.gmane.org/gmane.text.markdown.general/2146).)

3. Is a blank line needed before an indented code block?
(`Markdown.pl` requires it, but this is not mentioned in the
Expand Down Expand Up @@ -171,7 +171,7 @@ questions it does not answer:
```

(There are some relevant comments by John Gruber
[here](http://article.gmane.org/gmane.text.markdown.general/2554).)
[here](https://web.archive.org/web/20170611172104/http://article.gmane.org/gmane.text.markdown.general/2554).)

5. Can list markers be indented? Can ordered list markers be right-aligned?

Expand Down Expand Up @@ -1001,10 +1001,7 @@ interpretable as a [code fence], [ATX heading][ATX headings],

A [setext heading underline](@) is a sequence of
`=` characters or a sequence of `-` characters, with no more than 3
spaces indentation and any number of trailing spaces. If a line
containing a single `-` can be interpreted as an
empty [list items], it should be interpreted this way
and not as a [setext heading underline].
spaces of indentation and any number of trailing spaces or tabs.

The heading is a level 1 heading if `=` characters are used in
the [setext heading underline], and a level 2 heading if `-`
Expand Down Expand Up @@ -1638,7 +1635,7 @@ has been found, the code block contains all of the lines after the
opening code fence until the end of the containing block (or
document). (An alternative spec would require backtracking in the
event that a closing code fence is not found. But this makes parsing
much less efficient, and there seems to be no real down side to the
much less efficient, and there seems to be no real downside to the
behavior described here.)

A fenced code block may interrupt a paragraph, and does not require
Expand Down Expand Up @@ -2068,7 +2065,7 @@ followed by an uppercase ASCII letter.\
`<![CDATA[`.\
**End condition:** line contains the string `]]>`.

6. **Start condition:** line begins the string `<` or `</`
6. **Start condition:** line begins with the string `<` or `</`
followed by one of the strings (case-insensitive) `address`,
`article`, `aside`, `base`, `basefont`, `blockquote`, `body`,
`caption`, `center`, `col`, `colgroup`, `dd`, `details`, `dialog`,
Expand Down Expand Up @@ -5279,7 +5276,7 @@ well. ([reStructuredText](http://docutils.sourceforge.net/rst.html)
takes a different approach, requiring blank lines before lists
even inside other list items.)

In order to solve of unwanted lists in paragraphs with
In order to solve the problem of unwanted lists in paragraphs with
hard-wrapped numerals, we allow only lists starting with `1` to
interrupt paragraphs. Thus,

Expand Down Expand Up @@ -6929,7 +6926,7 @@ foo__bar__
```````````````````````````````` example
__foo, __bar__, baz__
.
<p><strong>foo, <strong>bar</strong>, baz</strong></p>
<p><strong>foo, bar, baz</strong></p>
````````````````````````````````


Expand Down Expand Up @@ -7200,7 +7197,7 @@ foo***bar***baz
```````````````````````````````` example
foo******bar*********baz
.
<p>foo<strong><strong><strong>bar</strong></strong></strong>***baz</p>
<p>foo<strong>bar</strong>***baz</p>
````````````````````````````````


Expand Down Expand Up @@ -7271,21 +7268,21 @@ __foo _bar_ baz__
```````````````````````````````` example
__foo __bar__ baz__
.
<p><strong>foo <strong>bar</strong> baz</strong></p>
<p><strong>foo bar baz</strong></p>
````````````````````````````````


```````````````````````````````` example
____foo__ bar__
.
<p><strong><strong>foo</strong> bar</strong></p>
<p><strong>foo bar</strong></p>
````````````````````````````````


```````````````````````````````` example
**foo **bar****
.
<p><strong>foo <strong>bar</strong></strong></p>
<p><strong>foo bar</strong></p>
````````````````````````````````


Expand Down Expand Up @@ -7570,14 +7567,14 @@ switching delimiters:
```````````````````````````````` example
****foo****
.
<p><strong><strong>foo</strong></strong></p>
<p><strong>foo</strong></p>
````````````````````````````````


```````````````````````````````` example
____foo____
.
<p><strong><strong>foo</strong></strong></p>
<p><strong>foo</strong></p>
````````````````````````````````


Expand All @@ -7588,7 +7585,7 @@ delimiters:
```````````````````````````````` example
******foo******
.
<p><strong><strong><strong>foo</strong></strong></strong></p>
<p><strong>foo</strong></p>
````````````````````````````````


Expand All @@ -7604,7 +7601,7 @@ Rule 14:
```````````````````````````````` example
_____foo_____
.
<p><em><strong><strong>foo</strong></strong></em></p>
<p><em><strong>foo</strong></em></p>
````````````````````````````````


Expand Down Expand Up @@ -9410,10 +9407,9 @@ character, and a `>` character.
A [closing tag](@) consists of the string `</`, a
[tag name], optional [whitespace], and the character `>`.

An [HTML comment](@) consists of `<!--` + *text* + `-->`,
where *text* does not start with `>` or `->`, does not end with `-`,
and does not contain `--`. (See the
[HTML5 spec](http://www.w3.org/TR/html5/syntax.html#comments).)
An [HTML comment](@) consists of `<!-->`, `<!--->`, or `<!--`, a string of
characters not including the string `-->`, and `-->` (see the
[HTML spec](https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state)).

A [processing instruction](@)
consists of the string `<?`, a string
Expand Down Expand Up @@ -9554,30 +9550,20 @@ Illegal attributes in closing tag:
Comments:

```````````````````````````````` example
foo <!-- this is a
comment - with hyphen -->
foo <!-- this is a --
comment - with hyphens -->
.
<p>foo <!-- this is a
comment - with hyphen --></p>
<p>foo <!-- this is a --
comment - with hyphens --></p>
````````````````````````````````


```````````````````````````````` example
foo <!-- not a comment -- two hyphens -->
.
<p>foo &lt;!-- not a comment -- two hyphens --&gt;</p>
````````````````````````````````


Not comments:

```````````````````````````````` example
foo <!--> foo -->

foo <!-- foo--->
foo <!---> foo -->
.
<p>foo &lt;!--&gt; foo --&gt;</p>
<p>foo &lt;!-- foo---&gt;</p>
<p>foo <!--> foo --&gt;</p>
<p>foo <!---> foo --&gt;</p>
````````````````````````````````


Expand Down
Loading

0 comments on commit 1209160

Please sign in to comment.