daffodil icon indicating copy to clipboard operation
daffodil copied to clipboard

[FEAT] Link to API docs from markdown guides

Open griest024 opened this issue 2 years ago • 5 comments

:bulb: Feature request

Feature Name

Link to API docs from markdown

The Desired Behavior

@daffodil/tools-dgeni replaces exported symbol links in markdown with daff.io links.

Your Use Case

As a daffodil dev, I want to be able to write API symbols in markdown files and have these replaced by the appropriate daff.io link to the symbol.

Prior Work

dgeni will currently correctly transform links of the form /libs/<package>/<symbol> but this is rather cumbersome. Ideally any public API symbol written in code blocks would be transformed to the appropraite link.

griest024 avatar Jun 15 '23 19:06 griest024

@hanmangokiwi is this something you're interested in tackling?

griest024 avatar Jun 15 '23 19:06 griest024

@griest024 you can use this approach

import { Dgeni, Plugin } from '@daffodil/tools-dgeni';

export class LinkToApiDocsPlugin implements Plugin {

  constructor(dgeni: Dgeni) {
    super(dgeni);

    // Register a processor that will replace links to symbols with links to daff.io.
    const linkToApiDocsProcessor = (doc: Document, node: Node) => {
      if (node.type === 'link' && node.attributes['href'].startsWith('daffodil')) {
        // Replace the link with the daff.io link for the symbol.
        node.attributes['href'] = `https://daff.io/docs/${node.attributes['href']}`;
      }
    };

    dgeni.addProcessor('linkToApiDocs', linkToApiDocsProcessor);
  }
}

shadow0500 avatar Jul 04 '23 08:07 shadow0500

@griest024 is this still relevant?

xelaint avatar Jun 11 '24 20:06 xelaint

Yes. Many times we will need to link to API symbols in docs (guides and other API docs). These links should be clickable and navigate to the relevant page of the API docs

griest024 avatar Jun 11 '24 20:06 griest024

this can be supported with a slightly goofy /libs/<package>/<symbol> syntax. It would be cool to have code blocks that match any API symbol to automatically get replaced with the link but that requires some interpackage dgeni deps.

griest024 avatar Jun 15 '24 17:06 griest024