Treat empty block as a newline character

This commit is contained in:
Annika Backstrom 2022-05-24 18:43:03 +01:00
parent 2fff247ac1
commit 859b660400
2 changed files with 17 additions and 2 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\ListBlock;
use League\CommonMark\Extension\CommonMark\Node\Block\ListItem;
class ArticleParser extends Parser {
private ?array $properties;
@ -17,14 +18,22 @@ class ArticleParser extends Parser {
$in_frontmatter = true;
// we only update this for significant nodes
$previous_node = null;
$node = null; //current node
$last_node = null; //updated every time
$previous_node = null; // we only update this for significant nodes
$walker = $this->document->walker();
while ($event = $walker->next()) {
$entering = $event->isEntering();
$last_node = $node;
$node = $event->getNode();
// treat empty node as a newline
if ($node instanceof ListItem && $last_node === $node && !$entering) {
$gemtext[] = '';
continue;
}
if (!$entering) {
continue;
}

View File

@ -89,4 +89,10 @@ class ArticleParserTest extends TestCase {
$this->parser->convert();
$this->assertTrue($this->parser->isPublished());
}
public function testNewlineBetweenLinks() {
$this->setArticleText("\n- [foo](bar)\n-\n- [bar](foo)");
$this->parser->load(vfsStream::url('root/article.md'));
$this->assertSame("=> bar foo\n\n=> foo bar", $this->parser->convert());
}
}