# Indenting of code blocks is incorrect when close to text

**URL:** https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799
**Category:** Bug
**Tags:** markdown-it-review
**Created:** [April 21, 2015, 1:33pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799 "2015-04-21T13:33:16Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [April 21, 2015, 1:33pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/1 "2015-04-21T13:33:16Z")

</div>

I believe there to be a bug or two in whatever version of highlight.js is being used in Discourse now.

See my test topic at Meta where the curly braces do not line up properly (under certain scenarios).  
[http://try.discourse.org/t/testing-code-tags/1227](http://try.discourse.org/t/testing-code-tags/1227)

What is the best approach for looking at getting this resolved?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 21, 2015, 2:01pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/2 "2015-04-21T14:01:14Z")

</div>

Can you test if this is still an issue in 8.5 [https://highlightjs.org/](https://highlightjs.org/) we want to upgrade anyway.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [April 21, 2015, 2:05pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/3 "2015-04-21T14:05:58Z")

</div>

> [@sam](#):
>
> Can you test if this is still an issue in 8.5 [https://highlightjs.org/](https://highlightjs.org/) we want to upgrade anyway.

It is just a matter of replacing highlight.js in the lib/highlight\_js/assets folder with the updated version right? If so, I’ll get it tested here shortly to see if it makes a difference.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 21, 2015, 2:38pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/4 "2015-04-21T14:38:38Z")

</div>

I had a rake task for this. have a search for it in the source tree.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [April 21, 2015, 2:55pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/5 "2015-04-21T14:55:37Z")

</div>

Yeah, I found it. I’m trying to get it running 😄  
(getting a lot of errors in the npm downloads, so I’ve got to track that down)

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [April 21, 2015, 3:32pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/6 "2015-04-21T15:32:25Z")

</div>

Hmm.. struggling to get this resolved (and there are a lot more further down still too)

```plaintext
/bin/sh: 1: node: not found
gyp: Call to 'node -e "require('nan')"' returned exit status 127. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/share/node-gyp/lib/configure.js:431:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.13.0-32-generic
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/discourse/discourse/tmp/highlight.js/node_modules/jsdom/node_modules/contextify
gyp ERR! node -v v0.10.25
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

```

Running it on  
Linux discourse 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86\_64 x86\_64 x86\_64 GNU/Linux

Seems I won’t get to this really quick and I’ve got a lot of meetings this afternoon.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 21, 2015, 6:37pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/7 "2015-04-21T18:37:06Z")

</div>

> [@cpradio](#):
>
> node: not found

you gonna need node.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [April 21, 2015, 8:23pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/8 "2015-04-21T20:23:38Z")

</div>

I did that.. via gem install, I’m out of the office now so I’ll have to try again tomorrow.

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [April 21, 2015, 9:35pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/9 "2015-04-21T21:35:38Z")

</div>

If you did `gem install node`, I’m afraid you got pranked. 😁  
Try `sudo apt-get install nodejs npm` instead.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [April 21, 2015, 10:01pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/10 "2015-04-21T22:01:23Z")

</div>

Okay, I know I did npm at work. Not sure why I though gem install node, but I swear that is what I did… I might not have though.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [April 22, 2015, 11:39am UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/11 "2015-04-22T11:39:39Z")

</div>

Okay, I don’t feel like I’m making any progress…

```plaintext
gyp: Call to 'node -e "require('nan')"' returned exit status 1. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/share/node-gyp/lib/configure.js:431:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.13.0-32-generic
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/discourse/discourse/tmp/highlight.js/node_modules/jsdom/node_modules/contextify
gyp ERR! node -v v0.10.25
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! Error: ENOENT, open '/home/discourse/discourse/tmp/highlight.js/node_modules/jsdom/node_modules/cssstyle/lib/properties/webkitLineBreak.js'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-@googlegroups.com>

npm ERR! System Linux 3.13.0-32-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! cwd /home/discourse/discourse/tmp/highlight.js
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR! path /home/discourse/discourse/tmp/highlight.js/node_modules/jsdom/node_modules/cssstyle/lib/properties/webkitLineBreak.js
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! weird error 1
npm ERR! tar pack Error reading /home/discourse/tmp/npm-3304-7qLObCBV/1429702602499-0.21514342329464853/package
npm ERR! tar pack Error reading /home/discourse/tmp/npm-3304-7qLObCBV/1429702602504-0.6174413014668971/package
npm ERR! tar pack Error reading /home/discourse/tmp/npm-3304-7qLObCBV/1429702602497-0.6347596128471196/package
npm ERR! addLocalDirectory Could not pack "/home/discourse/tmp/npm-3304-7qLObCBV/1429702602499-0.21514342329464853/package" to "/home/discourse/.npm/core-ut$
npm ERR! addLocalDirectory Could not pack "/home/discourse/tmp/npm-3304-7qLObCBV/1429702602504-0.6174413014668971/package" to "/home/discourse/.npm/isarray/$
npm ERR! addLocalDirectory Could not pack "/home/discourse/tmp/npm-3304-7qLObCBV/1429702602497-0.6347596128471196/package" to "/home/discourse/.npm/string_d$
npm ERR! Error: ENOENT, open '/home/discourse/tmp/npm-3304-7qLObCBV/1429702595790-0.5905938101932406/package/dist/handlebars.js'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-@googlegroups.com>

```

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [April 22, 2015, 12:18pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/12 "2015-04-22T12:18:42Z")

</div>

> [@cpradio](#):
>
> ```plaintext
> gyp ERR! node -v v0.10.25
> npm WARN This failure might be due to the use of legacy binary "node"
> npm WARN For further explanations, please read
> /usr/share/doc/nodejs/README.Debian
> 
> ```

Latest versions of node.js on Gentoo are 0.10.30 for `amd64` and 0.12.2-r1 for `~amd64` – perhaps you need a newer version and Debian is trailing too far behind again?

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [April 22, 2015, 12:20pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/13 "2015-04-22T12:20:31Z")

</div>

Well, that’s the confusing part. As the VM is Ubuntu… so I know it is Debian based, but it is using Ubuntu repos which is suggested as the distro to use for Discourse, right?

I feel like I’m missing something obvious here. I’ll dig around and see if I can find a more up to date repo for node… not sure if that would solve my problem or not though.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 22, 2015, 1:51pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/14 "2015-04-22T13:51:44Z")

</div>

Try pulling latest, I just updated

```plaintext
public function checkCredentials($username, $password)
{
    // ...
    $userDetails = $userQuery->fetch(PDO::FETCH_ASSOC);
    $isVerified = password_verify($password, $userDetails['password']);

    if ($isVerified) {
        session_start();
        $_SESSION['currentUser'] = $userDetails;
    }

    return $isVerified;
}

```

Seems to be working fine.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [April 22, 2015, 2:32pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/15 "2015-04-22T14:32:54Z")

</div>

Hmm…

```plaintext
public function checkCredentials($username, $password)
{
    // ...
    $userDetails = $userQuery->fetch(PDO::FETCH_ASSOC);
    $isVerified = password_verify($password, $userDetails['password']);

    if ($isVerified) {
        session_start();
        $_SESSION['currentUser'] = $userDetails;
    }

    return $isVerified;
}

```

Okay, what gives? (re-edit after hard refresh)

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 22, 2015, 3:51pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/16 "2015-04-22T15:51:55Z")

</div>

This bug has nothing to do with highlight js, our markdown parse is being insane. recategorizing as bug. (add newline here and indenting will be correct)

```plaintext
public function checkCredentials($username, $password)
{
    // ...
    $userDetails = $userQuery->fetch(PDO::FETCH_ASSOC);
    $isVerified = password_verify($password, $userDetails['password']);

    if ($isVerified) {
        session_start();
        $_SESSION['currentUser'] = $userDetails;
    }

    return $isVerified;
}

```

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [April 22, 2015, 3:56pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/17 "2015-04-22T15:56:53Z")

</div>

> [@sam](#):
>
> This bug has nothing to do with highlight js, our markdown parse is being insane. recategorizing as bug. (add newline here and indenting will be correct)

Thank you. I was starting to wonder that myself and I started in highlight.js as it seemed the obvious choice. It is also why I spent a lot of time trying to update highlight.js within Discourse so I could ensure I test it in relation to Discourse.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 26, 2017, 7:37pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/18 "2017-06-26T19:37:07Z")

</div>

This is fixed:

```plaintext
public function checkCredentials($username, $password)
{
    // ...
    $userDetails = $userQuery->fetch(PDO::FETCH_ASSOC);
    $isVerified = password_verify($password, $userDetails['password']);

    if ($isVerified) {
        session_start();
        $_SESSION['currentUser'] = $userDetails;
    }

    return $isVerified;
}

```

see:

> [@CommonMark testing started here!](https://meta.discourse.org/t/commonmark-testing-started-here/65121):
>
> Per our [migration plans](https://meta.discourse.org/t/discourse-commonmark-migration-plans-confetti-ball-balloon), I just enabled [markdown.it](https://github.com/markdown-it/markdown-it) at Meta. It is an excellent [CommonMark](http://commonmark.org/) compliant engine. I expect quite a few edges to be found during this period of testing. Do not open bugs about the new Engine, just reply here. I/we will be updating the top post here with the list of issues and striking out stuff as it is fixed. Current known issues (to be fixed)white_check_mark Onebox vanishes after you start typing and works not-super consistently white_check_mark pending…

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 26, 2017, 7:37pm UTC](https://meta.discourse.org/t/indenting-of-code-blocks-is-incorrect-when-close-to-text/27799/19 "2017-06-26T19:37:10Z")

</div>


