documentationjs / documentation

:book: documentation for modern JavaScript
http://documentation.js.org/
Other
5.79k stars 481 forks source link

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

Open kopax opened 5 years ago

kopax commented 5 years ago

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

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?

tmcw commented 5 years ago

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?

kopax commented 5 years ago

@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 commented 5 years ago

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?

sapegin commented 5 years ago

You should be able to do it with updateExample function:

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

kopax commented 5 years ago

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 commented 5 years ago

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