From 16c49f782b988a4e72a53cdeffe22caa79b7e6e4 Mon Sep 17 00:00:00 2001
From: chillbram <7299762+chillbram@users.noreply.github.com>
Date: Fri, 13 Feb 2026 15:33:29 +0100
Subject: [PATCH 1/2] Add config to disable inline footnotes + documentation
for inline footnotes
---
docs/2.x/extensions/footnotes.md | 45 +++++++++++++++----
src/Extension/Footnote/FootnoteExtension.php | 8 +++-
.../Footnote/FootnoteExtensionTest.php | 18 ++++----
3 files changed, 53 insertions(+), 18 deletions(-)
diff --git a/docs/2.x/extensions/footnotes.md b/docs/2.x/extensions/footnotes.md
index c5f72a7509..36795dee11 100644
--- a/docs/2.x/extensions/footnotes.md
+++ b/docs/2.x/extensions/footnotes.md
@@ -59,6 +59,34 @@ Result:
```
+### Inline footnotes
+
+Inline footnotes (or anonymous footnotes) are easier to write, since you don't have to pick an identifier and move down to type the note. They have a slightly different syntax, with the caret placed before the opening square bracket: `^[Note]`. Inline footnotes do not support multiple paragraphs.
+
+Sample Markdown input:
+
+```markdown
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi^[Elit Malesuada Ridiculus] leo risus, porta ac consectetur ac.
+```
+
+Result:
+
+```html
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi leo risus, porta ac consectetur ac.
+
+
+```
+
## Usage
Configure your `Environment` as usual and simply add the `FootnoteExtension`:
@@ -74,14 +102,15 @@ use League\CommonMark\MarkdownConverter;
// If you're happy with the defaults, feel free to remove them from this array
$config = [
'footnote' => [
- 'backref_class' => 'footnote-backref',
- 'backref_symbol' => '↩',
- 'container_add_hr' => true,
- 'container_class' => 'footnotes',
- 'ref_class' => 'footnote-ref',
- 'ref_id_prefix' => 'fnref:',
- 'footnote_class' => 'footnote',
- 'footnote_id_prefix' => 'fn:',
+ 'backref_class' => 'footnote-backref',
+ 'backref_symbol' => '↩',
+ 'container_add_hr' => true,
+ 'container_class' => 'footnotes',
+ 'enable_inline_footnotes' => true,
+ 'ref_class' => 'footnote-ref',
+ 'ref_id_prefix' => 'fnref:',
+ 'footnote_class' => 'footnote',
+ 'footnote_id_prefix' => 'fn:',
],
];
diff --git a/src/Extension/Footnote/FootnoteExtension.php b/src/Extension/Footnote/FootnoteExtension.php
index 0fa8038e22..adc7124463 100644
--- a/src/Extension/Footnote/FootnoteExtension.php
+++ b/src/Extension/Footnote/FootnoteExtension.php
@@ -44,6 +44,7 @@ public function configureSchema(ConfigurationBuilderInterface $builder): void
'backref_symbol' => Expect::string('↩'),
'container_add_hr' => Expect::bool(true),
'container_class' => Expect::string('footnotes'),
+ 'enable_inline_footnotes' => Expect::bool(true),
'ref_class' => Expect::string('footnote-ref'),
'ref_id_prefix' => Expect::string('fnref:'),
'footnote_class' => Expect::string('footnote'),
@@ -54,7 +55,6 @@ public function configureSchema(ConfigurationBuilderInterface $builder): void
public function register(EnvironmentBuilderInterface $environment): void
{
$environment->addBlockStartParser(new FootnoteStartParser(), 51);
- $environment->addInlineParser(new AnonymousFootnoteRefParser(), 35);
$environment->addInlineParser(new FootnoteRefParser(), 51);
$environment->addRenderer(FootnoteContainer::class, new FootnoteContainerRenderer());
@@ -62,9 +62,13 @@ public function register(EnvironmentBuilderInterface $environment): void
$environment->addRenderer(FootnoteRef::class, new FootnoteRefRenderer());
$environment->addRenderer(FootnoteBackref::class, new FootnoteBackrefRenderer());
- $environment->addEventListener(DocumentParsedEvent::class, [new AnonymousFootnotesListener(), 'onDocumentParsed'], 40);
$environment->addEventListener(DocumentParsedEvent::class, [new FixOrphanedFootnotesAndRefsListener(), 'onDocumentParsed'], 30);
$environment->addEventListener(DocumentParsedEvent::class, [new NumberFootnotesListener(), 'onDocumentParsed'], 20);
$environment->addEventListener(DocumentParsedEvent::class, [new GatherFootnotesListener(), 'onDocumentParsed'], 10);
+
+ if ($environment->getConfiguration()->get('footnote/enable_inline_footnotes')) {
+ $environment->addInlineParser(new AnonymousFootnoteRefParser(), 35);
+ $environment->addEventListener(DocumentParsedEvent::class, [new AnonymousFootnotesListener(), 'onDocumentParsed'], 40);
+ }
}
}
diff --git a/tests/functional/Extension/Footnote/FootnoteExtensionTest.php b/tests/functional/Extension/Footnote/FootnoteExtensionTest.php
index 38e0c0bf63..779172e445 100644
--- a/tests/functional/Extension/Footnote/FootnoteExtensionTest.php
+++ b/tests/functional/Extension/Footnote/FootnoteExtensionTest.php
@@ -66,15 +66,16 @@ public function testFootnotesWithCustomOptions(string $input, string $expected):
{
$environment = new Environment([
'footnote' => [
- 'backref_class' => 'custom-backref',
+ 'backref_class' => 'custom-backref',
// Ensure multiple characters are allowed (including multibyte) and special HTML characters are escaped.
- 'backref_symbol' => '↩ 🦄️ <3 You',
- 'container_add_hr' => false,
- 'container_class' => 'custom-notes',
- 'ref_class' => 'custom-ref',
- 'ref_id_prefix' => 'fnref:',
- 'footnote_class' => 'custom-footnote',
- 'footnote_id_prefix' => 'fn:',
+ 'backref_symbol' => '↩ 🦄️ <3 You',
+ 'container_add_hr' => false,
+ 'container_class' => 'custom-notes',
+ 'enable_inline_footnotes' => false,
+ 'ref_class' => 'custom-ref',
+ 'ref_id_prefix' => 'fnref:',
+ 'footnote_class' => 'custom-footnote',
+ 'footnote_id_prefix' => 'fn:',
],
]);
$environment->addExtension(new CommonMarkCoreExtension());
@@ -89,6 +90,7 @@ public static function dataProviderForTestFootnotesWithCustomOptions(): \Generat
{
yield ["Here[^note1]\n\n[^note1]: There", 'Here1
' . "\n" . ''];
yield ["_Here_[^note1]\n\n[^note1]: **There**", 'Here1
' . "\n" . ''];
+ yield ['Disabled inline notes^[note1]', 'Disabled inline notes^[note1]
'];
}
public function testFootnotesWithEmptySymbol(): void
From 89316d20e10e7b0e65eeee490dbb955abfe79e7a Mon Sep 17 00:00:00 2001
From: chillbram <7299762+chillbram@users.noreply.github.com>
Date: Thu, 19 Feb 2026 16:14:03 +0100
Subject: [PATCH 2/2] Prevent style guide error
---
src/Extension/Footnote/FootnoteExtension.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/Extension/Footnote/FootnoteExtension.php b/src/Extension/Footnote/FootnoteExtension.php
index adc7124463..d3daf36b24 100644
--- a/src/Extension/Footnote/FootnoteExtension.php
+++ b/src/Extension/Footnote/FootnoteExtension.php
@@ -54,6 +54,11 @@ public function configureSchema(ConfigurationBuilderInterface $builder): void
public function register(EnvironmentBuilderInterface $environment): void
{
+ if ($environment->getConfiguration()->get('footnote/enable_inline_footnotes')) {
+ $environment->addInlineParser(new AnonymousFootnoteRefParser(), 35);
+ $environment->addEventListener(DocumentParsedEvent::class, [new AnonymousFootnotesListener(), 'onDocumentParsed'], 40);
+ }
+
$environment->addBlockStartParser(new FootnoteStartParser(), 51);
$environment->addInlineParser(new FootnoteRefParser(), 51);
@@ -65,10 +70,5 @@ public function register(EnvironmentBuilderInterface $environment): void
$environment->addEventListener(DocumentParsedEvent::class, [new FixOrphanedFootnotesAndRefsListener(), 'onDocumentParsed'], 30);
$environment->addEventListener(DocumentParsedEvent::class, [new NumberFootnotesListener(), 'onDocumentParsed'], 20);
$environment->addEventListener(DocumentParsedEvent::class, [new GatherFootnotesListener(), 'onDocumentParsed'], 10);
-
- if ($environment->getConfiguration()->get('footnote/enable_inline_footnotes')) {
- $environment->addInlineParser(new AnonymousFootnoteRefParser(), 35);
- $environment->addEventListener(DocumentParsedEvent::class, [new AnonymousFootnotesListener(), 'onDocumentParsed'], 40);
- }
}
}