documentation icon indicating copy to clipboard operation
documentation copied to clipboard

How to replace ```javascript with ```js static in code blocks ? Is there a way to change the highlight language?

Open kopax opened this issue 7 years ago • 6 comments

Hi all, I have just tested documentjs and it work great.

The author of react-styleguidist recommended documentationjs after someone asked a question https://github.com/styleguidist/react-styleguidist/issues/445#issuecomment-302117671

I have issue with the generated markdown in the context of https://github.com/styleguidist/react-styleguidist

Type

  • [x] Bug

Reproduction

Generate a JSdoc for a function with @example and generate the markdown such as :

/**
 * @public
 * Create config provide our choice of configuration and some dynamic configuration
 * @name createConfig
 * @param {Object} config for react-styleguidist user configuration
 * @param {Object} options for extensions
 * @example
 * // returns config
 * createConfig({}, {});
 * @returns {Object} react-styleguidist configuration object
 */

The result look like

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## createStatus

### Parameters

-   `sau`  
-   `nie`  

Returns **[boolean][1]** 

## createConfig

### Parameters

-   `config` **[Object][2]** for react-styleguidist user configuration
-   `options` **[Object][2]** for extensions

### Examples

```javascript
// returns config
createConfig({}, {});
```

Returns **[Object][2]** react-styleguidist configuration object

[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

react-styleguidist recognize the \```javascript instead of the recommended \```js static for static example. Because of that, it try to render the js inside and this will break the documentation.

image

For static code highlight they recommend to use js static instead of javascript.

Is there a way to change the highlight language?

  • What version of documentation.js are you using?: 9.0.0-alpha.1
  • How are you running documentation.js (on the CLI, Node.js API, Grunt, other?): CLI

kopax avatar Nov 30 '18 06:11 kopax

Hi there,

This one's definitely not a bug. Markdown code highlighting blocks with javascript work perfectly fine as Markdown, react-styleguidist's unique interpretation is, well, not something for which documentation.js is responsible.

Assuming you're running documentationjs in a script, maybe try replacing ```javascript with your preferred code block language with a find & replace tool, like sed?

tmcw avatar Nov 30 '18 06:11 tmcw

@tmcw I am currently trying to find the proper solution for my users.

I am in the context of a package bundler boilerplate, and I do not know how the documentation will be written.

I've decided to follow your advice to use sed.

I'd like also to avoid generating the doc that are react components with documentationjs.

Isn't it possible to --exclude some pattern (like **/{components,containers}/** or `/[A-Z]/*)

Is that possible?

kopax avatar Nov 30 '18 07:11 kopax

I still have a draw back if I use sed.... and it is a bit annoying. We cannot use --watch and rebuild our documentation in live. Is there anything you could help with that?

kopax avatar Nov 30 '18 08:11 kopax

You should be able to do it with updateExample function:

https://react-styleguidist.js.org/docs/configuration#updateexample

sapegin avatar Dec 03 '18 15:12 sapegin

Thank you @sapegin, that was exactly what I was looking for. I've been through your documentation quite a few time and never saw this. Good catch

kopax avatar Dec 03 '18 16:12 kopax

I am reopening this.

So far we have found documentationjs good at generating our JSdoc, we want to be able to specify the lang used for the highlight.

In some case, we are showing node environment and providing a sandbox is something we might turn off by default.

I know this is related to react-styleguidist @sapegin, so far I am not sure where should I add this behavior, if it's in both and if it has to be a fork. Any recommendation on how to proceed and improve the overall experience?

Best regards

kopax avatar Dec 08 '18 04:12 kopax