| 1 | param([Parameter(Mandatory=$true)][string]$Root, [Parameter(Mandatory=$true)][string]$CloneHost) |
| 2 | Set-StrictMode -Version Latest |
| 3 | $ErrorActionPreference = 'Stop' |
| 4 | & "$PSScriptRoot\cold-current.ps1" -Root $Root -CloneHost $CloneHost |
| 5 | $inputs = Join-Path $Root 'inputs' |
| 6 | New-Item -ItemType Directory -Path $inputs | Out-Null |
| 7 | $app = New-Object -ComObject OneNote.Application |
| 8 | $notebookId = '' |
| 9 | $namespace = 'http://schemas.microsoft.com/office/onenote/2010/onenote' |
| 10 | try { |
| 11 | $app.OpenHierarchy((Join-Path $Root 'notebook'), '', [ref]$notebookId, 0) |
| 12 | $sectionId = '' |
| 13 | $app.OpenHierarchy('synthetic.one', $notebookId, [ref]$sectionId, 0) |
| 14 | $cases = @( |
| 15 | @{ name = 'Black highlight control'; html = '<span style="background:black">Black highlight, automatic text</span>' }, |
| 16 | @{ name = 'White on black'; html = '<span style="background:black;color:white">White text on black highlight</span>' }, |
| 17 | @{ name = 'Black on black'; html = '<span style="background:black;color:black">Black text on black highlight</span>' }, |
| 18 | @{ name = 'Partial black highlight'; html = '<b>Before <span style="background:black">middle</span> after</b>' }, |
| 19 | @{ name = 'Yellow control'; html = '<span style="background:yellow">Yellow highlight, automatic text</span>' }, |
| 20 | @{ name = 'Character styles'; html = 'Plain <b>bold</b> <i>italic</i> <u>underline</u> <s>strike</s> <sup>super</sup> <sub>sub</sub> <span style="font-family:Consolas;font-size:18pt;color:#804020;background:#00ffff">font and color</span>' }, |
| 21 | @{ name = 'Unicode runs'; html = 'BMP <b>' + [char]::ConvertFromUtf32(0x1F600) + 'e' + [char]0x0301 + '</b> ' + [char]0x6771 + [char]0x4EAC + ' <i>' + [char]0x0645 + [char]0x0631 + [char]0x062D + [char]0x0628 + [char]0x0627 + '</i>' }, |
| 22 | @{ name = 'Link runs'; html = 'Before <a href="https://example.invalid/fixture?x=1&amp;y=2"><b>Link label</b></a> after' } |
| 23 | ) |
| 24 | $pageId = '' |
| 25 | $app.CreateNewPage($sectionId, [ref]$pageId, 0) |
| 26 | $body = '<one:Title><one:OE><one:T><![CDATA[Native feature probes]]></one:T></one:OE></one:Title><one:Outline><one:Position x="72" y="108"/><one:Size width="480" height="400"/><one:OEChildren>' |
| 27 | foreach ($case in $cases) { $body += '<one:OE><one:T><![CDATA[' + $case.html + ']]></one:T></one:OE>' } |
| 28 | $body += '</one:OEChildren></one:Outline>' |
| 29 | $xml = '<one:Page xmlns:one="' + $namespace + '" ID="' + $pageId + '">' + $body + '</one:Page>' |
| 30 | [IO.File]::WriteAllText((Join-Path $inputs 'format-probes.xml'), $xml, [Text.Encoding]::UTF8) |
| 31 | $app.UpdatePageContent($xml, [DateTime]::MinValue, 1, $true) |
| 32 | $cases | ConvertTo-Json -Depth 8 | Set-Content (Join-Path $Root 'expected.json') -Encoding UTF8 |
| 33 | $app.SyncHierarchy($notebookId) |
| 34 | $app.CloseNotebook($notebookId, $false) |
| 35 | $notebookId = '' |
| 36 | } finally { |
| 37 | if ($notebookId) { $app.CloseNotebook($notebookId, $false) } |
| 38 | [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app) |
| 39 | $app = $null |
| 40 | [GC]::Collect() |
| 41 | [GC]::WaitForPendingFinalizers() |
| 42 | } |