SuperAPI AI Directory

law-to-markdown

Writing & research

View repository

Updated 10-16 08:08

About this skill

Law To Markdown

Processing Rules

  1. If the input is .txt: directly save as .md。
  2. If the input is .pdf / .docx:
    • First check whether mineru-ocr skill。
    • Not installed: prompt to install mineru-ocrfirst. Installation address: https://github.com/cat-xierluo/legal-skills/tree/main/skills/mineru-ocr
    • Already installed: preferentially call mineru-ocr for processing.
    • Call failed: first prompt to check the mineru-ocr configuration/Token.
    • Use the local fallback (python-docx / pdfplumber)。
  3. After the first stage is completed, perform the second-stage format adjustment by default (format only, do not change the original text characters):
    • The large model calling this skill first determines "legal/non-legal" and passes the result to the script.
    • If the caller does not pass the result, the script uses hard rules for automatic identification (--law-decision auto)。
    • Legal title #
    • Part/Sub-part ##
    • Chapter ###
    • Section ####
    • Article #####(only "Article X" is a title;第X条【条标】a whole line that is a title is not split)
    • Paragraphs/items/sub-items have no titles
    • Items and sub-items are placed on new lines according to markers
    • Clean up extra spaces: remove trailing spaces, remove leading ASCII spaces, remove full-width indentation at the start of body lines, and normalize spaces after titles
  4. If it is identified as clearly non-legal text (such as GB/standard-type documents), the second stage explicitly refuses:Stage2: rejected (non-law-document)。
  5. If the second stage does not recognize a legal structure or the fidelity check fails, automatically no-op without changing the text.
  6. Perform the third-stage check by default (two sub-stages, hard thresholds):
    • Stage3-A: verify stage2 relative to stage1 for textual content accuracy (the character stream must be identical after removing title symbols and whitespace)
    • Stage3-B: verify structural effects (structural hierarchy, article title rules, non-legal policy, space conventions, item/sub-item line breaks)
    • Any failure triggers an automatic rerun, up to 2 times; if it still fails, exit with an error by default

Second-stage recognition parameter

  • --law-decision law: the caller has determined it is legal text, directly optimize according to the legal structure.
  • --law-decision non-law: the caller has determined it is non-legal text, and stage two directly refuses.
  • --law-decision auto: the default mode when no determination is passed, using the hard rules in the script.

Third-stage parameter

  • --skip-stage3-check: skip the third-stage check (not skipped by default).
  • --stage3-max-retries: the number of automatic reruns after failure, default 2。
  • --stage3-strict / --no-stage3-strict:
    • Default strict mode (exit with an error on failure)
    • Non-strict mode only outputs a report and does not block the process
  • --artifact-level minimal|standard|debug:
    • minimal(default): delivery-oriented, minimal output
    • standard: retain process files (stage1/stage2/stage3-check) for troubleshooting
    • debug: retain all process artifacts (including debug information)

Output Rules

  • By default, output to the markdown/ subdirectory in the same directory as the input file, and create an independent directory based on the input file name:
    • markdown/<文件名>/
  • Default (--artifact-level minimal) output:
    • <原文件名>+审核报告.md(detailed process and conclusions)
    • <原文件名>+最终成果.md(generated only for legal text and when review passes)
  • Non-legal documents (such as GB/standards):
    • The conclusion is "reject processing"
    • Only output <原文件名>+审核报告.md
    • Do not output <原文件名>+最终成果.md
  • When the review fails, process files are automatically retained for troubleshooting:
    • <文件名>.stage1.md
    • <文件名>.stage2.md
    • <文件名>.stage3-check.md
  • If more artifacts are needed, you can switch:
    • --artifact-level standard: retain stage1/stage2/stage3-check
    • --artifact-level debug: retain all debug artifacts
  • You can specify via command parameters --out or --out-dir。

Common commands

python3 law-to-markdown/scripts/law_to_markdown.py "input.txt"
python3 law-to-markdown/scripts/law_to_markdown.py "input.docx"
python3 law-to-markdown/scripts/law_to_markdown.py "input.pdf"

When the user explicitly agrees to roll back:

python3 law-to-markdown/scripts/law_to_markdown.py "input.docx" --allow-fallback
python3 law-to-markdown/scripts/law_to_markdown.py "input.pdf" --allow-fallback

License

SPDX-License-Identifier: Apache-2.0

Copyright (c) 2026 JiCheng

Licensed under the Apache License 2.0; the original license text can be found in the repository root directory LICENSE。