Giter Club home page Giter Club logo

typedoc-plugin-mermaid's Introduction

GitHub Action CodeFactor npm version node version npm FOSSA Status License: MIT PRs Welcome All Contributors format: Biome test: Vitest build: Vite

typedoc-plugin-mermaid

A plugin for TypeDoc that generates graphs for mermaid.js diagrams by @mermaid annotation.

Installation

The plugin can then be installed using npm:

NPM

# npm
npm install --save-dev typedoc-plugin-mermaid
# or yarn
yarn add -D typedoc-plugin-mermaid

Add this plugin in your typedoc.json:

{
  "plugin": ["typedoc-plugin-mermaid"]
}

If you use the @mermaid tag in your tsdoc comments, add typedoc-plugin-mermaid/tsdoc.json to the extends of tsdoc.json:

{
  "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
  "extends": [
    "typedoc-plugin-mermaid/tsdoc.json"
  ]
}

Usage

Write tsdoc with @mermaid annotations:

/**
 * Hoge is sample class for example of `typedoc-plugin-mermaid`.
 *
 * @mermaid Make TypeDoc easy to use with mermaid.js
 * graph TB
 *   mermaid.js --> TypeDoc;
 */
export class Hoge { }

Or use fenced code blocks:

/**
 * Mermaid code blocks are automatically detect and converted.
 *
 * ```mermaid
 * graph TB
 *   mermaid.js --> TypeDoc;
 * ```
 */
export class Mermaid { }

↓↓ DEMO ↓↓

Example

Arguments

The following arguments can be used in addition to the default TypeDoc arguments.

$ typedoc --help
...
Options:
 --mermaidVersion            [Mermaid Plugin] The version of mermaid.js to use.
...
  • --mermaidVersion

    Specify mermaid.js version to use.

    Default: latest, Example: 8.14.0

Contributors

Thanks goes to these wonderful people (emoji key):

Yuki Yamazaki
Yuki Yamazaki

🤔 💻 ⚠️ 📖
Bob Kerns
Bob Kerns

🐛 💻
Emily Marigold Klassen
Emily Marigold Klassen

💻 ⚠️
Mathieu Jalbert-Claveau
Mathieu Jalbert-Claveau

🐛
Michael Schmidt
Michael Schmidt

💻 ⚠️ 📖
Carl Fürstenberg
Carl Fürstenberg

🐛 🚇
Will Henderson
Will Henderson

💻 🐛 💡
guryanovev
guryanovev

🐛
Ricardo Ferreira
Ricardo Ferreira

🤔
Maneet Goyal
Maneet Goyal

🤔
Juergen Zimmermann
Juergen Zimmermann

🐛
Michal Kindl
Michal Kindl

️️️️♿️
Ludovic Muller
Ludovic Muller

️️️️♿️

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This software is released under the MIT License, see LICENSE.

FOSSA Status

typedoc-plugin-mermaid's People

Contributors

allcontributors[bot] avatar azatoth avatar bobkerns avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar forivall avatar fossabot avatar github-actions[bot] avatar kamiazya avatar rundevelopment avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

typedoc-plugin-mermaid's Issues

Mermaid 8.8.1 introduced a visual regression

Describe the bug
Just want to bring to your attention that mermaid 8.8.1 brought a visual regression described here, where basically leaves a huge top and bottom whitespace.

I guess this needs to be fixed at mermaid level but wanted to shared with the others if they ever face the same issue and not spending the time for finding the problem.

The current workaround would be to change the unpkg.com url from https://unpkg.com/mermaid/dist/mermaid.min.js to https://unpkg.com/[email protected]/dist/mermaid.min.js.

Change mermaid.js version

Is your feature request related to a problem? Please describe.
Unlike the version that mermaid.js usually uses, errors may occur.

Describe the solution you'd like
Allows specification of command version as option.

Describe alternatives you've considered
Support only the latest version.

Breaking changes against typedoc 0.22.x

Seems they've added new breaking changes to typedoc that affects plugin loading; Trying to use the plugin with 0.22.5 results in following:

Error: The plugin typedoc-plugin-mermaid could not be loaded.
Error: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/lib/converter' is not defined by "exports" in /home/azatoth/project/node_modules/typedoc/package.json
    at new NodeError (internal/errors.js:322:7)
    at throwExportsNotFound (internal/modules/esm/resolve.js:322:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:545:3)
    at resolveExports (internal/modules/cjs/loader.js:450:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/home/azatoth/project/node_modules/typedoc-plugin-mermaid/dist/index.js:6:17)

Seems to be related to TypeStrong/typedoc#1696

mermaid initialize options

