diff --git a/scripts/diff.py b/scripts/diff.py index 083483c..5e3bcc4 100644 --- a/scripts/diff.py +++ b/scripts/diff.py @@ -43,27 +43,30 @@ def main() -> None: added_rules, removed_rules, updated_rules = get_diff_rules(OLD_JSON, NEW_JSON) with open(DIFF_MARKDOWN, "w", encoding="utf-8") as f: - f.write("## 新增规则\n") - f.write("|规则|示例|\n") - f.write("|----|----|\n") - for rule in added_rules: - f.write(rule.to_markdown_tr(verbose=False)) + if added_rules: + f.write("## 新增规则\n") + f.write("|规则|示例|\n") + f.write("|----|----|\n") + for rule in added_rules: + f.write(rule.to_markdown_tr(verbose=False) + "\n") f.write("\n") - f.write("## 更新规则\n") - f.write("|规则|示例|\n") - f.write("|----|----|\n") - for rule in updated_rules: - f.write(rule.to_markdown_tr(verbose=False)) + if updated_rules: + f.write("## 更新规则\n") + f.write("|规则|示例|\n") + f.write("|----|----|\n") + for rule in updated_rules: + f.write(rule.to_markdown_tr(verbose=False) + "\n") f.write("\n") - f.write("## 移除规则\n") - f.write("|规则|示例|\n") - f.write("|----|----|\n") - for rule in removed_rules: - f.write(rule.to_markdown_tr(verbose=False)) + if removed_rules: + f.write("## 移除规则\n") + f.write("|规则|示例|\n") + f.write("|----|----|\n") + for rule in removed_rules: + f.write(rule.to_markdown_tr(verbose=False) + "\n") except Exception as e: print(e) exit(1) diff --git a/scripts/utils.py b/scripts/utils.py index 4d60d5f..4119308 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -115,7 +115,7 @@ def to_markdown_tr(self, verbose: bool = False) -> str: Returns: str: Markdown 表格行 """ - filter_markdown = f"`{self.filter}`" + filter_markdown = f"`{self.filter.replace("|", "\|")}`" if self.examples: examples_markdown = "、".join([f"`{example}`" for example in self.examples])