from format_markdown import transform cases=[ ("chapter","CHAPTER IV\n\nThe story begins.","## CHAPTER IV"), ("named","Preface\n\nSome opening prose.","## Preface"), ("html_heading","

Methods

\n

A plain paragraph.

","## Methods"), ("list","• First item\n• Second item","- First item"), ("html_list","
  1. First
  2. Second
","1. First"), ("table","
TimeValue
13
","| Time | Value |"), ("pre","
if x < y:\n    print(x)
","if x < y:"), ] for name,text,expect in cases: out,edits=transform(text) assert expect in out,(name,out) print(name,edits) protected=[ "```python\nCHAPTER IV\n\n

literal

\n```\n", "$$\nx = 3 \\\\\ny=2\n$$\n", "

code literal

\n", "
Do not infer
", "An inline ` code ` example.", ] for text in protected: out,_=transform(text) assert out==text,(text,out) poetry="The rivers flow beneath the moon,\nAnd stars shall sing a silver tune.\n" assert transform(poetry,"Poems")[0]==poetry print('protected code/math/complex-table/poetry: OK') # Typical wrapped prose, containing real sentences, must preserve all tokens. import textwrap paragraph=("This is an ordinary prose paragraph with a sequence of clear explanatory statements. " "The following words continue the explanation without introducing any code or mathematical notation. ")*8 wrapped=textwrap.fill(paragraph,72) out,e=transform(wrapped,"An ordinary book") assert out.split()==wrapped.split() assert e.get('prose_hardwraps_joined',0)>0 print('prose whitespace-only join',e) # Regression: do not render instructional HTML or promote references to headings. for raw in ['Appendix B shows an equation of the form \\(x=1\\) can be rearranged:', 'Here is an HTML example:\n

Heading

\n

Example

', '| unordered list | |', '

Example

']: assert transform(raw)[0]==raw