Add support for Gemtext preformatted text. Fixes #5
This commit is contained in:
parent
ee4bd41d9c
commit
ee5ed3e075
@ -7,6 +7,7 @@ namespace LogseqGem;
|
|||||||
use League\CommonMark\Node\Inline\Text;
|
use League\CommonMark\Node\Inline\Text;
|
||||||
use League\CommonMark\Extension\CommonMark\Node\Inline\Link;
|
use League\CommonMark\Extension\CommonMark\Node\Inline\Link;
|
||||||
use League\CommonMark\Extension\CommonMark\Node\Block\BlockQuote;
|
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\Heading;
|
||||||
use League\CommonMark\Extension\CommonMark\Node\Block\ListBlock;
|
use League\CommonMark\Extension\CommonMark\Node\Block\ListBlock;
|
||||||
use League\CommonMark\Extension\CommonMark\Node\Block\ListItem;
|
use League\CommonMark\Extension\CommonMark\Node\Block\ListItem;
|
||||||
@ -78,6 +79,16 @@ class ArticleParser extends Parser {
|
|||||||
continue;
|
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) {
|
if ($node instanceof Text) {
|
||||||
$text = $node->getLiteral();
|
$text = $node->getLiteral();
|
||||||
|
|
||||||
|
@ -113,4 +113,10 @@ class ArticleParserTest extends TestCase {
|
|||||||
$this->parser->load(vfsStream::url('root/article.md'));
|
$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());
|
$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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user