Compare commits

...

2 Commits

3 changed files with 26 additions and 4 deletions

View File

@ -1,7 +1,7 @@
<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="parser">
<file>tests/ParserTest.php</file>
<testsuite name="logseq2gemtext">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@ -22,6 +22,9 @@ class ArticleParser extends Parser {
$last_node = null; //updated every time
$previous_node = null; // we only update this for significant nodes
$block_level = 0;
$list_item = 0;
$walker = $this->document->walker();
while ($event = $walker->next()) {
$entering = $event->isEntering();
@ -35,10 +38,16 @@ class ArticleParser extends Parser {
}
if (!$entering) {
if ($node instanceof ListBlock) {
$block_level -= 1;
$list_item = 0;
}
continue;
}
if ($node instanceof ListBlock) {
$block_level += 1;
$in_frontmatter = false;
continue;
}
@ -55,8 +64,15 @@ class ArticleParser extends Parser {
}
}
$leader = $previous_node ? "\n" : "";
$gemtext[] = $leader . $text;
if ($block_level > 1) {
$list_item += 1;
$leader = $list_item === 1 ? "\n" : "";
$gemtext[] = $leader . '* ' . $text;
} else {
$leader = $previous_node ? "\n" : "";
$gemtext[] = $leader . $text;
}
$previous_node = $node;

View File

@ -95,4 +95,10 @@ class ArticleParserTest extends TestCase {
$this->parser->load(vfsStream::url('root/article.md'));
$this->assertSame("=> bar foo\n\n=> foo bar", $this->parser->convert());
}
public function testList() {
$this->setArticleText("- para\n\t- item 1\n\t- item 2\n- out");
$this->parser->load(vfsStream::url('root/article.md'));
$this->assertSame("para\n\n* item 1\n* item 2\n\nout", $this->parser->convert());
}
}