jsdoc-to-markdown icon indicating copy to clipboard operation
jsdoc-to-markdown copied to clipboard

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

Open DigitalBrainJS opened this issue 4 years ago • 4 comments

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.

DigitalBrainJS avatar Mar 24 '20 18:03 DigitalBrainJS

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..

75lb avatar Mar 25 '20 18:03 75lb

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.

DigitalBrainJS avatar Mar 25 '20 20:03 DigitalBrainJS

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 @.

75lb avatar Mar 25 '20 21:03 75lb

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 ...

DigitalBrainJS avatar Mar 25 '20 21:03 DigitalBrainJS