-
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.
* Add more syntax renderers and tests * Drop testing on MacOS and Windows
- Loading branch information
Showing
34 changed files
with
464 additions
and
58 deletions.
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
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
composer.lock | ||
.phpcs-cache | ||
.phpunit.result.cache | ||
build/ | ||
vendor/ | ||
tests/data/CompileTest* | ||
|
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
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; | ||
|
||
use League\CommonMark\Extension\CommonMark\Node\Inline\Code; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
|
||
class CodeRenderer implements NodeRendererInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer) | ||
{ | ||
Code::assertInstanceOf($node); | ||
|
||
return '\\texttt{' . $node->getLiteral() . '}'; | ||
} | ||
} |
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; | ||
|
||
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
|
||
class FencedCodeRenderer implements NodeRendererInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer) | ||
{ | ||
FencedCode::assertInstanceOf($node); | ||
|
||
$lang = ''; | ||
$infoWords = $node->getInfoWords(); | ||
if (\count($infoWords) > 0) { | ||
$lang = $infoWords[0]; | ||
} | ||
|
||
return '\\lstset{language={' . $lang . '}}\\begin{lstlisting}' . "\n" | ||
. $node->getLiteral() | ||
. '\\end{lstlisting}'; | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Samwilson\CommonMarkLatex; | ||
|
||
use League\CommonMark\Extension\CommonMark\Node\Inline\Image; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
|
||
class ImageRenderer implements NodeRendererInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer) | ||
{ | ||
Image::assertInstanceOf($node); | ||
|
||
return '\includegraphics{' . $node->getUrl() . '}'; | ||
} | ||
} |
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; | ||
|
||
use League\CommonMark\Extension\CommonMark\Node\Block\IndentedCode; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
|
||
class IndentedCodeRenderer implements NodeRendererInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer) | ||
{ | ||
IndentedCode::assertInstanceOf($node); | ||
|
||
return '\\lstset{language={}}\\begin{lstlisting}' . "\n" | ||
. $node->getLiteral() | ||
. '\\end{lstlisting}'; | ||
} | ||
} |
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Samwilson\CommonMarkLatex; | ||
|
||
use League\CommonMark\Extension\CommonMark\Node\Inline\Link; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
use League\CommonMark\Util\RegexHelper; | ||
use League\Config\ConfigurationAwareInterface; | ||
use League\Config\ConfigurationInterface; | ||
|
||
class LinkRenderer implements NodeRendererInterface, ConfigurationAwareInterface | ||
{ | ||
private ConfigurationInterface $config; | ||
|
||
public function setConfiguration(ConfigurationInterface $configuration): void | ||
{ | ||
$this->config = $configuration; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer) | ||
{ | ||
Link::assertInstanceOf($node); | ||
|
||
$out = $childRenderer->renderNodes($node->children()); | ||
|
||
$url = \str_replace('_', '\\_', $node->getUrl()); | ||
|
||
$allowUnsafeLinks = $this->config->get('allow_unsafe_links'); | ||
if (! $allowUnsafeLinks && RegexHelper::isLinkPotentiallyUnsafe($url)) { | ||
return $out; | ||
} | ||
|
||
// Autolink extension makes the label and the URL the same. | ||
if ($out === $url) { | ||
return '\\url{' . $url . '}'; | ||
} | ||
|
||
$title = $node->getTitle(); | ||
if ($title) { | ||
$title .= ': '; | ||
} | ||
|
||
return $out . '\\footnote{' . $title . '\\url{' . $url . '}}'; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Samwilson\CommonMarkLatex; | ||
|
||
use League\CommonMark\Extension\CommonMark\Node\Block\ListBlock; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
|
||
class ListBlockRenderer implements NodeRendererInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer) | ||
{ | ||
ListBlock::assertInstanceOf($node); | ||
|
||
$listType = $node->getListData()->type === ListBlock::TYPE_BULLET ? 'itemize' : 'enumerate'; | ||
$innerSeparator = $childRenderer->getInnerSeparator(); | ||
|
||
return '\\begin{' . $listType . '}' . "\n" | ||
. $innerSeparator . $childRenderer->renderNodes($node->children()) . $innerSeparator | ||
. '\\end{' . $listType . '}'; | ||
} | ||
} |
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; | ||
|
||
use League\CommonMark\Extension\CommonMark\Node\Block\ListItem; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
|
||
class ListItemRenderer implements NodeRendererInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer) | ||
{ | ||
ListItem::assertInstanceOf($node); | ||
|
||
return '\\item ' . $childRenderer->renderNodes($node->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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Samwilson\CommonMarkLatex; | ||
|
||
use League\CommonMark\Extension\CommonMark\Node\Block\ThematicBreak; | ||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
|
||
class ThematicBreakRenderer implements NodeRendererInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer) | ||
{ | ||
ThematicBreak::assertInstanceOf($node); | ||
|
||
return "\n" . '\\noindent\\rule{\\textwidth}{0.4pt}'; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,10 @@ | ||
> A two-line | ||
> quote. | ||
> Another, one line this time. | ||
Para in between. | ||
|
||
> Multi-paragraph | ||
> | ||
> quote. |
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,14 @@ | ||
\begin{quote} | ||
A two-line | ||
quote. | ||
\end{quote} | ||
\begin{quote} | ||
Another, one line this time. | ||
\end{quote} | ||
Para in between. | ||
|
||
\begin{quote} | ||
Multi-paragraph | ||
|
||
quote. | ||
\end{quote} |
Oops, something went wrong.