Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html),
with the exception that 0.x versions can break between minor versions.

## Unreleased
### Fixed
- footnotes: Fix parsing of footnote definitions containing multiple paragraphs
separated by blank lines. Before it only worked if paragraphs were separated
by lines of 4 spaces. (#388)

## [0.25.0] - 2025-06-20
### Added
- Include OSGi metadata in jars (`META-INF/MANIFEST.MF` files) (#378)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public BlockContinue tryContinue(ParserState parserState) {
if (parserState.getIndent() >= 4) {
// It looks like content needs to be indented by 4 so that it's part of a footnote (instead of starting a new block).
return BlockContinue.atColumn(4);
} else if (parserState.isBlank()) {
// A blank line doesn't finish a footnote yet. If there's another line with indent >= 4 after it,
// that should result in another paragraph in this footnote definition.
return BlockContinue.atIndex(parserState.getIndex());
} else {
// We're not continuing to give other block parsers a chance to interrupt this definition.
// But if no other block parser applied (including another FootnotesBlockParser), we will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ private void renderDefinition(FootnoteDefinition def) {
writer.raw("]: ");

writer.pushPrefix(" ");
writer.pushTight(true);
renderChildren(def);
writer.popTight();
writer.popPrefix();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void testSimple() {
@Test
public void testUnreferenced() {
// Whether a reference has a corresponding definition or vice versa shouldn't matter for Markdown rendering.
assertRoundTrip("Test [^foo]\n\n[^foo]: one\n[^bar]: two\n");
assertRoundTrip("Test [^foo]\n\n[^foo]: one\n\n[^bar]: two\n");
}

@Test
Expand All @@ -36,6 +36,18 @@ public void testBackslashInLabel() {
assertRoundTrip("[^\\foo]\n\n[^\\foo]: note\n");
}

@Test
public void testMultipleLines() {
assertRoundTrip("Test [^1]\n\n[^1]: footnote l1\n footnote l2\n");
}

@Test
public void testMultipleParagraphs() {
// Note that the line between p1 and p2 could be blank too (instead of 4 spaces), but we currently don't
// preserve that information.
assertRoundTrip("Test [^1]\n\n[^1]: footnote p1\n \n footnote p2\n");
}

@Test
public void testInline() {
assertRoundTrip("^[test *foo*]\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ public void testDefContainsMultipleLines() {
assertText("still", paragraph.getLastChild());
}

@Test
public void testDefContainsMultipleParagraphs() {
var doc = PARSER.parse("[^1]: footnote p1\n\n footnote p2\n");
var def = find(doc, FootnoteDefinition.class);
assertThat(def.getLabel()).isEqualTo("1");
var p1 = (Paragraph) def.getFirstChild();
assertText("footnote p1", p1.getFirstChild());
var p2 = (Paragraph) p1.getNext();
assertText("footnote p2", p2.getFirstChild());
}

@Test
public void testDefFollowedByParagraph() {
var doc = PARSER.parse("[^1]: footnote\n\nnormal paragraph\n");
var def = find(doc, FootnoteDefinition.class);
assertThat(def.getLabel()).isEqualTo("1");
assertText("footnote", def.getFirstChild().getFirstChild());
assertText("normal paragraph", def.getNext().getFirstChild());
}

@Test
public void testDefContainsList() {
var doc = PARSER.parse("[^1]: - foo\n - bar\n");
Expand Down
4 changes: 4 additions & 0 deletions commonmark-integration-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<groupId>org.commonmark</groupId>
<artifactId>commonmark-ext-autolink</artifactId>
</dependency>
<dependency>
<groupId>org.commonmark</groupId>
<artifactId>commonmark-ext-footnotes</artifactId>
</dependency>
<dependency>
<groupId>org.commonmark</groupId>
<artifactId>commonmark-ext-ins</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.commonmark.Extension;
import org.commonmark.ext.autolink.AutolinkExtension;
import org.commonmark.ext.footnotes.FootnotesExtension;
import org.commonmark.ext.front.matter.YamlFrontMatterExtension;
import org.commonmark.ext.gfm.strikethrough.StrikethroughExtension;
import org.commonmark.ext.gfm.tables.TablesExtension;
Expand All @@ -15,6 +16,7 @@ public class Extensions {

static final List<Extension> ALL_EXTENSIONS = List.of(
AutolinkExtension.create(),
FootnotesExtension.create(),
ImageAttributesExtension.create(),
InsExtension.create(),
StrikethroughExtension.create(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,8 @@

public class MarkdownRendererIntegrationTest {

private static final List<Extension> EXTENSIONS = List.of(
AutolinkExtension.create(),
ImageAttributesExtension.create(),
InsExtension.create(),
StrikethroughExtension.create(),
TablesExtension.create(),
TaskListItemsExtension.create(),
YamlFrontMatterExtension.create());
private static final Parser PARSER = Parser.builder().extensions(EXTENSIONS).build();
private static final MarkdownRenderer RENDERER = MarkdownRenderer.builder().extensions(EXTENSIONS).build();
private static final Parser PARSER = Parser.builder().extensions(Extensions.ALL_EXTENSIONS).build();
private static final MarkdownRenderer RENDERER = MarkdownRenderer.builder().extensions(Extensions.ALL_EXTENSIONS).build();

@Test
public void testStrikethroughInTable() {
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@
<artifactId>commonmark-ext-autolink</artifactId>
<version>0.25.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.commonmark</groupId>
<artifactId>commonmark-ext-footnotes</artifactId>
<version>0.25.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.commonmark</groupId>
<artifactId>commonmark-ext-image-attributes</artifactId>
Expand Down