Is your feature request related to a problem? Please describe.
I want to pass on the securityLevel in the .initialize() options of mermaid.
This to enable the click functionality.

Describe the solution you'd like
Provide an additional option for typedoc, similar to the --mermaidVersion option, where the mermaid initialize options can be passed.

Describe alternatives you've considered
N/A

Additional context
N/A

Plugin now unusable due to typedoc change+bug: need to remove @Option

Describe the bug
In src/plugin.ts, the following appears:

  @Option({
    name: 'mermaidVersion',
    short: 'mmv',
    defaultValue: '7.1.2',
    help: 'Mermaid Plugin: Version of mermaid.js.',
    type: ParameterType.String,
  })

Unfortunately, @Option has been deprecated and slated to be removed in typedoc 0.17.
Even worse, it is broken in 0.16.9! This prevents your module from loading in 0.16.9

I tried to work around it by setting mermaidVersion in typedoc.json, but it didn't work. (I didn't expect it to).

To Reproduce
Steps to reproduce the behavior:

  • Upgrade to typedoc 0.16.9
  • Install typedoc-plugin-mermaid@latest
  • Run typedoc
  • Get the results below

Expected behavior
Successful run

Failing output

The @Option decorator is deprecated and will be removed in v0.17.
  (Used to register mermaidVersion)
Loaded plugin /Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc-plugin-mermaid
Loaded plugin /Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc-plugin-npm-externals

Using TypeScript 3.7.5 from /Users/rwk/p/npm-typescript-rollup-template/node_modules/typescript/lib
Skipping detailed PlantUml-Generation.
/Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc/dist/lib/utils/options/sources/decorator.js:19
                    return this.application.options.getValue(name);
                                                             ^

ReferenceError: name is not defined
    at MermaidPlugin.get [as mermaidVersion] (/Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc/dist/lib/utils/options/sources/decorator.js:19:62)
    at MermaidPlugin.get customScriptsAndBodyClosinngTag [as customScriptsAndBodyClosinngTag] (/Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc-plugin-mermaid/dist/plugin.js:21:37)
    at MermaidPlugin.convertPageContents (/Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc-plugin-mermaid/dist/plugin.js:61:66)
    at MermaidPlugin.onPageEnd (/Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc-plugin-mermaid/dist/plugin.js:83:34)
    at triggerEvents (/Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc/dist/lib/utils/events.js:128:43)
    at triggerApi (/Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc/dist/lib/utils/events.js:110:13)
    at eventsApi (/Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc/dist/lib/utils/events.js:21:18)
    at Renderer.trigger (/Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc/dist/lib/utils/events.js:264:13)
    at Renderer.renderDocument (/Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc/dist/lib/output/renderer.js:49:14)
    at /Users/rwk/p/npm-typescript-rollup-template/node_modules/typedoc/dist/lib/output/renderer.js:36:22

Additional context
I didn't bother to report it to typedoc, since they plan to remove it anyway in their next release, so that would be their fix, and you'll still have to change your code.

Sequence diagram misses arrows

Describe the bug
Sequence diagrams do not display any arrows when rendered

To Reproduce
Steps to reproduce the behavior:

  1. Just try rendering sample sequence diagram
sequenceDiagram
    Alice->>+John: Hello John, how are you?
    Alice->>+John: John, can you hear me?
    John-->>-Alice: Hi Alice, I can hear you!
    John-->>-Alice: I feel great!

Expected behavior
Arrows should display according to the mermaid syntax

Screenshots
image

Additional context

The reason is probably the fact that there are 2 versions rendered: light and dark

image

And arrows markers are referenced by id:

image

So id's got duplicated and light-theme svg tries to display markers from dark-theme svg

Fetch mermaid graph markdown from README.md

Is your feature request related to a problem? Please describe.

  1. Want to render a Mermaid graph before each class (this plugin already does that).
  2. But the Mermaid graph's markdown is stored in a README.md adjacent to the class.ts[x] file.
  3. Here's an example.
  4. Problem is I am not able to load that graph's markdown so that it can be rendered in TypeDoc.
  5. An entire community of users growing around StencilJS can benefit from this feature.

Describe the solution you'd like

  1. Currently, this plugin allows:
/**
 * Hoge is sample class for example of `typedoc-plugin-mermaid`.
 *
 * @mermaid Make TypeDoc easy to use with mermaid.js
 * graph TB
 *   mermaid.js --> TypeDoc;
 */
export class Hoge { }
  1. It will be great if a relative/path/to/graph can also be supported as alternate to inline graph.
/**
 * Hoge is sample class for example of `typedoc-plugin-mermaid`.
 *
 * @mermaid Make TypeDoc easy to use with mermaid.js
 * mermaid-path: relative/path/to/graph
 */
