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

FR: replace --> with → #143

Open
PhilipMay opened this issue Mar 16, 2021 · 6 comments
Open

FR: replace --> with → #143

PhilipMay opened this issue Mar 16, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@PhilipMay
Copy link

Hi,
what do you think about maybe adding the following replacement to your replacements extension:

Replace --> with →

That would be very useful to write documentations where I often want to say something like:
Go to this menu: Files -> Sessings -> Colors

I would try and provide an PR if you agree.

Thanks
Philip

@PhilipMay PhilipMay added the enhancement New feature or request label Mar 16, 2021
@welcome
Copy link

welcome bot commented Mar 16, 2021

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@chrisjsewell
Copy link
Member

chrisjsewell commented Mar 17, 2021

Thanks @PhilipMay, it definitely seems feasible as we are already looking for --; in markdown_it/rules_core/replacements.py adding something like ARROW_RE = re.compile(r"(^|\s)-->(?=\s|$)", flags=re.MULTILINE)

This being a port though, this issue perhaps makes it a bit problematic to implement directly in "core" 😬: markdown-it/markdown-it#543
Meaning it might be best to essentially extract the replacement code into a plugin in https://github.com/executablebooks/mdit-py-plugins, where we can be a bit more flexible

@PhilipMay
Copy link
Author

@chrisjsewell so you mean that I should add it as a plugin at https://github.com/executablebooks/mdit-py-plugins right?

Could you please give me some more hints on how to do that?
Is there any documentation? Is there a plugin I could use as a template or is there already a plugin I could extend?

@chrisjsewell
Copy link
Member

chrisjsewell commented Mar 20, 2021

so you mean that I should add it as a plugin at executablebooks/mdit-py-plugins right?

yep 👍

Is there any documentation?

There not actually any documentation specifically for creating plugins (yet), but obviously if you haven't already read https://markdown-it-py.readthedocs.io/en/latest/using.html and https://markdown-it-py.readthedocs.io/en/latest/architecture.html

The plugin would look something like this, such that you literally are replacing the current "replace" rule (in https://github.com/executablebooks/markdown-it-py/blob/master/markdown_it/rules_core/replacements.py) with a different one:

def replace_plus_plugin(md: MarkdownIt):
    # Replace existing replace rule by name with new function.
    md.core.ruler.at("replace", replace_plus)


def replace_plus(state: StateCore, *args, **kwargs) -> None:

    for token in state.tokens:
        if token.type != "inline":
            continue
        assert token.children is not None

        if SCOPED_ABBR_RE.search(token.content):
            replace_scoped(token.children)

        if RARE_RE.search(token.content):
            replace_rare(token.children)

Although I just realised this won't actually work yet in v0.6.2 , because of #146 😬

@PhilipMay
Copy link
Author

Great @chrisjsewell
I will check this...

@PhilipMay
Copy link
Author

Well - #146 seems to be merged new.
I do not think that I will provide a PR.
@chrisjsewell maybe you could provide one?

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

No branches or pull requests

2 participants