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

A way to override default Parsedown behavior #736

Closed
maxlysenko opened this issue Mar 21, 2016 · 3 comments
Closed

A way to override default Parsedown behavior #736

maxlysenko opened this issue Mar 21, 2016 · 3 comments

Comments

@maxlysenko
Copy link
Contributor

Hello,
I found that it's possible to call a new function (closure) for processing a standard block/inline type if we have possibility to insert the new tag for that type into the BlockTypes/InlineType array in a particular position (higher than the tag we want to override).
Here is a possible workaround that is working for me:
If you change the addBlockType function to something like this:

public function addBlockType($type, $tag, $continuable = false, $completable = false, $index = null)
{
    if (!isset($index)) {
        $this->BlockTypes[$type] [] = $tag;
    } else {
        array_splice($this->BlockTypes[$type], $index, 0, $tag);
    }

    if ($continuable) {
        $this->continuable_blocks[] = $tag;
    }

    if ($completable) {
        $this->completable_blocks[] = $tag;
    }
}

and then in the onMarkdownInitialized event call addBlockType like this:

 $markdown->addBlockType('>', 'QuoteExtended', true, false, 0);

the tag is inserted into the BlockTypes array higher than the existing tag

 #BlockTypes: array:24 [
...
    ">" => array:2 [
      0 => "QuoteExtended"
      1 => "Quote"
    ]
...
]

and then the closures are called so it's possible to extend/override standard processing.

The same is true for the addInlineType:

public function addInlineType($type, $tag, $index = null)
{
    if (!isset($index)) {
        $this->InlineTypes[$type] [] = $tag;
    } else {
        array_splice($this->InlineTypes[$type], $index, 0, $tag);
    }

    $this->inlineMarkerList .= $type;
}
@rhukster
Copy link
Member

How about a PR that can be tested for backwards compatibility?

I would definitely consider this for inclusion.

@maxlysenko
Copy link
Contributor Author

Hello,
unfortunately I didn't have time to properly learn how to use GitHub and GitFlow, but I hope I made the PR right.

@rhukster
Copy link
Member

Closing as we have this merged.

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

No branches or pull requests

2 participants