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

Adding examples (@example) to the documentation #135

Closed
bali182 opened this issue Sep 7, 2015 · 9 comments
Closed

Adding examples (@example) to the documentation #135

bali182 opened this issue Sep 7, 2015 · 9 comments
Labels
enhancement Improved functionality
Milestone

Comments

@bali182
Copy link

bali182 commented Sep 7, 2015

Thanks for the really great documentation tool!

I was wondering, if there is any way to add examples directly into the doccoment? I noticed, that adding custom tags like @whatever shows up in the generated documentation, and if I use the triple quote markdown syntax, I get syntax highlighting. It also looks like, that @example is not treated as a special annotiation. But is the @example & markdown combo the standard way of adding API examples to your source? Is there a standard way at all?

@sebastian-lenz
Copy link
Member

Hi Édes, nice to hear from you. TypeDoc currently has no explicit support for the @example tag, I've always preferred to include samples within the comment body itself using the markdown syntax for code blocks.

The "official" JSDoc implementation supports the @example tag, see here. TypeDoc is not aiming at being fully aligned to JSDoc but maybe we should give the @example special treatment too.

@sebastian-lenz sebastian-lenz added the enhancement Improved functionality label Sep 9, 2015
@bali182
Copy link
Author

bali182 commented Sep 10, 2015

Thanks for the quick response, Sebastian! I think, it would be a very nice extension of the existing functionality, if @example would be available :) If you consider adding it, let me know if I can help in any way!

@MartinSvarrer
Copy link

Just found this issue as I tried the same combination, expecting @example and code snippets to work together. Instead I just get a tag on top of my snippet, pushing my code.
image

@stepancar
Copy link

+1 need too:)

@tomlarkworthy
Copy link

I have tried triple markdown but the whitespace seems to get stripped? Some help on inserting code blocks would be greatly appreciated

@landonpoch
Copy link

I tried markdown syntax and it appears to work just fine. In my mind this issue isn't that critical. However, it might be nice to see the example tag show up above the examples that are included in the docs.

@jtraband
Copy link

jtraband commented Nov 7, 2016

Fenced code blocks do seems to have whitespace stripped. ( per comment above). This does make it difficult to include multiline examples in the docs.

@amarzavery
Copy link

amarzavery commented Oct 28, 2017

Update: I was able to preserve whitespaces/indentation. One needs to start the example with stars (*).

  /**
   * . . . 
   * @example
   * ```typescript
   * 
   *const resourceGroupName = 'res9101';
   *const accountName = 'sto4445';
   *const parameters: StorageManagementModels.StorageAccountCreateParameters = {
   *  sku: {
   *    name: <StorageManagementModels.SkuName>'Standard_GRS'
   *  },
   *  kind: <StorageManagementModels.Kind>'Storage',
   *  location: 'eastus2euap',
   *  tags: {
   *    "key1": "value1",
   *    "key2": "value2"
   *  }
   * };
   *const storageAccount = await client.storageAccounts.create(resourceGroupName, accountName, parameters);
   * ``` 
   * @param {string} resourceGroupName The name of the resource group within the
   * user's subscription. The name is case insensitive.
   * . . .
   */

As you can see the indentation is preserved in the example.

image

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Nov 26, 2021

With TypeDoc 0.23 (currently sitting on the beta branch, no release yet since I broke lots of things...), TypeDoc is much smarter about parsing comments, it will correctly handle indentation in code blocks, even without leading *s on each line.

Note: TypeDoc and JSDoc disagree about what an @example block contains. Both TypeDoc and TSDoc say that it contains regular text, like any other block, and may contain a code block. JSDoc says that the @example block is implicitly a code block.

@Gerrit0 Gerrit0 moved this from To do to Done in TSDoc - v0.23 Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality
Projects
No open projects
Development

No branches or pull requests

9 participants