Table of Contents
You can use this site to generate the code for you. For example:
## Table of Contents
- [Prerequisites](#prerequisites)
- [Create](#create)
---
## Prerequisites
- Stuff
- Things
---
## Create
- More stuff
- More things
Resource: https://stackoverflow.com/questions/11948245/markdown-to-create-pages-and-table-of-contents
Add line break
Simply add two spaces after the line that you want to break on.
Resource: https://stackoverflow.com/questions/26626256/how-to-insert-a-line-break-br-in-markdown
Markdown Lint rules in VSCode
Rules can be defined in the settings.json:
"markdownlint.config": {
"MD002": false,
"MD004": false,
"MD012": false,
"MD013": { "code_blocks": false, "line_length": 80 },
"MD029": false,
"MD032": false,
"MD033": false,
"MD034": false,
"MD041": false,
"ignore": ["**/themes/**"]
},
Markdown Lint Fixes
MD005 Inconsistent indentation for list items at the same level:
FILE=docs/container.md # Get line numbers of all list items list_item_lines=$(grep -n -E '^ +(-|\*|\d+\.)' $FILE | cut -f1 -d:) IFS=$'\n' for line_number in $list_item_lines; do # Get the current line's indentation level current_indent=$(sed -n "${line_number}p" $FILE | sed -E 's/^ +//; s/[^ ].*//') # Find the closest preceding list item previous_list_item=$(sed -n "1,${line_number}p" $FILE | tac | grep -m1 -E '^ +(-|\*|\d+\.)') previous_indent=$(echo "$previous_list_item" | sed -E 's/^ +//; s/[^ ].*//') # Calculate the correct indentation if [ -z "$previous_indent" ]; then correct_indent=" " else correct_indent="$previous_indent" fi # Replace the current indentation with the correct indentation sed -i "${line_number}s/^${current_indent}/${correct_indent}/" $FILE done
MD013 Line length:
FILE=path/to/file.md sed -E 's/(.{80}[^ ]*) /\1\n/g' -i $FILE
MD022 Headers should be surrounded by blank lines:
FILE=file.md sed -E -i 's/^(#+\s+)(.*)$/\n\1\2\n/g' $FILE