65 lines
3.4 KiB
PowerShell
65 lines
3.4 KiB
PowerShell
param([string]$Python = (Join-Path $PSScriptRoot '..\mdhelper_env\mdhelper_env\Scripts\python.exe'))
|
|
$ErrorActionPreference='Stop'
|
|
Push-Location (Join-Path $PSScriptRoot '..')
|
|
$word=$null
|
|
try {
|
|
$folder = (@'
|
|
import sys,tempfile
|
|
from pathlib import Path
|
|
sys.path.insert(0,str(Path('tests').resolve()))
|
|
from test_style_revision_056 import *
|
|
folder=Path(tempfile.mkdtemp(prefix='MDHelper-056-Word-'))
|
|
for engine in ENGINES:
|
|
for name,source,rules in [('code',CODE_SOURCE,CODE_RULES),('bold','# Parent\n\nBody `Inline`',BOLD_RULES),
|
|
('heading',HEADING_LIST,{}),('listcode',CODE_LIST,{}),('nested',NESTED_LIST,{})]:
|
|
export_markdown_to_docx(source,folder/f'{engine}-{name}.docx',engine=engine,style_rules=rules)
|
|
print(folder)
|
|
'@ | & $Python -B -).Trim()
|
|
if ($LASTEXITCODE -ne 0) {throw 'Fixture generation failed'}
|
|
$word=New-Object -ComObject Word.Application
|
|
$word.Visible=$false;$word.DisplayAlerts=0
|
|
foreach($engine in @('builtin','python-docx','pandoc')) {
|
|
foreach($case in @('code','bold','heading','listcode','nested')) {
|
|
$doc=$word.Documents.Open((Join-Path $folder "$engine-$case.docx"),$false,$true)
|
|
try {
|
|
if($case -eq 'code') {
|
|
foreach($text in @('PlainCode','InnerCode','OtherCode')) {
|
|
$r=$doc.Content.Duplicate;[void]$r.Find.Execute($text)
|
|
if($r.Font.Color -ne 255 -or $r.Font.Size -ne 20 -or $r.Font.Bold -ne -1 -or $r.Font.Underline -ne 0){throw "$engine $text lost code ancestor formatting"}
|
|
}
|
|
$doc.Styles.Item('MDHelper 标题 1').Font.Color=16711680
|
|
$r=$doc.Content.Duplicate;[void]$r.Find.Execute('PlainCode')
|
|
if($r.Font.Color -ne 16711680){throw "$engine code ancestor no longer editable"}
|
|
$doc.Styles.Item('MDHelper 加粗+行内代码').Font.Color=65280
|
|
foreach($text in @('InnerCode','OtherCode')) {
|
|
$r=$doc.Content.Duplicate;[void]$r.Find.Execute($text)
|
|
if($r.Font.Color -ne 65280){throw "$engine shared mixed style no longer editable"}
|
|
}
|
|
} elseif($case -eq 'bold') {
|
|
$r=$doc.Content.Duplicate;[void]$r.Find.Execute('Inline')
|
|
if($r.Font.Bold -ne -1 -or $r.Font.Size -ne 24.5){throw "$engine code emphasis reversed or defaults lost"}
|
|
} else {
|
|
$pairs = switch($case) {
|
|
'heading' { ,@(@('FirstHeading','1.'),@('Continuation',''),@('SecondHeading','2.')) }
|
|
'listcode' { ,@(@('CodeFirst','1.'),@('Continuation',''),@('Second','2.')) }
|
|
'nested' { ,@(@('Outer','1.'),@('NestedHeading','1.'),@('NestedCode','2.'),@('LastNested','3.'),@('LastOuter','2.')) }
|
|
}
|
|
foreach($pair in $pairs) {
|
|
$r=$doc.Content.Duplicate;[void]$r.Find.Execute($pair[0])
|
|
if($r.ListFormat.ListString.Trim() -ne $pair[1]){throw "$engine $case $($pair[0]) marker: $($r.ListFormat.ListString) expected $($pair[1])"}
|
|
}
|
|
$target=if($case -eq 'heading'){'FirstHeading'}elseif($case -eq 'listcode'){'CodeFirst'}else{'NestedHeading'}
|
|
$style=if($case -eq 'listcode'){'MDHelper 代码块'}else{'MDHelper 标题 3'}
|
|
$doc.Styles.Item($style).Font.Color=65280
|
|
$r=$doc.Content.Duplicate;[void]$r.Find.Execute($target)
|
|
if($r.Font.Color -ne 65280){throw "$engine list block lost editable paragraph base"}
|
|
}
|
|
Write-Output "$engine $case passed"
|
|
} finally {$doc.Close(0);[void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($doc)}
|
|
}
|
|
}
|
|
} finally {
|
|
if($word){$word.Quit();[void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($word)}
|
|
Pop-Location
|
|
}
|