typedoc2md / typedoc-plugin-markdown

A plugin for TypeDoc that enables TypeScript API documentation to be generated in Markdown.
https://typedoc-plugin-markdown.org
MIT License
702 stars 176 forks source link

Could not parse expression with acorn #680

Closed DavidBal closed 1 week ago

DavidBal commented 2 weeks ago

What package is the bug related to?

docusaurus-plugin-typedoc

Describe the issue

Here the full error message:

Module build failed (from ./node_modules/@docusaurus/mdx-loader/lib/index.js):
Error: MDX compilation failed for file "C:\Temp\Docusaurus\my-website\docs\api\SDK\*.CRMApplication\classes\ListContainers.md"
Cause: Could not parse expression with acorn
Details:
{
  "cause": {
    "pos": 1369,
    "loc": {
      "line": 60,
      "column": 341
    },
    "raisedAt": 9
  },
  "column": 342,
  "message": "Could not parse expression with acorn",
  "line": 60,
  "name": "60:342",
  "place": {
    "line": 60,
    "column": 342,
    "offset": 1369
  },
  "reason": "Could not parse expression with acorn",
  "ruleId": "acorn",
  "source": "micromark-extension-mdx-expression",
  "url": "https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression#could-not-parse-expression-with-acorn"
}

    at Object.mdxLoader (C:\Temp\Docusaurus\my-website\node_modules\@docusaurus\mdx-loader\lib\loader.js:130:25)

I have this in my ts file:

    /**
    * Liefert ein Objekt vom Typ {@link Container} mit dem angegebenen Namen zurück.  
    * Beim Erzeugen des ListContainers\-Objekts ist darauf zu achten, dass dabei {@link View.CurrentInputForm | CurrentInputForm(mode: InputFormMode)} (2) verwendet wird.Damit wird der aktuelle Modus des Containers samt aktuell selektiertem Datensatz beibehalten.
    *
    * @param containerName - Name des gewünschten Containers. Der Name setzt sich dabei wie folgt zusammen:  
    * Vollständige Relation(Achtung! Hier darf kein Relationsalias verwendet werden. Korrekt wäre bspw.ID.Aktivitäten.ContactID für die Relation zwischen Aktivitäten und Kontakten) + # + ID des entsprechenden Containers  (bspw. \{B3C0768A\-5599\-44B5\-B4F2\-7D31A6C10EC5\}).
    */
    public async ItemByName(containerName: string): Promise<Container> {

As you see { is escaped. But in the generated markdown the { is no longer escaped-

***

### ItemByName()

```ts
ItemByName(containerName): Promise<Container>

Liefert ein Objekt vom Typ Container mit dem angegebenen Namen zurück.
Beim Erzeugen des ListContainers-Objekts ist darauf zu achten, dass dabei CurrentInputForm(mode: InputFormMode) (2) verwendet wird.Damit wird der aktuelle Modus des Containers samt aktuell selektiertem Datensatz beibehalten.

Parameters

Parameter Type Description
containerName string Name des gewünschten Containers. Der Name setzt sich dabei wie folgt zusammen: Vollständige Relation(Achtung! Hier darf kein Relationsalias verwendet werden. Korrekt wäre bspw.ID.Aktivitäten.ContactID für die Relation zwischen Aktivitäten und Kontakten) + # + ID des entsprechenden Containers (bspw. {B3C0768A-5599-44B5-B4F2-7D31A6C10EC5}).

Returns

Promise\<Container>

Defined in



### TypeDoc configuration

[
      'docusaurus-plugin-typedoc',

      // Options
      {
        entryPoints: ["../SDK/*.ts", "../lib/*.ts"],
        tsconfig: '../tsconfig.json',
        exclude: 'src/**/*.tsx',
        parametersFormat: "table",
        interfacePropertiesFormat: "table",
        classPropertiesFormat: "table",
        enumMembersFormat: "table",
        typeDeclarationFormat: "table",
        propertyMembersFormat: "table",
        sidebar: { pretty: true },
        textContentMappings: {
          //"title.indexPage": "Example TypeDoc API",
          "title.memberPage": "{name}",
        },
        groupOrder: ["Classes", "Interfaces", "Enums"],
        useCodeBlocks: true
      },
    ],

### Expected behavior

The `{` should still be escaped after the markdown export.

Thank you for your help in advance.

Kind regards,
David
tgreyuk commented 2 weeks ago

Hi @DavidBal,

Because {} are reserved TSDoc/JSDoc characters (see https://typedoc.org/guides/doccomments/#escaping-comments) they will need to be double escaped.

ie you will need to write:

(bspw. \\{B3C0768A\-5599\-44B5\-B4F2\-7D31A6C10EC5\\})
DavidBal commented 2 weeks ago

Hi @tgreyuk,

thank's for your answer.

With the added \ the generated markdown looks fine.

But the comment in vscode now not looks fine...

image

Is there a way to get both sides working?

My first idea would be to run a replace just for the markdown generation from \{ -> \\{ and \} -> \\}.

Thanks again.

Kind regards, David

tgreyuk commented 2 weeks ago

As an alternative to escaping you could also try wrapping the braces in a single backtick like this:

(bspw. `{B3C0768A\-5599\-44B5\-B4F2\-7D31A6C10EC5}`)