void-linux / void-docs

mdbook source for docs.voidlinux.org
https://docs.voidlinux.org
Creative Commons Attribution Share Alike 4.0 International
162 stars 180 forks source link

Switch to using reference-style links #286

Open flexibeast opened 4 years ago

flexibeast commented 4 years ago

@jeffayle suggested here that we use reference-style links in the Handbook when linking to man pages. i like this idea, particularly as we factor out common information and increasingly link to page fragments: if all man page links can simply have the format [ls(1)], we won't have to worry about users being directed to a fragment which contains a non-linked man page reference.

ericonr commented 4 years ago

I love this idea! Some refactoring would be needed, of course :p

jeffayle commented 4 years ago

My recommendation:

vmdfmt rewrites reference style links as inline links, so that's going to be an issue.

edit: adding this to vmdfmt looks like it could be pretty involved. rather than converting markdown text to markdown text, it looks like vmdfmt converts the input to an abstract data structure, and then converts that back to markdown text. I haven't looked through the code, but that internal format probably doesn't distinguish between inline and reference style links and probably throws out the reference name (because it's based on a markdown parser that was designed to generate html).

hippi777 commented 4 years ago

maybe that "spec" link could be included in the docs somewhere around contributing

flexibeast commented 4 years ago

@hippi777: Yeah, it would probably be good to reference it from the style guide.

flexibeast commented 4 years ago

@jeffayle: Oh, so we can't just start using reference links without having to modify vmdfmt first? i'd been assuming vmdfmt could already handle this.

flexibeast commented 4 years ago

Upon further thought, even though i can understand why it might be useful to point to the CommonMark spec as a general guide to Markdown, i'm not sure we should actually do so, since we use Versioned Markdown, not CommonMark - i wouldn't want people to assume that they can use anything described by the latter spec. That said, it could certainly be used as a basis for adding reference-style links to Versioned Markdown.

jeffayle commented 4 years ago

@flexibeast yeah, I assumed vmdfmt would just leave them alone if it hadn't been written to handle it. I might take a look at vmdfmt, but I've never programmed in go before, and don't have a whole lot of experience with parsers

edit: I've looked over the code a bit more. The blackfriday AST produces a link object that doesn't differentiate between inline and reference links (which is why vmdfmt converts reference links to inline), however it looks like we could use the reference object to reconstruct the reference links.

My idea: modify vmd/internal/renderer/renderer.go: func link() to do a reverse reference lookup. If the url has a reference name attached, write the link in reference format (either [x] or [link text][x]. At the end of the document, output the reference table (if it's not empty) in a particular order (if we sort by url then all the man pages will get grouped together). (i guess it should also remove all references that don't have a link pointing to them)

This would have the following effects on the vmd spec:

But I guess this issue is blocked for now. I'll file an issue at the vmd repository since this is a pretty major diversion from that spec.