Add support for Gemtext blockquotes. Fixes #4

This commit is contained in:
Annika Backstrom 2022-05-24 22:24:47 +01:00
parent 99f5d1e660
commit 832bc08dc7
2 changed files with 17 additions and 0 deletions

View File

@ -6,6 +6,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\ListBlock;
use League\CommonMark\Extension\CommonMark\Node\Block\ListItem;
@ -22,6 +23,7 @@ class ArticleParser extends Parser {
$last_node = null; //updated every time
$previous_node = null; // we only update this for significant nodes
$blockquote = 0;
$block_level = 0;
$list_item = 0;
@ -41,6 +43,8 @@ class ArticleParser extends Parser {
if ($node instanceof ListBlock) {
$block_level -= 1;
$list_item = 0;
} elseif ($node instanceof BlockQuote) {
$blockquote -= 1;
}
continue;
@ -52,6 +56,11 @@ class ArticleParser extends Parser {
continue;
}
if ($node instanceof BlockQuote) {
$blockquote += 1;
$gemtext[] = '';
}
if ($node instanceof Text) {
$text = $node->getLiteral();
@ -69,6 +78,8 @@ class ArticleParser extends Parser {
$leader = $list_item === 1 ? "\n" : "";
$gemtext[] = $leader . '* ' . $text;
} elseif ($blockquote) {
$gemtext[] = '> ' . $text;
} else {
$leader = $previous_node ? "\n" : "";
$gemtext[] = $leader . $text;

View File

@ -101,4 +101,10 @@ class ArticleParserTest extends TestCase {
$this->parser->load(vfsStream::url('root/article.md'));
$this->assertSame("para\n\n* item 1\n* item 2\n\nout", $this->parser->convert());
}
public function testBlockquote() {
$this->setArticleText("- before\n- > this is a quote\n it spans 2 lines\n- more");
$this->parser->load(vfsStream::url('root/article.md'));
$this->assertSame("before\n\n> this is a quote\n> it spans 2 lines\n\nmore", $this->parser->convert());
}
}