Add support for Gemtext lists. Fixes #3
This commit is contained in:
parent
1de5e568ef
commit
577ab07e34
@ -22,6 +22,9 @@ 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
|
||||||
|
|
||||||
|
$block_level = 0;
|
||||||
|
$list_item = 0;
|
||||||
|
|
||||||
$walker = $this->document->walker();
|
$walker = $this->document->walker();
|
||||||
while ($event = $walker->next()) {
|
while ($event = $walker->next()) {
|
||||||
$entering = $event->isEntering();
|
$entering = $event->isEntering();
|
||||||
@ -35,10 +38,16 @@ class ArticleParser extends Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$entering) {
|
if (!$entering) {
|
||||||
|
if ($node instanceof ListBlock) {
|
||||||
|
$block_level -= 1;
|
||||||
|
$list_item = 0;
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($node instanceof ListBlock) {
|
if ($node instanceof ListBlock) {
|
||||||
|
$block_level += 1;
|
||||||
$in_frontmatter = false;
|
$in_frontmatter = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -55,8 +64,15 @@ class ArticleParser extends Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$leader = $previous_node ? "\n" : "";
|
if ($block_level > 1) {
|
||||||
$gemtext[] = $leader . $text;
|
$list_item += 1;
|
||||||
|
|
||||||
|
$leader = $list_item === 1 ? "\n" : "";
|
||||||
|
$gemtext[] = $leader . '* ' . $text;
|
||||||
|
} else {
|
||||||
|
$leader = $previous_node ? "\n" : "";
|
||||||
|
$gemtext[] = $leader . $text;
|
||||||
|
}
|
||||||
|
|
||||||
$previous_node = $node;
|
$previous_node = $node;
|
||||||
|
|
||||||
|
@ -95,4 +95,10 @@ class ArticleParserTest extends TestCase {
|
|||||||
$this->parser->load(vfsStream::url('root/article.md'));
|
$this->parser->load(vfsStream::url('root/article.md'));
|
||||||
$this->assertSame("=> bar foo\n\n=> foo bar", $this->parser->convert());
|
$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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user