Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Code Rules

These rules ensure proper formatting of code blocks and inline code in markdown documents.

Rules in This Category

  • MD040 - Fenced code blocks should have a language specified
  • MD014 - Dollar signs used before commands without showing output
  • MD031 - Fenced code blocks should be surrounded by blank lines
  • MD038 - Spaces inside code span elements
  • MD046 - Code block style
  • MD048 - Code fence style

Why Code Rules Matter

Proper code formatting:

  • Enables syntax highlighting for better readability
  • Maintains consistency across code examples
  • Improves copy-paste reliability
  • Ensures proper rendering in different viewers
  • Helps readers identify programming languages quickly

Code Block Styles

```javascript
function example() {
    return "Hello, world!";
}
```

Indented Code Blocks

    function example() {
        return "Hello, world!";
    }

Inline Code

Use the `console.log()` function to debug.

Language Specifications

Common language tags for syntax highlighting:

LanguageTags
JavaScriptjs, javascript
TypeScriptts, typescript
Pythonpy, python
Rustrs, rust
Shellsh, bash, shell
JSONjson
YAMLyml, yaml

Quick Configuration

# .mdbook-lint.toml

# Configure MD040 - Require language tags
[MD040]
allowed_languages = ["js", "python", "rust", "bash"]

# Configure MD046 - Code block style
[MD046]
style = "fenced"  # Options: "fenced", "indented", "consistent"

# Configure MD048 - Code fence style
[MD048]
style = "backtick"  # Options: "backtick", "tilde", "consistent"

Best Practices

  1. Always specify language: Enables syntax highlighting
  2. Use fenced blocks: More flexible than indented blocks
  3. Surround with blank lines: Improves readability
  4. Be consistent: Use the same style throughout
  5. Escape special characters: Use backslash when needed

Shell Commands

# Good - shows command without prompt
npm install mdbook-lint

# Avoid - dollar sign without output
$ npm install mdbook-lint