question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does Docz support syntax highlighting outside of Playground?

See original GitHub issue

Question

Does Docz support syntax highlighting outside of the Playground component?

Description

In addition to adding React component documentation, I am using Docz to document an entire system, at least half of which has nothing to do with React. Therefore, I need the ability to add “other” code snippets with the appropriate syntax highlighting.

For example, this does not seem to work:

Inside my file.mdx: screen shot 2018-09-10 at 6 56 11 pm

It produces the following in the docz-theme-default theme:

screen shot 2018-09-10 at 6 53 01 pm

The syntax highlighting for SCSS is not working. Syntax highlighting outside of the Playground, in general, does not work well, even for Javascript snippets.

Am I doing something wrong? Does Docz support this? Or maybe this is an MDX problem?

If this does not work, how can I help?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
meebixcommented, Sep 12, 2018

@pedronauck - I think we should reopen this. The above gets rid of the “Codemirror not defined” error, but the hightlight does not work. Let me explain what I tested.

From the Codemirror docs, it appears that hightlighting for scss or less comes directly from the CSS mode in the form of mime types, which are text/x-scss and text/x-less. Therefore, you do not need to import another package. Importing the CSS mode is good enough.

You would think you could also pass mode: 'scss' but for some reason you cannot. The highlighting does not work.

screen shot 2018-09-12 at 2 50 45 pm

It does work if you pass mode: 'text/x-scss'.

screen shot 2018-09-12 at 2 52 52 pm

Weird, right?

Since you already import the CSS package here: https://github.com/pedronauck/docz/blob/master/packages/docz-theme-default/src/components/ui/Editor/index.tsx#L21

I propose that to at least support scss and less in addition to css, we make an immediate change like this:

const getLanguage = (children: any) => {
  const defaultLanguage = 'jsx'
  if (typeof children === 'string') return defaultLanguage
  const language = get(children, 'props.props.className') || defaultLanguage
  const result = language.replace('language-', '')
  if (result === 'js' || result === 'javascript') return 'jsx'
  if (result === 'scss') return 'text/x-scss'
  if (result === 'less') return 'text/x-less'
  return result
}

Link to code

Down the road, more changes will be necessary to allow syntax highlighting for other languages such as “Ruby” for instance.

It does not seem that adding a package like https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.40.0/mode/ruby/ruby.min.js will be good enough to support different syntax highlighting for different languages.

What do you think?

3reactions
drewlustrocommented, Jun 7, 2019

Yeah can we reopen this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get syntax highlighting to work? #1292 - doczjs/docz
I have just migrated my docz to V2 and the syntax highlighting (outside Playground) is no longer working (it was working earlier in...
Read more >
Code blocks | Docusaurus
Use the matching language meta string for your code block, and Docusaurus will pick up syntax highlighting automatically, powered by Prism ...
Read more >
How to Use Syntax Highlighting with TinaMarkdown - Tina.io
Today we are going to walk you through how to use syntax highlighting with TinaMarkdown. Through a very basic setup and example we...
Read more >
Syntax Highlighting | Hugo
Highlighting is carried out via the built-in highlight shortcode. It takes exactly one required parameter for the programming language to be highlighted and ......
Read more >
Syntax Highlighting - Tree-sitter
The Tree-sitter syntax highlighting system can help you to achieve this by keeping track of local scopes and variables. The local variables query...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found