Skip to content

Code blocks syntax highlighting specified in markdown ignored #874

@bettiolo

Description

@bettiolo

🐛 Bug Report

Language syntax specified in markdown code blocks is ignored, eg ```js and ```text render the same output.

Today's (27th July) revision #75538395beb3bcd7591f586877d5971c51d4f5db in master was supposed to contain the fix for the language highlighting.

In fact the css bug of language- <lang> is fixed and now the CSS attribute is language-<lang> without the space. This was fixed by #840

Have you read the [Contributing Guidelines on issues]

Yes

To Reproduce

Create a .md file with the following content:


---
title: EXAMPLE
---

```text
function $initHighlight(block, cls) {
  try {
    if (cls.search(/\bno\-highlight\b/) != -1)
      return process(block, true, 0x0F) +
             ` class="${cls}"`;
  } catch (e) {
    /* handle exception */
  }
  for (var i = 0 / 2; i < classes.length; i++) {
    if (checkCondition(classes[i]) === undefined)
      console.log('undefined');
  }
}

export  $initHighlight;
```

```js
function $initHighlight(block, cls) {
  try {
    if (cls.search(/\bno\-highlight\b/) != -1)
      return process(block, true, 0x0F) +
             ` class="${cls}"`;
  } catch (e) {
    /* handle exception */
  }
  for (var i = 0 / 2; i < classes.length; i++) {
    if (checkCondition(classes[i]) === undefined)
      console.log('undefined');
  }
}

export  $initHighlight;
```

Expected behavior

I would expect the output to be highlighted differently between text and js code blocks, like this:

function $initHighlight(block, cls) {
  try {
    if (cls.search(/\bno\-highlight\b/) != -1)
      return process(block, true, 0x0F) +
             ` class="${cls}"`;
  } catch (e) {
    /* handle exception */
  }
  for (var i = 0 / 2; i < classes.length; i++) {
    if (checkCondition(classes[i]) === undefined)
      console.log('undefined');
  }
}

export  $initHighlight;
function $initHighlight(block, cls) {
  try {
    if (cls.search(/\bno\-highlight\b/) != -1)
      return process(block, true, 0x0F) +
             ` class="${cls}"`;
  } catch (e) {
    /* handle exception */
  }
  for (var i = 0 / 2; i < classes.length; i++) {
    if (checkCondition(classes[i]) === undefined)
      console.log('undefined');
  }
}

export  $initHighlight;

Actual Behavior

With fixed code in master, highlightjs seems to ignore language syntax specified in the code block:

screen shot 2018-07-27 at 16 47 44

As you can see the CSS class name is fixed but ignored.

Reproducible Demo

Use node 8

git clone https://github.com/bettiolo/docusaurus-hl-bug.git
cd docusaurus-hl-bug/website
npm install
npm start

A browser will open and will show the bug:

screen shot 2018-07-27 at 17 26 25

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions