creecros / MarkdownPlus

Improved Markdown, with check boxes, emoji shortcode, inline html, etc...
MIT License
52 stars 15 forks source link

Checkbox parser removes mentions and internal links #3

Closed tomaszstrojny closed 3 years ago

tomaszstrojny commented 3 years ago

After installing the plugin, all the comments and descriptions are cleared from the internal links and @mentions.

I've tracked down it's because of the ParsedownCheckbox, emojis work fine.

My current code for the MarkdownPlusHelper->markdown() looks like this, and it works:

    public function markdown($text, $isPublicLink = false)
    {
        $emoji = new Client(new Ruleset());
        $parser = new Markdown($this->container, $isPublicLink);
        $parsecheckbox = new ParsedownCheckbox();
        if ($this->configModel->get('unicode_shortcode', '2') == 1) {
            $text = $emoji->shortnameToUnicode($text);
        } else {
            $text = $emoji->toImage($text);
        }

        // $parser->setMarkupEscaped(MARKDOWN_ESCAPE_HTML);
        $text = $parser->text($text);
        // $text = $parsecheckbox->text($text);

        return $text;
    }

While I try to add the parsecheckbox in any other place, it's escaping the links. It generally makes sense, but I would like to have both of them and don't know how to touch it. Do you have any suggestions?

creecros commented 3 years ago

anyway you could include a screenshot or gif showing me the issue? it's been a long time since I really used kanboard so not sure I even know what you're talking about. point me in the right direction.

tomaszstrojny commented 3 years ago

Sure! Thanks for the response :)

For the code I've pasted above I am getting such a content: image

When I comment the $text = $parser->text($text); and uncomment the // $text = $parsecheckbox->text($text); I'm getting something like this: image

As you can see, the checkbox is rendered correctly, but the links under @admin and #1 disappeared.

creecros commented 3 years ago

OK, I understand now.

and what's the non preview of that link code look like?

is it markdown or html? or does it just link with #1 oh and the @

creecros commented 3 years ago

nm I see it autofills... I'll take a look, probably some js stuff goin on with that, I wasn't even aware of it.

tomaszstrojny commented 3 years ago

From what I observe, it's in PHP.

The methods meant to build the internal link and users (defined in the Core/Kanboard) are not run when we use the checkbox parser. I'm tracing the execution with xdebug and it just doesn't run it. It's like the Core/Markdown parser runs or the ParsedownCheckbox - I cannot get both of them working on the same content.

tomaszstrojny commented 3 years ago

OK, I understand now.

and what's the non preview of that link code look like?

is it markdown or html? or does it just link with #1 oh and the @

Generally in Kanboard internal links are created by the core parser, which looks for @ and #, give suggestions and then parse them as links. @mentions to users and #123 to tasks.

For the not parsed version HTML looks like that:

<article class="markdown">
    <p>test @admin <img class="emojione" alt="↕" title=":arrow_up_down:" src="https://cdn.jsdelivr.net/emojione/assets/4.5/png/32/2195.png"> #1 </p>
    <input type="checkbox" disabled=""> ates        
</article>

on the other hand we have this:

<article class="markdown">
    <p>test <a href="/?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link" title="admin" aria-label="admin">@admin</a> <img class="emojione" alt="↕" title=":arrow_up_down:" src="https://cdn.jsdelivr.net/emojione/assets/4.5/png/32/2195.png"> <a href="/?controller=TaskViewController&amp;action=show&amp;task_id=1">#1</a>
    </p>
    <p>[ ] ates</p>        
</article>
creecros commented 3 years ago

see, you know more than I do! I'll definitely take a look and see what I can come up with, might just take me a while to get the chance though. if I'm lucky, you solve it before me 😄

creecros commented 3 years ago

i figured out whats going on. had to come up with a workaround, but long story short, the core markdown extends Parsedown, i had to back it out and extend ParsedownCheckbox, which extends Parsedown extra, and then add to the construct to get it to run them all.

image

creecros commented 3 years ago

@tomaszstrojny givee it a test drive, hopefully i didn't screw anything up fixing it

creecros commented 3 years ago

well, now i'm getting an error, and I'm out of time for the day. to be continued: 2021/03/15 15:21:41 [error] 16#16: *202 FastCGI sent in stderr: "PHP message: PHP Notice: Trying to access array offset on value of type null in /var/www/app/plugins/MarkdownPlus/vendor/erusev/parsedown-extra/ParsedownExtra.php on line 241PHP message: PHP Notice: Trying to access array offset on value of type null in /var/www/app/plugins/MarkdownPlus/vendor/erusev/parsedown-extra/ParsedownExtra.php on line 241" while reading response header from upstream, client: 172.17.0.3, server: localhost, request: "GET /project/4/task/110 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host: "projects.divdist.com"

creecros commented 3 years ago

@tomaszstrojny ok, so no errors, and all appears to correctly be parsing...let me know if you see anymore issues.

creecros commented 3 years ago

reopen if you find any issues, closing for now.

tomaszstrojny commented 3 years ago

Changes in the vendor directory is always a lot of fun :)

Anyway, everything works nice now, thanks!

creecros commented 3 years ago

I know, I hated to do it, but really had no choice.