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.

Rendering of indented code blocks concatenates lines

See original GitHub issue
  • [✅] I’ve read the [contribution guidelines] [✅] and agree with them

I’ve found a bug and checked that …

  • [✅] … the problem doesn’t occur with the default MkDocs template

  • [✅] … the problem is not in any of my customizations (CSS, JS, template)

  • [✅] … the documentation does not mention anything about my problem

    not that I have been able to find

  • [✅] … there are no open or closed issues that are related to my problem

    not that I have been able to find

Description

I think there is a rendering problem with code blocks that are indented inside bullet and numbered lists, where individual code block lines are concatenated.

Every other markdown rendering engine I have tried renders each line inside the code fence on a line by itself. Material is the only rendering engine that seems to concatenate lines.

Expected behavior

in this case, the rendering is by GitHub (ie this issue) between the horizontal rules:


Lead in:

  1. First:

    $ sudo apt update
    $ sudo apt upgrade -y
    
  2. Second.


Actual behavior

this is what Material seems to do (concatenation):


Lead in:

  1. First:

    $ sudo apt update $ sudo apt upgrade -y
    
  2. Second.


Package versions


$ python --version
Python 3.7.3

$ pip --version
pip 21.1.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)

$ mkdocs --version
mkdocs, version 1.1.2 from /home/pi/.local/lib/python3.7/site-packages/mkdocs (Python 3.7)

$ pip show mkdocs-material | grep -E ^Version
Version: 7.1.3

$ pip list | grep -e "^mkdocs"
mkdocs                      1.1.2
mkdocs-awesome-pages-plugin 2.5.0
mkdocs-material             7.1.3
mkdocs-material-extensions  1.0.1

System information

$ uname -a
Linux sec-dev 5.10.17-v7l+ #1403 SMP Mon Feb 22 11:33:35 GMT 2021 armv7l GNU/Linux
  • Browsers: The problem is “browser independent”. I have tried Safari, Firefox and Chrome, and on both macOS and iOS.

Test setup

Directory structure:

$ tree .
.
├── docs
│   └── test.md
└── mkdocs.yml

Test file:

$ cat docs/test.md
Lead in:

1. First:

	```
	$ sudo apt update
	$ sudo apt upgrade -y
	```

2. Second.

Dump of test file:

$ hexdump -C docs/test.md 
00000000  4c 65 61 64 20 69 6e 3a  0a 0a 31 2e 20 46 69 72  |Lead in:..1. Fir|
00000010  73 74 3a 0a 0a 09 60 60  60 0a 09 24 20 73 75 64  |st:...```..$ sud|
00000020  6f 20 61 70 74 20 75 70  64 61 74 65 0a 09 24 20  |o apt update..$ |
00000030  73 75 64 6f 20 61 70 74  20 75 70 67 72 61 64 65  |sudo apt upgrade|
00000040  20 2d 79 0a 09 60 60 60  0a 0a 32 2e 20 53 65 63  | -y..```..2. Sec|
00000050  6f 6e 64 2e 0a                                    |ond..|

No extraneous whitespace. No weird characters. Standard Unix 0x0A line-endings. Last line terminated properly.

Tests

Test 1 - material

$ cat mkdocs.yml 
site_name: Test
site_description: 'demonstrate concatenated code-block lines'
theme:
  name: material
  features:
    - tabs
  plugins:
    - search
    - awesome-pages
MATERIAL

Notes:

  1. Material runs the two sudo statements together.
  2. Apart from changing the site name and description, this mkdocs.yml is “as it comes” from SensorsIot/IOTstack. I have, however, repeated all these tests without the “awesome-pages” and it makes zero discernible difference to the outcome.

Test 2 - mkdocs

$ cat mkdocs.yml 
site_name: Test
site_description: 'demonstrate concatenated code-block lines'
theme:
  name: mkdocs
  features:
    - tabs
  plugins:
    - search
    - awesome-pages
MKDOCS

“mkdocs” renders the sudo statements on two lines.

Test 3 - readthedocs

$ cat mkdocs.yml 
site_name: Test
site_description: 'demonstrate concatenated code-block lines'
theme:
  name: readthedocs
  features:
    - tabs
  plugins:
    - search
    - awesome-pages
READTHEDOCS

“readthedocs” renders the sudo statements on two lines.

Test 4 - MacDown (side-by-side markdown editor)

MACDOWN

“MacDown” renders the sudo statements on two lines.

Other examples:

Compare/contrast:

LIVE

I don’t know what process is used to get the GitHub “original” to the mkdocs rendered version. The material point (pun intended) is that it doesn’t occur on my hardware so the test results shown in this issue aren’t likely to be explained by some peculiarity of my Raspberry Pi system.

It was, in fact, the other way around. I noticed the problem on the IOTstack documentation pages and set about trying to see whether I could replicate the problem on my own hardware. I could, so the problem appears to follow Material.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Paraphrasercommented, May 7, 2021

I did notice the misalignment but I didn’t think it polite to remark on it, particularly when I had no idea what was going on.

Again, many thanks for this.

1reaction
Paraphrasercommented, May 7, 2021

Brilliant! Thanks so much.

DF9C8DA7-8425-4410-8D09-6710A84BE083

Any idea why Material needs this extra option? I’m thinking that if all the other renderers I tried didn’t need a special setting, there must be some logical reason why Material has it off by default.

Read more comments on GitHub >

github_iconTop Results From Across the Web

md_indent: Markdown indented code block in gluedown: Wrap ...
Turn a character vector of lines into a single code block with each line indented four spaces. This markdown leaf block can be...
Read more >
R: Markdown indented code block - R-Project.org
Turn a character vector of lines into a single code block with each line indented four spaces. This markdown leaf block can be...
Read more >
Render a string in HTML and preserve spaces and linebreaks
As part of that I have a description (retrieved from a db) that has spaces and new lines. When it is rendered the...
Read more >
Fenced code blocks - CommonMark Spec
An indented code block cannot interrupt a paragraph, so if it occurs before or after a paragraph, there must be an intervening blank...
Read more >
Statement, Indentation and Comment in Python - GeeksforGeeks
The lines print('Logging on to geeksforgeeks…') and print('retype the URL.') are two separate code blocks. The two blocks of code in our example ......
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