jsdoc2md / jsdoc-to-markdown

Generate markdown documentation from jsdoc-annotated javascript
MIT License
1.69k stars 152 forks source link

How do i escape an @ char in a code example block? #209

Open DigitalBrainJS opened 4 years ago

DigitalBrainJS commented 4 years ago

I need to document a decorator with an example, but this breaks the parser because jsdoc2md trying to parse decorators in the example block as jsdoc tag.

    /**
     * type decorator
     * @param {BasicType} type
     * @returns {MethodDecorator}
     * @alias module:define-accessor2#type
     * @example
     * class Cat {
     *   @string
     *   name = '';
     *   @type(string|number)
     *   foo= 123;
     * }
     */

Since jsdoc2md render an example block as a markdown code block I can't use & commat; to avoid this problem.

75lb commented 4 years ago

Does this comment block render correctly using jsdoc? Jsdoc2md sits downstream of jsdoc, so if it's broken in jsdoc it will be broken in jsdoc2md..

DigitalBrainJS commented 4 years ago

Yes, JSDoc has the same behavior (I thought the package has its own parser because of jsoc-parser in the dependencies), but since it renders docs as html it's possible to use html entries chars to avoid this issue. Unfortunately, since jsdoc2md renders examples as markdown code blocks without the ability to use html entries inside, I can't use this workaround. So, is there really no way to do post-processing of comments data after jsdoc parser? Does this package fully rely on parsed jsdoc data and has no access to raw data to make some fix? For example, just render commat; html entry to @ before render it to a code block.

75lb commented 4 years ago

I've looked into a workaround but unfortunately there's nothing I can do to stop jsdoc parsing the @ character in example blocks. It's a known issue.

Generally, you can use @ anywhere in jsdoc comments except within a code block, where github's markdown parser will print it literally as @ instead of @.

DigitalBrainJS commented 4 years ago

But this package could just replace @ to @ and then output it to a markdown block of code. This would not be an ideal solution, but acceptable to have at least some workaround for this issue.

     /**
     * type decorator
     * @param {BasicType} type
     * @returns {MethodDecorator}
     * @alias module:define-accessor2#type
     * @example
     * class Cat {
     *   @string
     *   name = '';
     *   @type(string|number)
     *   foo= 123;
     * }
     */

It doesn't look so bad ...