Compare commits
No commits in common. "ee5ed3e0750dace4979c8beed4f712b589e475dc" and "99f5d1e660e75197d04be32623744b5443842562" have entirely different histories.
ee5ed3e075
...
99f5d1e660
@ -6,9 +6,6 @@ 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\FencedCode;
|
|
||||||
use League\CommonMark\Extension\CommonMark\Node\Block\Heading;
|
|
||||||
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;
|
||||||
|
|
||||||
@ -25,7 +22,6 @@ 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;
|
||||||
|
|
||||||
@ -45,8 +41,6 @@ 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;
|
||||||
@ -58,37 +52,6 @@ class ArticleParser extends Parser {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($node instanceof BlockQuote) {
|
|
||||||
$blockquote += 1;
|
|
||||||
$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 FencedCode) {
|
|
||||||
$leader = $previous_node ? "\n" : "";
|
|
||||||
|
|
||||||
$gemtext[] = $leader . "```";
|
|
||||||
$gemtext[] = $node->getLiteral() . '```'; // allow trailing slash from literal
|
|
||||||
|
|
||||||
$previous_node = $node;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($node instanceof Text) {
|
if ($node instanceof Text) {
|
||||||
$text = $node->getLiteral();
|
$text = $node->getLiteral();
|
||||||
|
|
||||||
@ -106,8 +69,6 @@ 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,22 +101,4 @@ 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());
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPreformatted() {
|
|
||||||
$this->setArticleText("- before\n- ```\n one\n two\n ```\n- after");
|
|
||||||
$this->parser->load(vfsStream::url('root/article.md'));
|
|
||||||
$this->assertSame("before\n\n```\none\ntwo\n```\n\nafter", $this->parser->convert());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user