diff --git a/docs/architecture.md b/docs/architecture.md index d33ebfe..658b548 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -51,6 +51,8 @@ CSS 同步按三个步骤处理:`_collect_cascade` 决定生效的声明,`_CoreRuleReader` 转换可表达的字体和段落属性,`analyze_css` 汇总结果。无法映射的 CSS 继续保留原文,不改写级联规则或 Word 的支持范围。 +选择器先区分独立元素与旧版完整基准组;级联项同时记录声明归属,避免将基准值复制成子样式的显式覆盖。Word 组合字符样式也记录最终属性归属,初始值相等不会抹去内层覆盖。用于命名列表样式的编号定义复制后移除缩进,并分配独立 `nsid`,避免 Word 合并新旧定义而恢复旧缩进。 + 明确无效的声明在级联选择前忽略;简写中任一无效组件使整条简写失效,有效但不支持的表达式仍遮盖前面的值。普通 `p` 同时映射引用段落及 `rules._list_paragraph` 上下文;各引擎通过临时段落标记区分宽松列表和紧凑列表。表格文字使用独立内容容器承载段间距,表格边框和单元格内边距保持原位置。 `render_css` 使用与图形写入相同的字体变量表达继承,并生成列表层级缩进及独立文字修饰的辅助规则。显式取消列表基准时会恢复该语义类型的默认格式,旧配置缺少元数据时仍保留兼容基准。 diff --git a/docs/user_manual.md b/docs/user_manual.md index 7f005ed..953b6fb 100644 --- a/docs/user_manual.md +++ b/docs/user_manual.md @@ -177,6 +177,8 @@ Markdown 支持: Word 每段文字只能引用一个字符样式,因此加粗链接等组合会生成 `MDHelper 超链接+加粗` 等组合样式。不同嵌套顺序分别保存,按 Markdown 从外到内应用格式;含链接的组合以超链接为基准,内层明确设置可覆盖外层。组合不会同时继承多个字符样式,其他组合属性可通过对应组合样式统一修改。嵌套列表使用基于对应列表样式的层级样式,层级缩进可单独修改。 +内层明确设置与基准的初始值相同时,也会保留该覆盖关系;之后修改基准不会改变内层的明确设置。列表的缩进由命名段落样式控制,编号只负责标记和序号,因此在 Word 样式面板调整首行、悬挂和左右缩进可以继续生效。 + Word 的字符样式会把加粗、斜体和删除线作为与段落格式叠加的开关。导出采用强调保护:明确字符样式中的这些字形设置会固定在对应文字上,避免修改正文或标题样式时反向关闭强调。字体、字号、颜色、下划线和段落仍由命名样式统一控制;受保护的加粗、斜体和删除线不能仅通过 Word 字符样式关闭,可在 MDHelper 调整后重新导出,或在 Word 中清除对应文字的直接字形格式再使用其原生样式规则。 纸张宽度是全局阅读设置,内置样式不再写死正文宽度,会跟随纸张宽度变化。 @@ -187,6 +189,8 @@ Word 的字符样式会把加粗、斜体和删除线作为与段落格式叠加 核心同步覆盖对象的常规选择器,例如 `p`、`.reader p`、`h1`、`.reader h1`、`strong`、`em`、`s`、`a`,以及程序生成的 `data-mdh-style` 语义选择器。可识别的属性包括字体、字号、颜色、字符间距、`text-decoration-line`、`background-color`、对齐、行距、缩进、四向间距、换行分页,以及 `border-color` / `border-width`、表格 `padding` 和 `list-style-type`。支持常见字体简写、间距简写和 `!important`;重置当前对象只清除其核心设置,保留扩展效果。 +独立的 `th`、`td`、`pre` 设置分别对应表头、单元格和代码块,不会串用到其他对象。旧版生成的 `table, th, td` 和 `pre, code` 合并规则仍作为兼容基准,未单独设置的子样式继续继承。 + 普通 `p` 选择器也作用于引用和宽松列表中的段落,Word 会保留这些上下文格式;紧凑列表没有独立段落元素,不受该选择器影响。表头和单元格的段前、段后及左右间距作用于内部文字区域,表格内边距仍独立设置。明显无效的 CSS 值(例如 `font-size:nope`)会被忽略并提示,前面的有效声明继续同步;有效但不能转换为 Word 的扩展表达式仍保留为 CSS。 颜色选择“随所在文字颜色”(CSS `currentColor` / `inherit`)会继承段落或外层文字的颜色,不等同于“自动(随主题)”。如果它同时需要取消某个字符基准中的固定颜色,Word 无法只取消一个继承属性,因此导出会将该基准的其他已解析格式保留在当前命名字符样式内;导出后请修改此命名样式,其他普通样式的基准继承保持不变。 diff --git a/mdhelper/docx_semantic.py b/mdhelper/docx_semantic.py index 9068c72..4d9ca0e 100644 --- a/mdhelper/docx_semantic.py +++ b/mdhelper/docx_semantic.py @@ -78,6 +78,7 @@ class WordStyles: self.created = {} self.characters = {} self.number_overrides = {} + self.style_numbering = {} for key in CATALOG: if CATALOG[key].kind == 'character': self.character(key) elif CATALOG[key].kind == 'paragraph': self.paragraph(key) @@ -167,8 +168,12 @@ class WordStyles: keys = ordered_styles(keys) if not keys: return '' merged = {} + owners = {} for key in keys: - merged.update({field: value for field, value in self.character_rule(key).items() if not (field == 'font_color' and value == 'inherit')}) + for field, value in self.character_rule(key).items(): + if field == 'font_color' and value == 'inherit': continue + merged[field] = value + owners[field] = key identifier = self.character(keys[0]) if len(keys) == 1 else 'MDHelperMix' + ''.join(style_id(key)[8:] for key in keys) if identifier not in self.created: base = 'link' if 'link' in keys else keys[0] @@ -176,7 +181,7 @@ class WordStyles: props, old = child(style, 'rPr'), ET.Element(W + 'rPr') _run_properties(props, merged) _run_properties(old, self.character_rule(base)) - _delta(props, old) + _delta(props, old, {field: value for field, value in merged.items() if owners[field] != base}) return identifier def syntax_style(self, run_id, target): @@ -207,6 +212,34 @@ class WordStyles: abstract = self.numbering.find(f"w:abstractNum[@w:abstractNumId='{abstract_id}']", NS) return level, abstract.find(f"w:lvl[@w:ilvl='{level}']", NS) if abstract is not None else None + def inherit_list_indents(self, numpr): + """Numbering owns the marker; named paragraph styles own indentation.""" + original = reference(numpr, 'numId') + if not original: return + if original not in self.style_numbering: + _, level = self.list_level(numpr) + if level is None: return + num = deepcopy(self.numbering.find(f"w:num[@w:numId='{original}']", NS)) + abstract = deepcopy(level.getparent()) + num_id = 1 + max(int(n.get(W + 'numId')) for n in self.numbering.findall(W + 'num')) + abstract_id = 1 + max(int(n.get(W + 'abstractNumId')) for n in self.numbering.findall(W + 'abstractNum')) + num.set(W + 'numId', str(num_id)); val(num, 'abstractNumId', abstract_id) + abstract.set(W + 'abstractNumId', str(abstract_id)) + self.identify_numbering(abstract, abstract_id) + for root in (num, abstract): + for props in root.iter(W + 'pPr'): remove_fields(props, ('ind', 'tabs')) + self.numbering.extend((abstract, num)) + self.style_numbering[original] = str(num_id) + val(numpr, 'numId', self.style_numbering[original]) + + def identify_numbering(self, abstract, identifier): + # Word coalesces definitions with the same nsid, even when their XML + # ids differ. A modified clone must have its own list identity. + used = {reference(node, 'nsid') for node in self.numbering.findall(W + 'abstractNum')} + candidate = (0x4d440000 + identifier) & 0xffffffff + while f'{candidate:08X}' in used: candidate = (candidate + 1) & 0xffffffff + val(abstract, 'nsid', f'{candidate:08X}') + def classify(self, paragraph, original_id): names = self.names(original_id) heading = re.search(r'heading\s*([1-6])', names) @@ -288,6 +321,7 @@ class WordStyles: abstract_id = 1 + max(int(n.get(W + 'abstractNumId')) for n in self.numbering.findall(W + 'abstractNum')) num.set(W + 'numId', str(num_id)); val(num, 'abstractNumId', abstract_id) abstract.set(W + 'abstractNumId', str(abstract_id)) + self.identify_numbering(abstract, abstract_id) self.numbering.extend((abstract, num)) self.number_overrides[key] = str(num_id) val(numpr, 'numId', self.number_overrides[key]) @@ -359,6 +393,7 @@ class WordStyles: identifier = self.paragraph(target) if target.startswith('list_'): numpr = ppr.find(W + 'numPr') + self.inherit_list_indents(numpr) level, _ = self.list_level(numpr) if level: identifier = self.nested_list(target, level) marker = self.effective[target].get('list_marker') diff --git a/mdhelper/docx_style.py b/mdhelper/docx_style.py index e0bb9c8..cdff149 100644 --- a/mdhelper/docx_style.py +++ b/mdhelper/docx_style.py @@ -34,6 +34,7 @@ def _order_properties(root): # numbering, bookmarks, tracked changes) while inserting ours in that order. orders = { 'numbering': 'numPicBullet abstractNum num numIdMacAtCleanup', + 'abstractNum': 'nsid multiLevelType tmpl name styleLink numStyleLink lvl', 'style': 'name aliases basedOn next link autoRedefine hidden uiPriority semiHidden unhideWhenUsed qFormat locked personal personalCompose personalReply rsid pPr rPr tblPr trPr tcPr tblStylePr', 'tblPr': 'tblStyle tblpPr tblOverlap bidiVisual tblStyleRowBandSize tblStyleColBandSize tblW jc tblCellSpacing tblInd tblBorders shd tblLayout tblCellMar tblLook tblCaption tblDescription tblPrChange', 'tcPr': 'cnfStyle tcW gridSpan hMerge vMerge tcBorders shd noWrap tcMar textDirection tcFitText vAlign hideMark cellIns cellDel cellMerge tcPrChange', diff --git a/mdhelper/resources/reader.css b/mdhelper/resources/reader.css index f03fcd6..93ee9c0 100644 --- a/mdhelper/resources/reader.css +++ b/mdhelper/resources/reader.css @@ -360,7 +360,7 @@ td code { color: #cccccc; } -pre.highlight { +pre:where(.highlight) { margin: 0; padding: 1em; overflow-x: auto; @@ -368,7 +368,7 @@ pre.highlight { color: #000000; } -:where(html[data-theme="dark"]) pre.highlight { +:where(html[data-theme="dark"]) pre:where(.highlight) { background: #1e1e1e; color: #d4d4d4; } diff --git a/mdhelper/style_sync.py b/mdhelper/style_sync.py index 2fa6e6d..ca1444f 100644 --- a/mdhelper/style_sync.py +++ b/mdhelper/style_sync.py @@ -55,7 +55,8 @@ def _normalize_selector_text(value): ALIASES = {"p": "paragraph", **{f"h{i}": f"h{i}" for i in range(1, 7)}, "li": "list", "blockquote": "blockquote", "blockquote p": "blockquote", ".admonition p": "blockquote", - "pre": "code", "code": "code", "table": "table", "th": "table", "td": "table"} + "pre": "code_block", "code": "code", "table": "table", "th": "table_head", "td": "table_cell", + "pre code": "code_block", "pre > code": "code_block"} ALIASES.update({".reader " + key: target for key, target in list(ALIASES.items())}) ALIASES.update({selector: key for key, selector in SELECTORS.items() if ',' not in selector}) ALIASES.update({'strong': 'strong', 'em': 'emphasis', 's': 'strike', 'del': 'strike', '.reader del': 'strike', 'a': 'link'}) @@ -92,6 +93,32 @@ def _selector(tokens): return _normalize_selector_text(_text([t for t in tokens if t.type != "comment"])) +def _rule_aliases(parts): + """Keep old generated baseline groups, but never merge independent objects.""" + aliases = {_selector(part): ALIASES.get(_selector(part)) for part in parts} + for prefix in ('', '.reader '): + for base, names in (('code', ('pre', 'code')), ('table', ('table', 'th', 'td'))): + group = {prefix + name for name in names} + if group <= aliases.keys(): + for selector in group: aliases[selector] = base + return aliases + + +def _owned_fields(entries, target): + """A winning baseline declaration must remain inherited by its child.""" + fields = set() + variables = {value: (key,) for key, value in FONT_VARIABLES.items()} + variables.update({'--mdhelper-underline': ('underline',), '--mdhelper-strike': ('strike',)}) + for prop, entry in entries.items(): + if entry[2] != target: continue + if prop == 'font-family' and re.sub(r'\s+', '', entry[1]) == re.sub(r'\s+', '', FONT_EXPRESSION): continue + if prop == 'text-decoration-line' and entry[1] == DECORATION_EXPRESSION: continue + if prop in variables: fields.update(variables[prop]); continue + for group, properties in PROPERTIES.items(): + if prop in properties: fields.update(GROUPS[group]) + return fields + + def _property(declaration): # Custom property names are case-sensitive in CSS. return declaration.name if declaration.name.startswith("--") else declaration.lower_name @@ -256,9 +283,10 @@ def _collect_cascade(source: str, result: Analysis): if node.type != "qualified-rule": continue targets = {} + aliases = _rule_aliases(_split(node.prelude)) for part in _split(node.prelude): selector = _selector(part) - target = ALIASES.get(selector) + target = aliases.get(selector) if target: direct = int(target != 'blockquote' or selector.endswith(' p')) targets[target] = max(targets.get(target, (0, (0, 0))), (direct, _specificity(selector))) @@ -296,10 +324,21 @@ def _collect_cascade(source: str, result: Analysis): result.notes.append("font 简写保留在 CSS 中;核心字体请使用 font-family/font-size 等属性") if prop not in CORE_PROPERTIES: continue - for target, (direct, specificity) in targets.items(): + bindings = [(target, target, direct, specificity) for target, (direct, specificity) in targets.items()] + # Old baseline groups directly select their child elements too. + for selector, origin in aliases.items(): + child = {'th': 'table_head', 'td': 'table_cell', 'code': 'code_block', 'pre': 'code_block'}.get(selector.removeprefix('.reader ')) + if child and origin in ('table', 'code'): + if origin == 'table' and prop in PROPERTIES['border_color'] | PROPERTIES['border_width'] | PROPERTIES['padding']: continue + bindings.append((child, origin, 1, _specificity(selector))) + character_props = set().union(*(PROPERTIES[g] for g in ('fonts','size','bold','italic','color','tracking','decoration'))) + for target, origin, direct, specificity in bindings: + if target == 'code_block' and prop in character_props: + # Plain pre typography is inherited by the inner code. + direct = 0 if all(s in ('pre', '.reader pre') for s, t in aliases.items() if t == origin) else 1 rank = (direct, declaration.important, specificity, order, position) if prop not in winners[target] or rank >= winners[target][prop][0]: - winners[target][prop] = (rank, _text(declaration.value)) + winners[target][prop] = (rank, _text(declaration.value), origin) return winners @@ -467,6 +506,8 @@ def analyze_css(source: str, font_size_px: float = 16) -> Analysis: winners = _collect_cascade(source, result) for target, entries in winners.items(): rule = _CoreRuleReader('paragraph' if target == LIST_PARAGRAPH else target, entries, result, font_size_px).parse() + owned = _owned_fields(entries, target) + rule = {field: value for field, value in rule.items() if field in owned} if rule: result.rules[target] = rule result.notes = list(dict.fromkeys(result.notes)) @@ -518,11 +559,12 @@ def patch_core(source: str, target: str, before: dict, after: dict, *, reset=Fal output.append(node) continue selectors = _split(node.prelude) - selected = [p for p in selectors if ALIASES.get(_selector(p)) == target] + aliases = _rule_aliases(selectors) + selected = [p for p in selectors if aliases.get(_selector(p)) == target] if not selected: output.append(node) continue - others = [p for p in selectors if ALIASES.get(_selector(p)) != target] + others = [p for p in selectors if aliases.get(_selector(p)) != target] declarations = css.parse_blocks_contents(node.content, skip_comments=False, skip_whitespace=False) kept = [] touched = False @@ -568,7 +610,8 @@ def patch_core(source: str, target: str, before: dict, after: dict, *, reset=Fal # This also avoids expanding a simple .reader p rule into a second block. if marked: canonical = next((node for node in reversed(output) if node.type == "qualified-rule" and - all(ALIASES.get(_selector(part)) == target and + all(_rule_aliases(_split(node.prelude)).get(_selector(part)) == target and + (target != 'code_block' or 'data-mdh-style' in _selector(part)) and (target != 'blockquote' or _selector(part).endswith(' p')) for part in _split(node.prelude))), None) if canonical is not None: diff --git a/tests/test_style_revision_053.py b/tests/test_style_revision_053.py new file mode 100644 index 0000000..3b54595 --- /dev/null +++ b/tests/test_style_revision_053.py @@ -0,0 +1,83 @@ +"""Regressions from the 0.5.2 cross-surface style audit.""" +import zipfile +from lxml import etree as ET +import pytest +from mdhelper.style_sync import normalize_payload, analyze_css +from mdhelper.style_dialog import DocumentStyleEditorDialog +from mdhelper.docx_exporter import export_markdown_to_docx +from mdhelper.docx_style import W, NS +from test_style_regressions import browser, parts +from docx_assertions import effective_document + +ENGINES = ('builtin', 'python-docx', 'pandoc') +SEPARATE_CSS = '.reader th {color:red;font-size:20pt;} .reader td {color:blue;font-size:12pt;} pre {color:green;} code {font-size:11pt;}' +TABLE_SOURCE = '| Header |\n|---|\n| Cell |' +MIX_SOURCE = '**[LinkInner](https://example.com)** and [**BoldInner**](https://example.com)' +MIX_RULES = {'strong': {'font_color': '#ff0000'}, 'link': {'font_color': '#ff0000'}} +LIST_RULES = {'list_bullet': {'indent_mode': 'first', 'indent_value': 18, 'indent_unit': 'pt'}} + + +def test_legacy_css_keeps_separate_element_scopes_and_gui_edits(qt_application, tmp_path): + payload = normalize_payload({'css': SEPARATE_CSS}) + assert normalize_payload(payload) == payload + assert payload['rules']['table_head']['font_color'] == '#ff0000' + assert payload['rules']['table_cell']['font_color'] == '#0000ff' + assert payload['rules']['code_block']['font_color'] == '#008000' + assert 'font_color' not in payload['rules']['code'] + actual = browser(qt_application, tmp_path, payload, TABLE_SOURCE + '\n\n`Inline`\n\n```text\nBlock\n```', + "[...document.querySelectorAll('th,td,code')].map(e=>[e.textContent.trim(),getComputedStyle(e).color,parseFloat(getComputedStyle(e).fontSize)])") + assert actual[:2] == [['Header','rgb(255, 0, 0)',pytest.approx(20*4/3,.001)],['Cell','rgb(0, 0, 255)',16]] + assert actual[2][1] != 'rgb(0, 128, 0)' and actual[3][1] == 'rgb(0, 128, 0)' + dialog = DocumentStyleEditorDialog(payload) + try: + dialog.select_target('table_head'); dialog.font_size_spin.setValue(22) + updated = dialog.style_payload() + assert updated['rules']['table_head']['font_size'] == 22 + assert updated['rules']['table_cell']['font_size'] == 12 + finally: dialog.close() + + +def test_old_baseline_groups_keep_inheritance_and_importance(): + original = {'table': {'font_color':'#ff0000','cell_padding':5}, 'code':{'font_size':15,'font_size_unit':'pt'}} + payload = normalize_payload({'rules':original}) + assert payload['rules'] == original + result = analyze_css('table,th,td {color:red !important;} th {color:blue;}') + assert result.rules['table']['font_color'] == '#ff0000' + assert 'font_color' not in result.rules.get('table_head', {}) + + +@pytest.mark.parametrize('engine', ENGINES) +def test_independent_css_scopes_reach_word(tmp_path, engine): + payload = normalize_payload({'css':SEPARATE_CSS}) + path = export_markdown_to_docx(TABLE_SOURCE+'\n\n`Inline`\n\n```text\nBlock\n```',tmp_path/'scopes.docx',engine=engine,style_rules=payload['rules']) + doc,styles = parts(path); rendered=effective_document(doc,styles) + colors={''.join(r.itertext()).strip():r.find('w:rPr/w:color',NS).get(W+'val') for r in rendered.iter(W+'r') if r.find('w:rPr/w:color',NS) is not None} + assert colors['Header']=='ff0000' and colors['Cell']=='0000ff' + assert colors['Block']=='008000' and colors['Inline']!='008000' + + +@pytest.mark.parametrize('engine', ENGINES) +def test_equal_initial_colors_keep_inner_explicit_override(tmp_path, engine): + path=export_markdown_to_docx(MIX_SOURCE,tmp_path/'mix.docx',engine=engine,style_rules=MIX_RULES) + doc,styles=parts(path) + styles.find("w:style[@w:styleId='MDHelperLink']/w:rPr/w:color",NS).set(W+'val','0000ff') + rendered=effective_document(doc,styles) + colors={''.join(r.itertext()):r.find('w:rPr/w:color',NS).get(W+'val') for r in rendered.iter(W+'r') if 'Inner' in ''.join(r.itertext())} + assert colors=={'LinkInner':'0000ff','BoldInner':'ff0000'} + + +@pytest.mark.parametrize('engine', ENGINES) +@pytest.mark.parametrize('source', ['- First\n- Second','- First\n\n- Second','- First\n - Second']) +def test_numbering_does_not_override_named_list_indents(tmp_path, engine, source): + path=export_markdown_to_docx(source,tmp_path/'list.docx',engine=engine,style_rules=LIST_RULES) + with zipfile.ZipFile(path) as package: + doc=ET.fromstring(package.read('word/document.xml')); numbering=ET.fromstring(package.read('word/numbering.xml')) + for numpr in doc.findall('.//w:pPr/w:numPr',NS): + num_id=numpr.find(W+'numId').get(W+'val') + num=numbering.find(f"w:num[@w:numId='{num_id}']",NS) + abstract_id=num.find(W+'abstractNumId').get(W+'val') + abstract=numbering.find(f"w:abstractNum[@w:abstractNumId='{abstract_id}']",NS) + assert abstract.find('.//w:pPr/w:ind',NS) is None + assert num.find('.//w:pPr/w:ind',NS) is None + identity=abstract.find(W+'nsid').get(W+'val') + assert sum(n.find(W+'nsid') is not None and n.find(W+'nsid').get(W+'val')==identity for n in numbering.findall(W+'abstractNum'))==1 diff --git a/tests/word_styles_smoke.ps1 b/tests/word_styles_smoke.ps1 index 2672508..6b464bd 100644 --- a/tests/word_styles_smoke.ps1 +++ b/tests/word_styles_smoke.ps1 @@ -13,10 +13,13 @@ from mdhelper.docx_exporter import export_markdown_to_docx from mdhelper.style_catalog import style_name from test_style_regressions import PARTIAL_RULES, UNIT_RULES, NESTED_SOURCE, NESTED_RULES from test_style_revision_052 import REPEATED_SOURCE, REPEATED_RULES, ABSOLUTE_PAYLOAD, SCOPED_SOURCE, SCOPED_CSS +from test_style_revision_053 import MIX_SOURCE, MIX_RULES, LIST_RULES from mdhelper.style_sync import normalize_payload folder = Path(tempfile.mkdtemp(prefix='MDHelper-Word-Styles-')) rules = {'h2': {'bold': False}, '_metadata': {'h2': {'based_on': 'h1'}}} for engine in ('builtin', 'python-docx', 'pandoc'): + export_markdown_to_docx(MIX_SOURCE, folder / (engine + '-equal-mix.docx'), engine=engine, style_rules=MIX_RULES) + export_markdown_to_docx('- FirstItem\n\n- SecondItem', folder / (engine + '-list-first.docx'), engine=engine, style_rules=LIST_RULES) export_markdown_to_docx(SOURCE + '\n\n## Child title', folder / (engine + '.docx'), engine=engine, style_rules=rules) export_markdown_to_docx('# Parent\n\n## Child', folder / (engine + '-partial.docx'), engine=engine, style_rules=PARTIAL_RULES) export_markdown_to_docx('# Parent\n\n## ChildUnits', folder / (engine + '-units.docx'), engine=engine, style_rules=UNIT_RULES) @@ -39,6 +42,23 @@ print(folder) $word.Visible = $false $word.DisplayAlerts = 0 foreach ($engine in @('builtin', 'python-docx', 'pandoc')) { + $doc = $word.Documents.Open((Join-Path $testDirectory "$engine-equal-mix.docx"), $false, $true) + try { + $doc.Styles.Item($names.link).Font.Color = 16711680 + foreach ($text in @('LinkInner','BoldInner')) { + $range = $doc.Content.Duplicate; [void]$range.Find.Execute($text) + $expected = if ($text -eq 'BoldInner') {255} else {16711680} + if ($range.Font.Color -ne $expected) { throw "$engine lost explicit inner color when values initially matched." } + } + } finally { $doc.Close(0); [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($doc) } + $doc = $word.Documents.Open((Join-Path $testDirectory "$engine-list-first.docx"), $false, $true) + try { + $range = $doc.Content.Duplicate; [void]$range.Find.Execute('FirstItem') + if ($range.ParagraphFormat.FirstLineIndent -ne 18) { throw "$engine numbering overrides first-line indentation." } + $style = $range.Style; $style.ParagraphFormat.FirstLineIndent = 24 + if ($range.ParagraphFormat.FirstLineIndent -ne 24) { throw "$engine numbering blocks Word style edits." } + } finally { $doc.Close(0); [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($doc) } + Write-Output "$engine passed: explicit equal-value overrides and list indentation style edits." $doc = $word.Documents.Open((Join-Path $testDirectory "$engine.docx"), $false, $true) try { $range = $doc.Content.Duplicate