-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Samwilson\CommonMarkLatex\Footnotes; | ||
|
||
use League\CommonMark\Extension\Footnote\Node\FootnoteBackref; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
|
||
final class FootnoteBackrefRenderer implements NodeRendererInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer) | ||
{ | ||
FootnoteBackref::assertInstanceOf($node); | ||
|
||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Samwilson\CommonMarkLatex\Footnotes; | ||
|
||
use League\CommonMark\Extension\Footnote\Node\FootnoteContainer; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
|
||
final class FootnoteContainerRenderer implements NodeRendererInterface | ||
{ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer): string | ||
{ | ||
FootnoteContainer::assertInstanceOf($node); | ||
|
||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Samwilson\CommonMarkLatex\Footnotes; | ||
|
||
use League\CommonMark\Extension\Footnote\Node\FootnoteRef; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
|
||
final class FootnoteRefRenderer implements NodeRendererInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer) | ||
{ | ||
FootnoteRef::assertInstanceOf($node); | ||
|
||
$footnote = GatherFootnotesListener::$footnotes[$node->getReference()->getTitle()]; | ||
|
||
return '\\footnote{' . $childRenderer->renderNodes($footnote->children()) . '}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Samwilson\CommonMarkLatex\Footnotes; | ||
|
||
use League\CommonMark\Extension\Footnote\Node\Footnote; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
|
||
final class FootnoteRenderer implements NodeRendererInterface | ||
{ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer): string | ||
{ | ||
Footnote::assertInstanceOf($node); | ||
|
||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Samwilson\CommonMarkLatex\Footnotes; | ||
|
||
use League\CommonMark\Event\DocumentParsedEvent; | ||
use League\CommonMark\Extension\Footnote\Node\Footnote; | ||
use League\CommonMark\Node\NodeIterator; | ||
|
||
final class GatherFootnotesListener | ||
{ | ||
/** @var Node[] */ | ||
public static array $footnotes; | ||
|
||
public function onDocumentParsed(DocumentParsedEvent $event): void | ||
{ | ||
$document = $event->getDocument(); | ||
|
||
foreach ($document->iterator(NodeIterator::FLAG_BLOCKS_ONLY) as $node) { | ||
if (! $node instanceof Footnote) { | ||
continue; | ||
} | ||
|
||
$ref = $document->getReferenceMap()->get($node->getReference()->getLabel()); | ||
if ($ref !== null) { | ||
self::$footnotes[$ref->getTitle()] = $node; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Lorem[^fnlabel] ipsum. | ||
|
||
And[^1] another. | ||
|
||
[^1]: A multi- | ||
|
||
-paragraph footnote. | ||
|
||
[^fnlabel]: Footnote *text*. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Lorem\footnote{Footnote \emph{text}. | ||
} ipsum. | ||
|
||
And\footnote{A multi- | ||
|
||
-paragraph footnote. | ||
} another. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters