Add support for Gemtext preformatted text. Fixes #5

This commit is contained in:
Annika Backstrom 2022-05-24 22:45:17 +01:00
parent ee4bd41d9c
commit ee5ed3e075
2 changed files with 17 additions and 0 deletions

View File

@ -7,6 +7,7 @@ namespace LogseqGem;
use League\CommonMark\Node\Inline\Text;
use League\CommonMark\Extension\CommonMark\Node\Inline\Link;
use League\CommonMark\Extension\CommonMark\Node\Block\BlockQuote;
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
use League\CommonMark\Extension\CommonMark\Node\Block\Heading;
use League\CommonMark\Extension\CommonMark\Node\Block\ListBlock;
use League\CommonMark\Extension\CommonMark\Node\Block\ListItem;
@ -78,6 +79,16 @@ class ArticleParser extends Parser {
continue;
}
if ($node instanceof FencedCode) {
$leader = $previous_node ? "\n" : "";
$gemtext[] = $leader . "```";
$gemtext[] = $node->getLiteral() . '```'; // allow trailing slash from literal
$previous_node = $node;
continue;
}
if ($node instanceof Text) {
$text = $node->getLiteral();

View File

@ -113,4 +113,10 @@ class ArticleParserTest extends TestCase {
$this->parser->load(vfsStream::url('root/article.md'));
$this->assertSame("before\n\n# h1\n\n## h2\n\n### h3\n\nafter", $this->parser->convert());
}
public function testPreformatted() {
$this->setArticleText("- before\n- ```\n one\n two\n ```\n- after");
$this->parser->load(vfsStream::url('root/article.md'));
$this->assertSame("before\n\n```\none\ntwo\n```\n\nafter", $this->parser->convert());
}
}