1param([Parameter(Mandatory=$true)][string]$Root, [Parameter(Mandatory=$true)][string]$CloneHost)
2Set-StrictMode -Version Latest
3$ErrorActionPreference = 'Stop'
4& "$PSScriptRoot\cold-current.ps1" -Root $Root -CloneHost $CloneHost
5$inputs = Join-Path $Root 'inputs'
6New-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'
10try {
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 $body = '<one:TagDef index="0" type="0" symbol="3" fontColor="automatic" highlightColor="none" name="Fixture checkbox"/><one:TagDef index="1" type="90" symbol="13" fontColor="#804020" highlightColor="#00ffff" name="Fixture custom tag"/><one:QuickStyleDef index="0" name="h1" font="Calibri" fontSize="20" bold="true" fontColor="#123456" highlightColor="automatic" spaceBefore="8" spaceAfter="4"/>' + $body
30 $body += '<one:Outline><one:Position x="72" y="540"/><one:Size width="480" height="600"/><one:OEChildren>'
31 $body += '<one:OE quickStyleIndex="0" alignment="right"><one:T><![CDATA[Named paragraph style]]></one:T></one:OE>'
32 $body += '<one:OE><one:Tag index="0" completed="false" disabled="false" creationDate="2020-01-02T03:04:05.000Z"/><one:Tag index="1" completed="true" disabled="false" creationDate="2020-01-02T03:04:05.000Z" completionDate="2020-01-02T04:05:06.000Z"/><one:T><![CDATA[Two tags on this paragraph]]></one:T></one:OE>'
33 $body += '<one:OE><one:List><one:Bullet bullet="3" fontSize="11"/></one:List><one:T><![CDATA[Outer bullet]]></one:T><one:OEChildren><one:OE><one:List><one:Bullet bullet="13" fontSize="11"/></one:List><one:T><![CDATA[Nested bullet]]></one:T></one:OE></one:OEChildren></one:OE>'
34 $body += '<one:OE><one:List><one:Number numberSequence="1" numberFormat="##." restartNumberingAt="3" font="Calibri" fontSize="11"/></one:List><one:T><![CDATA[Numbered item three]]></one:T></one:OE><one:OE><one:List><one:Number numberSequence="1" numberFormat="##." font="Calibri" fontSize="11"/></one:List><one:T><![CDATA[Numbered item four]]></one:T></one:OE>'
35 $body += '<one:OE><one:Table bordersVisible="true"><one:Columns><one:Column index="0" width="120" isLocked="true"/><one:Column index="1" width="180" isLocked="false"/></one:Columns>'
36 foreach ($row in 0..2) {
37 $body += '<one:Row>'
38 foreach ($column in 0..1) {
39 $body += '<one:Cell><one:OEChildren><one:OE><one:T><![CDATA[Cell ' + $row + ',' + $column + ']]></one:T></one:OE></one:OEChildren></one:Cell>'
40 }
41 $body += '</one:Row>'
42 }
43 $body += '</one:Table></one:OE></one:OEChildren></one:Outline>'
44
45 $xml = '<one:Page xmlns:one="' + $namespace + '" ID="' + $pageId + '">' + $body + '</one:Page>'
46 [IO.File]::WriteAllText((Join-Path $inputs 'format-probes.xml'), $xml, [Text.Encoding]::UTF8)
47 $app.UpdatePageContent($xml, [DateTime]::MinValue, 1, $true)
48 $cases | ConvertTo-Json -Depth 8 | Set-Content (Join-Path $Root 'expected.json') -Encoding UTF8
49 $app.SyncHierarchy($notebookId)
50 $app.CloseNotebook($notebookId, $false)
51 $notebookId = ''
52} finally {
53 if ($notebookId) { $app.CloseNotebook($notebookId, $false) }
54 [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app)
55 $app = $null
56 [GC]::Collect()
57 [GC]::WaitForPendingFinalizers()
58}