Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments #4

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Yep! It's a looking glass for your [lava rocks](https://en.wikipedia.org/wiki/Ob
- [x] Fully support [Obsidian's embedded image format](https://help.obsidian.md/How+to/Embed+files#Developer+notes)
- [x] Including resizing
- [ ] Safely support `iframe` embeds
- [ ] [Comments](https://help.obsidian.md/How+to/Format+your+notes#Comments)
- [x] Allow marking certain folders as private
- [x] Parsing/syntax highlighting of code blocks?
- [x] Mermaid.js
Expand Down
44 changes: 44 additions & 0 deletions app/Services/ArticleParser/InlineParser/ArticleCommentParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Services\ArticleParser\InlineParser;

use League\CommonMark\Extension\CommonMark\Node\Inline\Link;
use League\CommonMark\Parser\Inline\InlineParserMatch;
use League\CommonMark\Parser\InlineParserContext;

class ArticleCommentParser implements \League\CommonMark\Parser\Inline\InlineParserInterface
{

public function getMatchDefinition(): InlineParserMatch
{
return InlineParserMatch::regex('%%(.*)%%');
}

public function parse(InlineParserContext $inlineContext): bool
{
$cursor = $inlineContext->getCursor();

// The # symbol must not have any other characters immediately prior
$previousChar = $cursor->peek(-1);
if (!in_array($previousChar, [null, ' ', "\n"])) {
// peek() doesn't modify the cursor, so no need to restore state first
return false;
}

// This seems to be a valid match
// Advance the cursor to the end of the match
$cursor->advanceBy($inlineContext->getFullMatchLength());

if($cursor->isAtEnd()) {
return true;
}

$nextChar = $cursor->peek();
if (!in_array($nextChar, [null, ' ', "\n"])) {
// peek() doesn't modify the cursor, so no need to restore state first
return false;
}

return true;
}
}
2 changes: 2 additions & 0 deletions app/Services/ArticleParser/Pipeline/ConvertMarkdownToHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Services\ArticleParser\Pipeline;

use App\Models\Article;
use App\Services\ArticleParser\InlineParser\ArticleCommentParser;
use App\Services\ArticleParser\InlineParser\ArticleTagParser;
use App\Services\ArticleParser\Pipe;
use League\CommonMark\Environment\Environment;
Expand Down Expand Up @@ -98,6 +99,7 @@ private function createParser(): MarkdownConverter
$environment->addExtension(new FrontMatterExtension());

$environment->addInlineParser(new ArticleTagParser());
$environment->addInlineParser(new ArticleCommentParser());

return new MarkdownConverter($environment);
}
Expand Down