Skip to content

Support regions and line numbers within @includeCode tag reference #2814

@shawninder

Description

@shawninder

Search terms

@knodes/typedoc-plugin-code-blocks, [email protected], [email protected], @codeblock

Question

Back in typedoc 0.23, I could use the @knodes/typedoc-plugin-code-blocks plugin to include bits of code from other files into markdown files which would end up as doc pages thanks to typedoc-plugin-pages.

For example, consider a source file examples/basic-usage.ts:

// #region import
import sum from '../src/sum'
// #endregion import

console.log(
  // #region functionCall
  sum(3, 4)
  // #endregion functionCall
)

and a markdown file pages/basic-usage.md:

# Sum

## Basic usage
### import the function
{@codeblock examples/basic-usage.ts#import}

### call the function
{@codeblock examples/basic-usage.ts#functionCall}

Then, in typedoc.json, I would have:

{
  "pluginPages": {
    "pages": [{
      "name": "Docs",
      "children": [{
        "name": "Basic Usage",
        "source": "basic-usage.md"
      }]
    }]
  }
}

Well, it seems the @knodes/typedoc-plugin-code-blocks plugin isn't compatible with more recent versions of typedoc…

Is it still possible do achieve something like this, perhaps using a different plugin? I tried using typedoc-plugin-include-example, but that seems only to work in typescript files and not in markdown files.

The reason I want this is because I want to include thoughtfully composed guides in my docs (hence the markdown) which include code samples that are taken directly from example files which I actually run in my tests. This ensures that the code samples in the docs never fall out of sync with the actual code and are all tested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedContributions are especially encouraged

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions