Add support for Gemtext blockquotes. Fixes #4
This commit is contained in:
parent
99f5d1e660
commit
832bc08dc7
@ -6,6 +6,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\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;
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ class ArticleParser extends Parser {
|
|||||||
$last_node = null; //updated every time
|
$last_node = null; //updated every time
|
||||||
$previous_node = null; // we only update this for significant nodes
|
$previous_node = null; // we only update this for significant nodes
|
||||||
|
|
||||||
|
$blockquote = 0;
|
||||||
$block_level = 0;
|
$block_level = 0;
|
||||||
$list_item = 0;
|
$list_item = 0;
|
||||||
|
|
||||||
@ -41,6 +43,8 @@ class ArticleParser extends Parser {
|
|||||||
if ($node instanceof ListBlock) {
|
if ($node instanceof ListBlock) {
|
||||||
$block_level -= 1;
|
$block_level -= 1;
|
||||||
$list_item = 0;
|
$list_item = 0;
|
||||||
|
} elseif ($node instanceof BlockQuote) {
|
||||||
|
$blockquote -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@ -52,6 +56,11 @@ class ArticleParser extends Parser {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($node instanceof BlockQuote) {
|
||||||
|
$blockquote += 1;
|
||||||
|
$gemtext[] = '';
|
||||||
|
}
|
||||||
|
|
||||||
if ($node instanceof Text) {
|
if ($node instanceof Text) {
|
||||||
$text = $node->getLiteral();
|
$text = $node->getLiteral();
|
||||||
|
|
||||||
@ -69,6 +78,8 @@ class ArticleParser extends Parser {
|
|||||||
|
|
||||||
$leader = $list_item === 1 ? "\n" : "";
|
$leader = $list_item === 1 ? "\n" : "";
|
||||||
$gemtext[] = $leader . '* ' . $text;
|
$gemtext[] = $leader . '* ' . $text;
|
||||||
|
} elseif ($blockquote) {
|
||||||
|
$gemtext[] = '> ' . $text;
|
||||||
} else {
|
} else {
|
||||||
$leader = $previous_node ? "\n" : "";
|
$leader = $previous_node ? "\n" : "";
|
||||||
$gemtext[] = $leader . $text;
|
$gemtext[] = $leader . $text;
|
||||||
|
@ -101,4 +101,10 @@ class ArticleParserTest extends TestCase {
|
|||||||
$this->parser->load(vfsStream::url('root/article.md'));
|
$this->parser->load(vfsStream::url('root/article.md'));
|
||||||
$this->assertSame("para\n\n* item 1\n* item 2\n\nout", $this->parser->convert());
|
$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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user