Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typedoc-plugin-markdown] How to change title format #450

Closed
Dr-Electron opened this issue Jul 19, 2023 · 10 comments
Closed

[typedoc-plugin-markdown] How to change title format #450

Dr-Electron opened this issue Jul 19, 2023 · 10 comments
Labels
next Fix available in the '@next' release

Comments

@Dr-Electron
Copy link

Hi,
Currently we are using your project to create markdown files which we import in Docusaurus. But the title of the the pages is always Type: TypeName. For example: Class: SomeClass. In Docusaurus that creates the following sidebar structure:

Classes/
├── Class: SomeClass
└── Class: AnotherClass

Would be nice if the title could be customised to only have SomeClass as title.

I'm not sure if any other plugin like the frontmatter one could help here 🤔

@tgreyuk tgreyuk added next Fix available in the '@next' release and removed next Fix available in the '@next' release labels Jul 23, 2023
@NicolasThierion
Copy link

NicolasThierion commented Jul 28, 2023

I also wish there was an option to override the Handlebars helpers. At the moment, here is my hacky workaround:

    // override helper to exclude ReflectionKind from sidebar
    Handlebars.registerHelper(
      'reflectionTitle',
      function (shouldEscape = true) {
        const title = [''];
        title.push(
          shouldEscape ? escapeChars(this.model.name) : this.model.name,
        );
        if (this.model.typeParameters) {
          const typeParameters = this.model.typeParameters
            .map((typeParameter) => typeParameter.name)
            .join(', ');
          title.push(`<${typeParameters}${shouldEscape ? '\\>' : '>'}`);
        }
        return title.join('');
      },
    );
    const _registerHelper = Handlebars.registerHelper;
    Handlebars.registerHelper = function (...args): void {
      if (args[0] === 'reflectionTitle') {
        return;
      }

      return _registerHelper.apply(Handlebars, args);
    };

    function escapeChars(str) {
      return str
        .replace(/>/g, '\\>')
        .replace(/_/g, '\\_')
        .replace(/`/g, '\\`')
        .replace(/\|/g, '\\|');
    }

@Dr-Electron
Copy link
Author

@tgreyuk cool just tried out next and it works like intended.

But I had to remove the --theme markdown option for it to work.
And the docs went from looking like this:
Bildschirmfoto 2024-03-01 um 15 12 36

To this:
Bildschirmfoto 2024-03-01 um 15 12 58

Why is there a slash after Promise now? And also if I would like to keep the table format, would that be possible?

@tgreyuk
Copy link
Member

tgreyuk commented Mar 1, 2024

Hi @Dr-Electron,

Why is there a slash after Promise now?

There shouldn't be. Is this output from Docusaurus?

And also if I would like to keep the table format, would that be possible?

This can be achieved with --parametersFormat table. There is actually a bunch of new options https://www.typedoc-plugin-markdown.org/options .

@Dr-Electron
Copy link
Author

There shouldn't be. Is this output from Docusaurus?

We import it in docusaurus but it is not generated by the docusaurus plugin. (We pull the reference docs from outside of docusaurus).
Should I create another issue for that problem?

And also if I would like to keep the table format, would that be possible?

This can be achieved with --parametersFormat table. There is actually a bunch of new options https://www.typedoc-plugin-markdown.org/options .

Lovely ❤️ . Really nice changes you made in the next version ❤️

@tgreyuk
Copy link
Member

tgreyuk commented Mar 2, 2024

We import it in docusaurus but it is not generated by the docusaurus plugin. (We pull the reference docs from outside of docusaurus).

Ok, I assume you are using Docusaurus 2?. The issue is that the output is now MDX but Docusaurus is not MDX compatible (this is handled by the Docusaurus plugin). This looks to be the same issue as raised here #564 . I think the best thing here is to offer an opt-out of MDX.

@tgreyuk
Copy link
Member

tgreyuk commented Mar 2, 2024

@Dr-Electron in the mean time i've had another idea. You can use the docusaurus-plugin without executing build or start with an exposed cli command generate-typedoc. So you could install docusaurus-plugin-typedoc@next and then run docusaurus generate-typedoc rather than typedoc. This should fix/remove the escaped angle brackets.

@Dr-Electron
Copy link
Author

We import it in docusaurus but it is not generated by the docusaurus plugin. (We pull the reference docs from outside of docusaurus).

Ok, I assume you are using Docusaurus 2?. The issue is that the output is now MDX but Docusaurus is not MDX compatible (this is handled by the Docusaurus plugin). This looks to be the same issue as raised here #564 . I think the best thing here is to offer an opt-out of MDX.

Yeah we are still using docusaurus v2. I guess an update to v3 wouldn't help here either? 🤔

@Dr-Electron
Copy link
Author

@Dr-Electron in the mean time i've had another idea. You can use the docusaurus-plugin without executing build or start with an exposed cli command generate-typedoc. So you could install docusaurus-plugin-typedoc@next and then run docusaurus generate-typedoc rather than typedoc. This should fix/remove the escaped angle brackets.

The problem with this is, that I need to install docusaurus in that repo too. Only to generate the docs, which are then uploaded and used by the main docusaurus project 😅

@tgreyuk
Copy link
Member

tgreyuk commented Mar 4, 2024

Yeah we are still using docusaurus v2. I guess an update to v3 wouldn't help here either?

Upgrading to Docusaurus v3 will fix the issue.

The problem with this is, that I need to install docusaurus in that repo too.

Ok that makes sense. I think there does need to be a workaround for this.

@tgreyuk
Copy link
Member

tgreyuk commented May 4, 2024

Closing this as original issue fixed.

The mdx issues should be fixed by adding the following to docusuaurus.config:

  markdown: {
    format: 'detect'
  },

@tgreyuk tgreyuk closed this as completed May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next Fix available in the '@next' release
Projects
None yet
Development

No branches or pull requests

3 participants