export class Hoge { }
  1. The plugin loads the markdown file, extracts the mermaid graph and renders it as usual.

nomnoml を表示したい

こんにちは
素晴らしい ライブラリ ですね

Is your feature request related to a problem? Please describe.
nomnoml を 表示したいです
https://github.com/skanaar/nomnoml

Additional context
typedoc-plugin-mermaid の名前だと nomnoml を表示することにそぐわないですが...

Add support for dark theme

Is your feature request related to a problem? Please describe.
TypeDoc 0.22.x added support for dark themes and switching between light and dark themes. This is a problem for this plugin because Mermaid's default theme uses black lines for arrows which makes them invisible on a dark background.

Describe the solution you'd like
This plugin should support both light and dark themes. It should automatically use an appropriate theme depending on whether TypeDoc's light or dark theme is currently active.

Breaking change after upgrade to typedoc 0.23.1

Describe the bug
After upgrading to typedoc 0.23.1 I get the stacktrace below

To Reproduce
Steps to reproduce the behavior:
npm i -D typedoc

Expected behavior
No stacktrace.

Desktop (please complete the following information):

  • OS: Windows 11 Enterprise
  • Version: 21H2

Additional context
Stacktrace:

TypeDoc exiting with unexpected error:
TypeError: Cannot read properties of undefined (reading 'replace')
    at MermaidPlugin.handleMermaidCodeBlocks (C:\workspace\software-engineering\buch\node_modules\typedoc-plugin-mermaid\dist\index.js:163:21)
    at MermaidPlugin.onConverterResolveBegin (C:\workspace\software-engineering\buch\node_modules\typedoc-plugin-mermaid\dist\index.js:135:37)
    at Converter.<anonymous> (C:\workspace\software-engineering\buch\node_modules\typedoc-plugin-mermaid\dist\index.js:119:18)
    at triggerEvents (C:\workspace\software-engineering\buch\node_modules\typedoc\dist\lib\utils\events.js:191:43)
    at triggerApi (C:\workspace\software-engineering\buch\node_modules\typedoc\dist\lib\utils\events.js:167:13)
    at eventsApi (C:\workspace\software-engineering\buch\node_modules\typedoc\dist\lib\utils\events.js:60:18)
    at Converter.trigger (C:\workspace\software-engineering\buch\node_modules\typedoc\dist\lib\utils\events.js:389:13)
    at Converter.resolve (C:\workspace\software-engineering\buch\node_modules\typedoc\dist\lib\converter\converter.js:123:14)
    at Converter.convert (C:\workspace\software-engineering\buch\node_modules\typedoc\dist\lib\converter\converter.js:39:14)
    at Application.convert (C:\workspace\software-engineering\buch\node_modules\typedoc\dist\lib\application.js:151:40)

Issues with TypeDoc 0.25.x

Describe the bug
I upgraded to TypeDoc 0.25.x on my project, and the rendering of the mermaid graph I have on my README.md file is not working anymore.
It was working well with previous versions.

Expected behavior
The mermaid graph on the README.md file should be rendered.

Additional context
I'm using the latest version of typedoc-plugin-mermaid.

It is working as expected with 0.23.x and 0.24.x TypeDoc versions.

When I run TypeDoc, it's also showing the following line in the console:

Loaded plugin typedoc-plugin-mermaid

Which is not the case anymore with 0.25.x.

Class Diagram

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

mermaid from imported markdown files

Describe the bug
When importing a file into typedoc using [[include:path/to/file.md]], mermaid tags will not be handled and it will complain it can't highlight it.

To Reproduce

Steps to reproduce the behavior:

  1. Create typescript foo.ts:
/**
 * [[include:foo.md]]
 */
export class Foo {

}
  1. Create foo.md with:
# Foo

```mermaid
  flowChart TB
    A --> B
```
  1. Execute typedoc:
    typedoc src/foo.ts --logLevel Verbose --includes src/

Info: Loaded plugin typedoc-plugin-mermaid
Debug: Using TypeScript 4.3.5 from ./node_modules/typescript/lib
Debug: Converting with 1 programs 1 entry points
Debug: Finished getting entry points in 7598ms
Debug: Begin readme search at ./src
Debug: Finished conversion in 99ms
Debug: Renderer: Loading highlighter took 472ms
Warning:
Unsupported highlight language "mermaid" will not be highlighted. Run typedoc --help for a list of supported languages.
target code block :
flowChart TB
A --> B
source files :undefined
output file :
undefined
Info: Documentation generated at ./docs
Debug: HTML rendering took 493ms

  1. See error

Expected behavior
I expect mermaid blocks be rendered from the included markdown file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.