orium / cargo-rdme

Cargo command to create the README.md from your crate's documentation
Mozilla Public License 2.0
126 stars 5 forks source link

Reference style links #163

Closed smoelius closed 1 year ago

smoelius commented 1 year ago

Am I correct to infer that intralink support does not extend to reference style links? Would they be difficult to support?

orium commented 1 year ago

Hi. Currently they are not supported but that's something we would like to have. I don't give it a lot of priority, but it is certainly a nice to have.

It shouldn't be too hard to implement, but it is not trivial either. PRs are welcome though.

smoelius commented 1 year ago

Could you say a couple of sentences about what you imagine the change looking like?

orium commented 1 year ago

Sure. All magic happens in intralinks.rs. There is a struct MarkdownInlineLink that represents an inline link. This is created by fn markdown_inline_link_iterator(). I suggest we introduce a enum like this:

enum MarkdownLinkInfo {
    Inline { link: MarkdownInlineLink },
    ReferenceDefinition { reference_definition: MarkdownReferenceDefinition }
}

and change markdown_inline_link_iterator() to return MarkdownItemIterator<MarkdownLink>. This function uses pulldown_cmark to parse the markdown. Not sure how reference links definitions are represented (write a unit tests and add some println!() and it should become obvious).

Once you change the return type of markdown_inline_link_iterator() the compiler should guide you through.