Overview
Convert legal texts (legal provisions or legal cases) into standardized Markdown format, remove promotional and redundant information, automatically identify the text type, and apply the corresponding formatting rules.
Core Responsibilities: Only responsible for formatting and content cleanup, and does not include content scraping capabilities.
Collaboration with Other Skills
Typical Workflow
Scenario: The user requests formatting of legal text on a webpage
用户请求 → AI 判断来源 → 抓取类 skill 获取内容 → legal-text-format 格式化
Example workflow:
- The user provides a WeChat public account link → the AI uses
wechat-article-fetchto scrape → the AI callslegal-text-formatto format - The user provides an ordinary webpage link → the AI uses other tools to scrape → the AI calls
legal-text-formatto format - The user directly pastes text → the AI directly calls
legal-text-formatto format
Skill Responsibility Boundaries:
wechat-article-fetch/ Other scraping tools: Responsible for obtaining raw text content from various sourceslegal-text-format: Responsible for formatting and cleaning up the acquired text
Core Principles
Content Integrity Guarantee: Apart from formatting adjustments and removal of promotional content, the substantive content of all legal cases and legal provisions must be fully retained, with no omissions whatsoever!
Workflow
Step 1: Analyze the Text Type
Use an LLM to analyze the input text:
- Determine whether it is a legal provision or a legal case
- Identify structural features of the text (chapters, articles, case numbers, etc.)
- Determine the appropriate formatting strategy
- Extract the subject for file naming
Analysis Prompt Reference:
分析以下文本,判断其类型:
- 如果是法律条文:识别章、节、条的结构
- 如果是法律案例:识别案例标题、案号、案情、裁判结果、典型意义等
- 提取主题用于文件命名
Step 2: Save the Original Content
Save the input original content as a local Markdown file:
- File location:
archive/{YYYYMMDD_HHMMSS}_{主题}/ - File naming:
{YYYYMMDD}_{主题}_raw.md - Purpose: Provide a basis for traceability and facilitate content comparison and verification
Example Archive Directory Structure:
archive/20250122_153400_个人信息保护检察公益诉讼典型案例/
├── 20250122_个人信息保护检察公益诉讼典型案例_raw.md # 原始内容
├── 20250122_个人信息保护检察公益诉讼典型案例_formatted.md # 格式化后的内容(步骤4生成)
└── meta.json # 元信息(可选)
Step 3: Format the Text
Important: Process the complete text at once, without segmenting it.
Formatting Prompt(Refer to the detailed examples in examples.md ):
请将以下法律文本格式化为规范的 Markdown 格式。
# 法律条文格式化规则
- 章前面添加二级 markdown 格式(##)
- 不同条文之间添加空行
- 每一条条文内部换行时不应有多余空行
- "第X条"进行加粗(**第X条**)
- 如果一段文字的最后没有句号或分号,则删除后方的回车
- 保持所有条文内容完整,不得遗漏任何条款
# 法律案例格式化规则
- 把英文标点符号替换成中文标点符号(包括括号、逗号、句号、冒号、分号等)
- 案例序号或名称前添加二级 markdown 格式(##),序号后要紧跟案例名称
- 每个案例的章节前添加三级 markdown 格式(###)
- 每个案例的章节内部不应有大于1个的空行(连续换行数不超过2个)
- 清理多余的连续空行,保持段落间适当的分隔
- 把数字格式调整为半角
- 内容范围限定:
- 仅保留从第一个案例到最后一个案例的内容
- 删除前面的文章介绍、作者信息、引言、目录等
- 删除底部的宣传推广内容、二维码、公众号介绍、相关文章推荐等
- 保留标准:只保留案例标题、案号、基本案情、裁判结果、典型意义等法律案例本身的内容
- 保持所有案例实质内容完整,包括案情、裁判、意义等所有部分
# 参考示例
详见 references/examples.md 文件,其中包含4个完整的格式化示例。
Summary of Legal Provision Formatting Rules
- Add Level 2 Markdown formatting before chapters (
##) - Add blank lines between different provisions
- There should be no extra blank lines when wrapping lines within each provision
- Bold "Article X" (
**第X条**) - If a paragraph does not end with a period or semicolon, delete the carriage return after it
- Keep the content of all provisions complete, without omitting any clauses
Summary of Legal Case Formatting Rules
- Replace English punctuation marks with Chinese punctuation marks
- Add Level 2 Markdown formatting before the case number or name (
##), and the case name should immediately follow the number - Add Level 3 Markdown formatting before the section of each case (
###) - Within the section of each case, there should not be more than 1 blank line (no more than 2 consecutive line breaks)
- Clean up redundant consecutive blank lines and maintain appropriate separation between paragraphs
- Adjust number formats to half-width
- Content scope limitation:
- Keep onlythe content from the first case to the last case
- Delete the precedingarticle introduction, author information, introduction, table of contents, etc.
- Delete the bottompromotional content, QR codes, official account introduction, related article recommendations, etc.
- Retention criteria: Keep only the content of the legal case itself, such as the case title, case number, basic facts, judgment result, and typical significance
- Keep the substantive content of all cases complete, including all parts such as the facts, judgment, and significance
Step 4: Save
Save the formatted document:
- File location:
archive/{YYYYMMDD_HHMMSS}_{主题}/ - File naming:
{YYYYMMDD}_{主题}_formatted.md - and
raw.mdsaved in the same archive directory
Conservative boundaries of deterministic scripts
Use python3 scripts/format_legal_cases.py 输入.md 输出.md 法院名称 原文URL 文档标题 to process the case text. The script only needs the Python 3 standard library; it does not connect to the internet, does not call models, and is not responsible for legal provision structure recognition or semantic verification.
- First save the original content according to the workflow; after completion, compare the result with the original text.
- Do not trim the main text by date, first case word, blank paragraph position, or fixed character count. The function caller can specify a prefix trimming point only when
keep_from_markeris explicitly passed; the CLI retains the prefix by default, and ambiguous introduction and promotional text are left for manual confirmation. - Only clean up identified complete end-of-document source/end markers and the known promotional lines immediately following them; source, contact, and similar words in the main text, quotation lines, and evidence images are retained. If it cannot be determined whether something belongs to the footer, retain it; the script output must not be treated as proof that semantic cleanup has been completed.
- Retain case numbers, decimals, thousands separators, URLs, email addresses, Markdown links, and inline code syntax; fenced code/evidence blocks are retained as in the original text; punctuation in ordinary main text is still adjusted according to Chinese typesetting rules, and numbers in ordinary main text are still converted to half-width according to existing rules.
- It is not guaranteed to parse arbitrarily nested Markdown or identify all promotional formats. Manually review ambiguous boundaries and evidence quotations, and do not add, summarize, or omit case content.
Regression check:python3 -m unittest discover -s scripts/tests -v. Tests use only fictional cases and cannot replace integrity verification of real documents.
Reference documents
Formatting examples
For detailed formatting examples and comparisons, see examples.md, including:
- 4 complete legal case formatting examples
- Each example includes a comparison of the original text and the formatted version
- Summary of formatting key points (punctuation handling, heading levels, blank line handling, content scope, etc.)
Accuracy requirements
- Do not change the meaning of the original text: Formatting adjustments must not change the original meaning of the legal text
- Retain key information: Key information such as case numbers, court names, and parties must be retained
- Keep numbering: Case numbers and article numbers must not be modified
Output document structure
Archive directory organization
All formatting results are archived and stored by timestamp:
archive/
├── {YYYYMMDD_HHMMSS}_{文档主题}/
│ ├── {YYYYMMDD}_{主题}_raw.md # 原始抓取内容
│ ├── {YYYYMMDD}_{主题}_formatted.md # 格式化后的内容
│ └── meta.json # 元信息(可选)
Naming rules:
- Directory name:
{YYYYMMDD_HHMMSS}_{主题}(Example:20250122_153400_个人信息保护典型案例) - File name:
- Original file:
{YYYYMMDD}_{主题}_raw.md(Example:20250122_个人信息保护典型案例_raw.md) - Formatted file:
{YYYYMMDD}_{主题}_formatted.md(Example:20250122_个人信息保护典型案例_formatted.md)
- Original file:
- Topic limit: The core topic extracted from the text, limited to 30 characters
- Date format:
YYYYMMDD(Example: 20250122)
formatted.md content structure
# {文档标题}
## 元信息
- **原文链接**:{从原始文件的 `> 原文链接:` 行提取,无则省略此行}
- **处理时间**:{时间戳}
- **文本类型**:{法律条文/法律案例}
---
{格式化后的正文内容}
Original link extraction rules: When the input comes from wechat-article-fetch , the header of the original Markdown file contains > 原文链接: https://mp.weixin.qq.com/s/xxxxx, and this URL must be extracted and written into the "Original Link" field of the metadata.
Quality standards
- Unified punctuation: All punctuation uses Chinese punctuation
- Unified number format: Numbers use half-width characters
- Clear hierarchical structure: Correct use of second-level and third-level headings
- Blank line standards: Appropriate blank lines between paragraphs, neither too many nor missing
- Content completeness: Retain all legally relevant content and remove irrelevant promotional information
Applicable scenarios
- Organizing compilations of legal provisions
- Standardizing collections of legal cases
- Preparing legal study materials
- Building a legal text knowledge base
- Cleaning legal texts scraped from web pages
Input requirements
This skill accepts the following types of input:
- Scraped text content: Text obtained by other skills (such as wechat-article-fetch)
- Text pasted by the user: Text content provided directly by the user
- Local files: Saved Markdown/text files
Not accepted: Web page links (links should be handled by dedicated scraping skills)
Automatic invocation from wechat-article-fetch
When wechat-article-fetch detects legal content and this skill is installed, it will automatically chain-call this skill. In this case, the input is the path to a saved Markdown file. The processing flow remains unchanged:
- Read the content of the Markdown file at the specified path as input
- Execute steps 1-4 (analyze type, save original, format, verify)
- Save the result to this skill's
archive/directory - The file path is recorded in the "Source" field of the formatted.md metadata