53 lines
3.0 KiB
Python
53 lines
3.0 KiB
Python
"""Nested block geometry and editable style inheritance in all Word engines."""
|
|
import pytest
|
|
from mdhelper.docx_exporter import export_markdown_to_docx
|
|
from mdhelper.docx_style import W, NS
|
|
from test_style_regressions import parts
|
|
from docx_assertions import effective_document
|
|
|
|
ENGINES = ('builtin','python-docx','pandoc')
|
|
CONTINUED = '1. FirstText\n\n ContinuedText\n\n ### ContinuedHeading\n\n ```text\n CodeFirst\n CodeSecond\n ```\n\n2. LastText'
|
|
CODE = '1. ```text\n CodeFirst\n CodeSecond\n ```\n\n2. LastText'
|
|
QUOTE = '> ### QuotedHeading\n>\n> ```text\n> QuotedCode\n> ```\n>\n> > ### InnerHeading'
|
|
|
|
|
|
@pytest.mark.parametrize('engine', ENGINES)
|
|
def test_continuations_cancel_hanging_and_preserve_parent_styles(tmp_path, engine):
|
|
doc, styles = parts(export_markdown_to_docx(CONTINUED,tmp_path/'continued.docx',engine=engine))
|
|
effective = effective_document(doc,styles)
|
|
for p in effective.iter(W+'p'):
|
|
text = ''.join(p.itertext())
|
|
if text.startswith(('Continued','Code')):
|
|
ind=p.find('w:pPr/w:ind',NS)
|
|
assert int(ind.get(W+'left')) == 480
|
|
assert ind.get(W+'hanging','0') == ind.get(W+'hangingChars','0') == '0'
|
|
assert p.find('w:pPr/w:numPr',NS) is None
|
|
heading = next(p for p in doc.iter(W+'p') if ''.join(p.itertext()) == 'ContinuedHeading')
|
|
style_id=heading.find('w:pPr/w:pStyle',NS).get(W+'val')
|
|
assert 'ListOrdered' in style_id and 'Continuation' in style_id
|
|
styles.find("w:style[@w:styleId='MDHelperH3']/w:rPr/w:color",NS).set(W+'val','ff0000')
|
|
heading=next(p for p in effective_document(doc,styles).iter(W+'p') if ''.join(p.itertext()) == 'ContinuedHeading')
|
|
assert heading.find('w:r/w:rPr/w:color',NS).get(W+'val') == 'ff0000'
|
|
assert not any(a.startswith('{urn:mdhelper:source}') for el in doc.iter() for a in el.attrib)
|
|
|
|
|
|
@pytest.mark.parametrize('engine', ENGINES)
|
|
def test_multiline_code_remains_one_numbered_paragraph(tmp_path, engine):
|
|
doc, _ = parts(export_markdown_to_docx(CODE,tmp_path/'code.docx',engine=engine))
|
|
code = next(p for p in doc.iter(W+'p') if 'CodeFirst' in ''.join(p.itertext()))
|
|
assert 'CodeSecond' in ''.join(code.itertext()) and code.find('.//w:br',NS) is not None
|
|
assert code.find('w:pPr/w:numPr',NS) is not None
|
|
|
|
|
|
@pytest.mark.parametrize('engine', ENGINES)
|
|
def test_quote_blocks_keep_container_depth_and_editable_heading_base(tmp_path, engine):
|
|
doc, styles = parts(export_markdown_to_docx(QUOTE,tmp_path/'quote.docx',engine=engine))
|
|
rendered=effective_document(doc,styles)
|
|
for p in rendered.iter(W+'p'):
|
|
text=''.join(p.itertext())
|
|
if text in ('QuotedHeading','QuotedCode','InnerHeading'):
|
|
assert int(p.find('w:pPr/w:ind',NS).get(W+'left')) == (600 if text=='InnerHeading' else 300)
|
|
styles.find("w:style[@w:styleId='MDHelperH3']/w:rPr/w:sz",NS).set(W+'val','40')
|
|
for p in effective_document(doc,styles).iter(W+'p'):
|
|
if 'Heading' in ''.join(p.itertext()): assert p.find('w:r/w:rPr/w:sz',NS).get(W+'val')=='40'
|