https://github.com/harttle/md-padding
AST-based padding for Markdown and natural language, improving readability in multilingual documents. Supports Vim and VSCode.
https://github.com/harttle/md-padding
ast fixer linter markdown vim vscode-extension
Last synced: about 1 month ago
JSON representation
AST-based padding for Markdown and natural language, improving readability in multilingual documents. Supports Vim and VSCode.
- Host: GitHub
- URL: https://github.com/harttle/md-padding
- Owner: harttle
- Created: 2020-01-28T09:06:05.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-24T14:52:38.000Z (2 months ago)
- Last Synced: 2025-03-29T19:07:52.600Z (about 1 month ago)
- Topics: ast, fixer, linter, markdown, vim, vscode-extension
- Language: TypeScript
- Homepage: https://harttle.land/md-padding/
- Size: 842 KB
- Stars: 63
- Watchers: 2
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# Markdown Padding
[](https://www.npmjs.org/package/md-padding)
[](https://www.npmjs.org/package/md-padding)
[](https://github.com/harttle/md-padding/actions/workflows/check.yml)
[](https://github.com/harttle/md-padding/actions/workflows/release.yml)
[](https://coveralls.io/github/harttle/md-padding?branch=master)
[](https://github.com/harttle/md-padding/issues)
[](https://github.com/harttle/md-padding/blob/master/LICENSE)English | [简体中文](https://github.com/harttle/md-padding/blob/master/README.zh.md)
**A tool for formatting Markdown content with padding**.
- *Ensures consistent spacing* before and after Markdown elements like *headings*, *lists*, and *code blocks*.
- *Aligns tables* by formatting column spacing properly.
- Supports formatting inside *code blocks* and recognizes *mathematical expressions*, *HTML elements*, *YAML front matter*, and *fenced code blocks* for correct formatting.
- Applies an extended AST parsing to ensure natural language structures like punctuations and latin characters are padded correctly.Here's a change made by md-padding:
```diff
- # 如何中ArchLinux中安装X11?
+ # 如何中 ArchLinux 中安装 X11?- 首先要安装ArchLinux,然后安装`xorg-server`软件包:
+ 首先要安装 ArchLinux,然后安装 `xorg-server` 软件包:- 确保你的xorg-server版本已经足够高,比如>=1.20,然后安装**合适**的驱动:
+ 确保你的 xorg-server 版本已经足够高,比如 >= 1.20,然后安装 **合适** 的驱动:- 如果你需要3D加速等新的功能,可能还需要安装*闭源驱动*。详情请参考[ArchWiki里的对应章节](https://wiki.archlinux.org/index.php/Xorg)。
+ 如果你需要 3D 加速等新的功能,可能还需要安装 *闭源驱动*。详情请参考 [ArchWiki 里的对应章节](https://wiki.archlinux.org/index.php/Xorg)。
```## Command Line Interface
```bash
npx md-padding -i README.md # fix the file in place
npx md-padding README.md # output the fixed content
```For more options:
```bash
> npx md-padding --help
md-padding [OPTION]...Options:
--help, -h Show help [boolean]
--version Show version number [boolean]
--in-place, -i Edit file in place [boolean]
--ignore-words, -I Ignore padding for specific words [string]
--ignore-patterns, -P Ignore specific patterns using regex [string]
--read-files, -r Read file list from input, one file per line [string]Examples:
stdout md-padding README.md
in-place md-padding -i README.md
pipe cat README.md | md-padding
ignore-words cat README.md | md-padding -I '=' '::'
ignore-patterns cat README.md | md-padding -P '=' ':+'
batch format cat list.txt | md-padding -r -i
equivalent w/ md-padding -r list.txt -i
```## Vim Integration
Map the `F6` key to format Markdown files:
```vim
" Hotkey for md-padding format
noremap :%!npx md-padding
```## VS Code Integration
Install the [Markdown Padding](https://marketplace.visualstudio.com/items?itemName=harttle.md-padding-vscode) extension.
- Open Command Palette (`Ctrl + Shift + P` on Windows/Linux, `Cmd + Shift + P` on macOS) and run `Markdown Padding`.
- Use the default formatting shortcut:
- `Shift + Alt + F` (Windows)
- `Shift + Option + F` (Mac)
- `Ctrl + Shift + I` (Linux)### Configuration
| Setting | Type | Description |
| -------------------------- | --------------- | ----------------------------------------------- |
| `mdpadding.ignoreWords` | `Array` | Words to exclude from padding adjustments |
| `mdpadding.ignorePatterns` | `Array` | Regular expressions defining patterns to ignore |## Q&A
### How to ignore a specific section
You can exclude certain sections from formatting using the `md-padding-ignore` directive:
```markdown
Some text before the ignored section.a*b=c, b>1 => a<c
This text will be formatted as usual.
```