Add support for Gemtext headings. Fixes #2
This commit is contained in:
parent
832bc08dc7
commit
ee4bd41d9c
@ -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\Heading;
|
||||
use League\CommonMark\Extension\CommonMark\Node\Block\ListBlock;
|
||||
use League\CommonMark\Extension\CommonMark\Node\Block\ListItem;
|
||||
|
||||
@ -61,6 +62,22 @@ class ArticleParser extends Parser {
|
||||
$gemtext[] = '';
|
||||
}
|
||||
|
||||
if ($node instanceof Heading) {
|
||||
$next = $walker->next();
|
||||
$text = $next->getNode();
|
||||
|
||||
if (!$text instanceof Text) {
|
||||
throw new \Exception('Expected Heading to contain a Text node, got ' . get_class($text));
|
||||
}
|
||||
|
||||
$leader = $previous_node ? "\n" : "";
|
||||
$gemtext[] = $leader . str_repeat('#', $node->getLevel()) . ' ' . $text->getLiteral();
|
||||
|
||||
$previous_node = $node;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($node instanceof Text) {
|
||||
$text = $node->getLiteral();
|
||||
|
||||
|
@ -107,4 +107,10 @@ class ArticleParserTest extends TestCase {
|
||||
$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());
|
||||
}
|
||||
|
||||
public function testHeadings() {
|
||||
$this->setArticleText("- before\n- # h1\n- ## h2\n- ### h3\n- after");
|
||||
$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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user