Skip to content

[typedoc-vitepress-theme]: Anchors generated by typdoc will not be compatible with vitepress if they contain colon #725

@aiktb

Description

@aiktb

What package is the bug related to?

typedoc-vitepress-theme

Describe the issue

For example, I have an object property named "build:before", the anchor generated by typedoc is "buildbefore", but the anchor generated by vitepress is "build-before".

More Information

function slugifyAnchor(anchor: string) {
return anchor
.toLowerCase()
.trim()
.replace(/[^\w\s-]/g, '')
.replace(/[\s_-]+/g, '-')
.replace(/^-+|-+$/g, '');
}

I noticed that the above implementation is wrong. Line 82 eliminates all non-alphanumeric and "-" characters, which is inconsistent with the implementation of VitePress.

https://github.com/vuejs/vitepress/blob/452d6c77a6afa43faa245452e7d0b360e55a36fb/src/node/markdown/markdown.ts#L16

I found the anchor generation code used by vitepress, we can reuse it.

https://github.com/mdit-vue/mdit-vue/blob/e0c38a4a7d0565a2c4c59dcfbb7e58aa38dc12e3/packages/shared/src/slugify.ts#L1-L25

TypeDoc configuration

{
  "$schema": "https://typedoc.org/schema.json",
  "entryPointStrategy": "packages",
  "entryPoints": ["../packages/wxt"],
  "plugin": [
    "typedoc-plugin-markdown",
    "typedoc-vitepress-theme",
    "typedoc-plugin-frontmatter"
  ],
  "out": "./api/reference",
  "githubPages": false,
  "excludePrivate": true,
  "excludeProtected": true,
  "excludeInternal": true,
  "readme": "none",
  "frontmatterGlobals": {
    "editLink": false
  }
}

Expected behavior

typedoc generates "build-before" anchor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue raised as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions