SuperAPI AI Directory

law-to-markdown

Office & productivity

View repository

Updated 10-15 19:56

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
    • Installed: prioritize calling mineru-ocr for processing.
    • Call failed: first prompt to check the mineru-ocr configuration/Token.
    • Only when the user explicitly agrees, use the local fallback (python-docx / pdfplumber)。
  3. After the first stage is completed, by default execute the second-stage format adjustment (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 to automatically identify (--law-decision auto)。
    • Legal name #
    • Part/Sub-part ##
    • Chapter ###
    • Section ####
    • Article #####(only "Article X" is a heading;第X条【条标】if the entire line is a heading, do not split)
    • Paragraph/Item/Sub-item have no headings
    • Items and sub-items are line-broken according to markers
    • Clean up excess spaces: remove trailing spaces, remove leading ASCII spaces, remove full-width indentation at the beginning of body lines, normalize spaces after headings
  4. If it is identified as clearly non-legal text (such as GB/standard documents), the second stage explicitly refuses:Stage2: rejected (non-law-document)。
  5. If the second stage does not identify a legal structure or fidelity verification fails, automatically no-op without changing the text.
  6. By default, execute the third-stage check (two sub-stages, hard thresholds):
    • Stage3-A: Verify the textual content accuracy of stage2 relative to stage1 (the character stream must be identical after removing heading symbols and whitespace)
    • Stage3-B: Verify the structural effect (structural hierarchy, article heading rules, non-legal strategy, whitespace conventions, item/sub-item line breaks)
    • Any failure triggers automatic re-run, up to 2 times; if still failing, by default report an error and exit

Second-stage recognition parameters

  • --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, stage two directly refuses.
  • --law-decision auto: the default mode when no determination is passed, using hard rules within the script.

Third-stage parameters

  • --skip-stage3-check: skip the third-stage check (not skipped by default).
  • --stage3-max-retries: number of automatic re-runs after failure, default 2。
  • --stage3-strict / --no-stage3-strict:
    • Default strict mode (report an error and exit 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 a separate directory based on the input file name:
    • markdown/<文件名>/
  • Default (--artifact-level minimal) output:
    • <原文件名>+审核报告.md(detailed process and conclusion)
    • <原文件名>+最终成果.md(Generated only for legal texts that pass review)
  • Non-legal documents (such as GB/standard types):
    • The conclusion is "reject processing"
    • Only output <原文件名>+审核报告.md
    • Do not output <原文件名>+最终成果.md
  • When 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 fall 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