20

I have a simple method in API, that allows searching objects with JSONPath. As its syntax is pretty much unfamiliar to junior developers, i decided to provide some examples within JSDoc comment. Yet, here is the catch, - @ sign is treated as a start of new jsdoc-tag, and so description becomes corrupted.

Question: how to make NetBeans (or jsdoc in general) ignore @ signs inside of particular code chunk ? Preferably, within @example block.

So this code, would show unmodified within tooltip:

$..book[?(@.price<10)] // - filter all books cheaper than 10

Also, @example, <code>, <pre> - do not help.

Html entity &#64; is converted to @ in tooltip, but it looks unreadable in the code itself ($..book[?(&#64;.price<10)]) and its only working in main jsdoc text ...

1
  • @ignore may work. Commented Aug 23, 2012 at 22:26

5 Answers 5

6

This is a pretty old question, but I was having the same problem, except in VSCode and thought I'd share a possible solution.

What finally worked was moving @returns below the example and, unfortunately, not using @example, e.g.:

/** * some description * * For example: * ```js * $..book[?(@.price<10)] // - filter all books cheaper than 10 * ``` * @returns {*} whatever you're returning */ 

This is not ideal, but works for VSCode's tooltip; I'm not sure if it'll work with NetBeans.

Sign up to request clarification or add additional context in comments.

1 Comment

If you download Netbeans and check that it works - i will gladly accept the answer 😀 p.s.: i don't have Netbeans on my machines anymore, so cannot verify it myself.
3

Not sure if this will work everywhere, but in Visual Studio Code, the blank braille character â € (U+2800) works well for escaping @:

/** * Persists an Subject's value to localStorage and restores it on initialization. * When the subject's value changes, it will automatically be saved to localStorage. * @example * ``` * class MyComponent { * â €@Persist() * public readonly theme$ = new Subject<string>('light'); // light by default * } * ``` */ 

Also, this character appears to be supported by Cascadia Mono—therefore it won't produce weird non-monospace offsets.

Comments

2

Not sure if this will work for all environments, but when using VSCode on a typescript (.ts) file I was able to use template strings to achieve nicely displayed example code

/** * @description * This function totally does something. * * @example``` import { SomeThing } from '@mycompany/my-cool-library'; DoSomething(SomeThing)``` * * @returns string */ 

Makes the tooltip display like:

escaping_the_@_sign

1 Comment

This also doesn't work for me but making the string a template string did, so using ` instead of ' around the string with @ in it
2

-- For anyone struggling with this in the future --

A round about solution is to use the 'ï¼ ' - U+FF20 character instead. It appears a little bit bigger than the actual '@' but does the job regardless of the editor/environment. This works as long as no one actually tries to copy the example code, in which case most modern editors/IDEs should highlight the unusual Unicode character.

1 Comment

...That is as long as no one actually tries to copy the example code - in which case they will get weird errors. Which I think is a pretty big drawback as copying an example seems like a fairly normal thing to do. So I would really call this "hack" rather than "proper" - but it is an interesting alternative at least.
1

All the answers here don't work for me.

Finally I found a solution: There's a plugin jsdoc-escape-at that allows to escape with backslash: \@

Example:

/** Implements Signal / Slot - Observer Pattern @example \@Emitter class A { constructor(private x) {} \@Signal test(x) {} emitTest = () => this.test(this.x) } */ export function Emitter(target: any) { // add function to register slot, called by Observer constructor target.prototype.__REGISTER_SLOT = function (key, slotFn) { ((this.__SLOTS ??= {})[key] ??= []).push(slotFn) } return target } 

Generates:

Emitter() Implements Signal / Slot - Observer Pattern Source: observe.ts, line 64 Example @Emitter class A { constructor(private x) {} @Signal test(x) {} emitTest = () => this.test(this.x) } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.