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.

MD046 assumes block indents are bad if they are a part of lists.

See original GitHub issue

Description

MD046 incorectly flags all fenced code blocks as violations even if they are a part of lists.

Motivating example:

1. Here is my list item

    ```bash
    # example code
    ```
2. Here is my next list item.

which I expect to render as follows:


  1. Here is my list item

    # example code
    
  2. Here is my next list item.


The vscode markdownlint extension flags this as a violation of MD046 but if I follow the advice on the MD046 wiki page then I get the following rendering:

Example following MD046 advice:

1. Here is my list item

```bash
# example code
``` <!-- space added here to prevent rendering errors in comment-->

2. Here is my next list item.

Rendered result:


  1. Here is my list item
# example code
  1. Here is my next list item.

which is not how I want the list to appear in its rendered form.

Possible Resolutions:

It seems like there are two approaches that could be used to fix this issue:

  1. broaden MD046 to allow for these cases when in lists. (both formations are valid so it probably just needs to be disabled when immediately following list items (ordered or unordered)
  2. Allow the visual studio code extension to ignore specific violations.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
DavidAnsoncommented, Oct 19, 2020

@MichaIng Your failing test run reports an issue with docs/dietpi_tools.md, but your example and link are for a different file.

Looking at the reported file, we see code fences on lines 7 and 17, so the report of an indented code block on line 27 being inconsistent is correct.

https://github.com/MichaIng/DietPi-Docs/blame/b9ac99eab398f0b850eac7460ea8267f06bf0c4e/docs/dietpi_tools.md

0reactions
MichaIngcommented, Oct 19, 2020

Many thanks for mentioning CommonMark, good to know there is such a specification, only sad that Python-Markdown core + standard library extensions do not fulfil it completely (e.g. fenced code in list items is not possible) so that pymdownx needs to be used for that, while other extensions of pymdownx are not part of CommonMark. Not a real issue but that makes it difficult for newcomers to differentiate between common/specified syntax that is usually interpreted correctly and uncommon syntax where one has to expect failures of code quality/syntax tests 😅.

But all fine, I see that these content tabs a very uncommon and conflict with some header and thematic break syntax. So the effort to implement support is likely too large effort to be reasonable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code block style [Expected: indented; Actual: fenced]
I 'm assuming your are using the markdownlint plugin for VSCode. ... you desire, I will note that there are multiple options for...
Read more >
Markdownlint Rules
Note: This rule applies to a sublist only if its parent lists are all also unordered (otherwise, extra indentation of ordered lists interferes...
Read more >
Implement ```-style (fenced) Markdown code blocks
Fenced code blocks are like Markdown's regular code blocks, except that they're not indented and instead rely on a start and end fence...
Read more >
Indenting C Programs
Selection Statements: IF, IF-ELSE, and SWITCH. In this section, I present a variety of code examples to demonstrate how to indent various forms...
Read more >
IndentationError: expected an indented block
In most popular programming languages, spaces or indentation are just used to make the code look better and be easier to read. In...
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