feat: Option --code-language für Codeblöcke ohne erkannte Sprache
Weist Blöcken ohne erkannte Sprache ein vom Nutzer gewähltes Label zu. Aliase wie py werden normalisiert, unbekannte Werte ergeben Exit 1. Erkannte Labels haben Vorrang; im Bericht detected_by "option" (QA-Befund R1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8afa1cc6d4
commit
cc36372329
1 changed files with 39 additions and 2 deletions
|
|
@ -86,3 +86,18 @@ def test_prose_is_not_forced_into_code(convert):
|
|||
def test_unlabeled_code_is_reported(convert):
|
||||
run = convert(Book(docs=[Doc("c.xhtml", "<h1>U</h1><pre>foo bar</pre>")]))
|
||||
assert run.report["code_blocks"]["languages"] == {"(keine)": 1}
|
||||
|
||||
|
||||
def test_code_language_option_fills_only_unlabeled_blocks(convert):
|
||||
body = "<h1>C</h1><pre>x = compute()</pre><pre>#include <stdio.h>\nint main(void) { return 0; }</pre>"
|
||||
run = convert(Book(docs=[Doc("c.xhtml", body)]), "--code-language", "py")
|
||||
langs = [lang for _, lang, _ in fenced_blocks(run.chapter("001"))]
|
||||
assert langs == ["python", "c"]
|
||||
by = {item["language"]: item["detected_by"] for item in run.report["code_blocks"]["items"]}
|
||||
assert by == {"python": "option", "c": "content"}
|
||||
|
||||
|
||||
def test_code_language_option_rejects_unknown_values(convert):
|
||||
run = convert(Book(docs=[Doc("c.xhtml", "<h1>C</h1><pre>x</pre>")]), "--code-language", "quatsch")
|
||||
assert run.rc == 1
|
||||
assert "quatsch" in run.stderr
|
||||
|
|
|
|||
Loading…
Reference in a new issue