Skip to content

Proper broken link handler #385

@lucascool12

Description

@lucascool12

Context

It would be nice if there was an easy way to have a function resolve link references that haven't been registered (similar to pulldown-cmark https://docs.rs/pulldown-cmark/0.13.1/pulldown_cmark/struct.Parser.html#method.new_with_broken_link_callback).
So we can programmatically decide the href of something like this:

[broken_link]

I didn't find anything in the documentation describing how to properly do this, and the only work around I found was to copy and paste the link function in rules_inline (

def link(state: StateInline, silent: bool) -> bool:
) and whenever false is returned when parseReference is true to put some custom logic to try to resolve the reference.
And then register this rule with:

md = markdown_it.MarkdownIt()
def custom_link(state, silent):
    ....
md.inline.ruler.disable("link")
md.inline.ruler.push("custom_link",  custom_link)

It would be very nice if there was some blessed route to be able to do this.

Proposal

No response

Tasks and updates

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions