Markdown 字符压缩器 语言 | 英文 | 简体 中文 一个强大的工具,用于使用渲染感知验证来压缩 Markdown 文件。 安全模式 …
Markdown 字符压缩器 语言 | 英文 | 简体 中文 一个强大的工具,用于使用渲染感知验证来压缩 Markdown 文件。 安全模式 …
A powerful tool to compress Markdown files with render-aware verification. safe mode prioritizes rendering stability, while aggressive mode targets higher compression with possible mismatch risk.
[2026.04.09] Support Claude Skills: https://github.com/hydrogenhy/md-char-compressor-skill
[2026.04.06] Available online: https://shorter-re.streamlit.app/
[2026.04.05] Initial release.
https://github.com/user-attachments/assets/6cec05f5-1b85-4d8f-b9c5-2a6782781de6
pip install -e .Interactive side-by-side editor and preview (embedded HTML iframe rendering):
streamlit run ui/app.pyOne-command conversion:
python main.py source.md target.mdWith options:
python main.py source.md target.md --mode aggressive --contribution report.jsonsafe (recommended default): Uses low-risk rules and is best for final submissions that require stable rendering.aggressive: Enables medium/high-risk rules for stronger compression; can introduce render mismatches in some edge cases.aggressive first, then switch to safe or disable risky rules if verification reports mismatch.--mode safe|aggressive Compression mode (safe = stability, aggressive = max savings)
--verify/--no-verify Enable render equivalence check (default: enabled)
--strict-verify Fail if verification fails
--report FILE Output detailed JSON report
--contribution FILE Output rule contribution breakdown
--only-rule RULE_ID Run only specific rules (repeatable)
--skip-rule RULE_ID Skip specific rules (repeatable)These rules may alter edge-case parsing in some renderers.
\alpha → α, \rightarrow → →, etc.These rules can increase compression significantly, but are the most likely source of render mismatch.
Supported macro replacements include:
Running with contribution report:
=== Rule Contribution Report ===
Total chars saved: 642
1. collapse-intra-line-spaces 368 chars ( 57.3%)
2. trim-table-cell-padding 136 chars ( 21.2%)
3. math-trim-spaces 42 chars ( 6.5%)
4. math-macro-to-unicode 42 chars ( 6.5%)
...Custom rules can be used directly from the CLI with a Python file that exports CUSTOM_RULES.
python main.py file.md out.md --custom-rules my_rules.pyThe Python file should define:
CUSTOM_RULES = [rule1, rule2, ...]from mdcompressor.rules.custom_rules import CustomReplacementRule
rule = CustomReplacementRule(
rule_id="my-shorthand",
description="Replace common phrases",
replacements={
"therefore": "∴",
"because": "∵",
},
targets={"text"},
risk="medium"
)from mdcompressor.rules.custom_rules import CustomFunctionRule
def my_compressor(text: str) -> str:
return text.replace(" ", " ")
rule = CustomFunctionRule(
rule_id="my-function",
description="Custom compression",
func=my_compressor,
targets={"text"},
risk="low"
)You can place both replacement and function rules into the same CUSTOM_RULES list and load them together from the CLI.
Default: GitHub Flavored Markdown (GFM)
The tool compares normalized HTML before/after:
Strict verification (--strict-verify) will reject output if rendering differs.
Notes:
safe mode should be preferred when visual equivalence is mandatory.aggressive mode may trigger mismatch on formula-heavy content or renderer-specific edge cases.python main.py rebuttal.md rebuttal.compressed.md --mode aggressive --contribution report.jsonThis typically achieves higher savings, but always review verification results before submission.
python main.py docs.md docs.min.md --mode safeSafe mode preserves all rendering and is suitable for versioning.
See sample.md for a comprehensive example with:
Tested with:
Note: Different renderers may handle edge cases differently. Always verify output visually.
暂无开放 Issues,或尚未同步最近议题。