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

Fenced code encapsuled #599

Closed
ElGigi opened this issue Apr 5, 2018 · 1 comment
Closed

Fenced code encapsuled #599

ElGigi opened this issue Apr 5, 2018 · 1 comment
Labels
Milestone

Comments

@ElGigi
Copy link

ElGigi commented Apr 5, 2018

Encapsuled fenced code doesn't works.

````markdown
```mermaid
graph LR
    Start --> Stop
```
````

To fix this issue:

    protected function blockFencedCode($Line)
    {
        if (preg_match('/^([' . $Line['text'][0] . ']{3,})[ ]*([^`]+)?[ ]*$/', $Line['text'], $matches)) {
            $Element = [
                'name' => 'code',
                'text' => '',
            ];

            if (isset($matches[2])) {
                $class = 'language-' . $matches[2];

                $Element['attributes'] = [
                    'class' => $class,
                ];
            }

            $Block = [
                'char'    => $Line['text'][0],
                'element' => [
                    'name'    => 'pre',
                    'handler' => 'element',
                    'text'    => $Element,
                    'length'  => mb_strlen($matches[1]),
                ],
            ];

            return $Block;
        }
    }

    protected function blockFencedCodeContinue($Line, $Block)
    {
        if (isset($Block['complete'])) {
            return;
        }

        if (isset($Block['interrupted'])) {
            $Block['element']['text']['text'] .= "\n";

            unset($Block['interrupted']);
        }

        if (preg_match('/^' . $Block['char'] . '{' . $Block['element']['length'] . '}[ ]*$/', $Line['text'])) {
            $Block['element']['text']['text'] = substr($Block['element']['text']['text'], 1);

            $Block['complete'] = true;

            return $Block;
        }

        $Block['element']['text']['text'] .= "\n" . $Line['body'];

        return $Block;
    }
@aidantwoods
Copy link
Collaborator

Thanks @ElGigi! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants