| 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 | $app = New-Object -ComObject OneNote.Application |
| 6 | $notebook = '' |
| 7 | try { |
| 8 | $app.OpenHierarchy((Join-Path $Root 'notebook'), '', [ref]$notebook, 0) |
| 9 | $section = '' |
| 10 | $app.OpenHierarchy('synthetic.one', $notebook, [ref]$section, 0) |
| 11 | $mixed = '<b>Bold</b> <i>italic</i> ' + [char]::ConvertFromUtf32(0x1F980) + ' e' + [char]0x0301 + ' <span style="color:#123456">tail</span>' |
| 12 | $text = '<one:T><![CDATA[' + $mixed + ']]></one:T>' |
| 13 | $child = '<one:OEChildren><one:OE><one:T>Preserved child</one:T></one:OE></one:OEChildren>' |
| 14 | $tag = '<one:Tag index="0" completed="true" disabled="false" creationDate="2020-01-02T03:04:05.000Z" completionDate="2020-01-02T04:05:06.000Z"/>' |
| 15 | $cases = @( |
| 16 | @{ name = 'Join inherited styles'; body = '<one:OE quickStyleIndex="0"><one:T>Left </one:T></one:OE><one:OE quickStyleIndex="1"><one:T><![CDATA[Right <i>italic</i>]]></one:T></one:OE>' }, |
| 17 | @{ name = 'Join empty left tag'; body = '<one:OE>' + $tag + '<one:T><![CDATA[]]></one:T></one:OE><one:OE>' + $text + '</one:OE>' }, |
| 18 | @{ name = 'Join right tag'; body = '<one:OE><one:T>Left </one:T></one:OE><one:OE>' + $tag + $text + '</one:OE>' }, |
| 19 | @{ name = 'Join both tags'; body = '<one:OE>' + $tag + '<one:T>Left </one:T></one:OE><one:OE>' + $tag + $text + '</one:OE>' }, |
| 20 | @{ name = 'Join both children'; body = '<one:OE><one:T>Left </one:T><one:OEChildren><one:OE><one:T>Left child</one:T></one:OE></one:OEChildren></one:OE><one:OE>' + $text + '<one:OEChildren><one:OE><one:T>Right child</one:T></one:OE></one:OEChildren></one:OE>' } |
| 21 | ) |
| 22 | $inputs = Join-Path $Root 'inputs' |
| 23 | New-Item -ItemType Directory -Path $inputs | Out-Null |
| 24 | foreach ($case in $cases) { |
| 25 | $page = '' |
| 26 | $app.CreateNewPage($section, [ref]$page, 0) |
| 27 | $xml = '<one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2010/onenote" ID="' + $page + '"><one:TagDef index="0" type="0" symbol="3" fontColor="automatic" highlightColor="none" name="Fixture task"/><one:QuickStyleDef index="0" name="p" font="Calibri" fontSize="11" fontColor="automatic" highlightColor="automatic"/><one:QuickStyleDef index="1" name="h1" font="Georgia" fontSize="18" bold="true" fontColor="#123456" highlightColor="automatic" spaceBefore="8" spaceAfter="4"/><one:Title><one:OE><one:T>' + $case.name + '</one:T></one:OE></one:Title><one:Outline><one:Position x="72" y="108"/><one:OEChildren>' + $case.body + '<one:OE><one:T>Preserved sibling</one:T></one:OE></one:OEChildren></one:Outline></one:Page>' |
| 28 | [IO.File]::WriteAllText((Join-Path $inputs ($case.name + '.xml')), $xml, [Text.Encoding]::UTF8) |
| 29 | $app.UpdatePageContent($xml, [DateTime]::MinValue, 1, $true) |
| 30 | $case.page = $page |
| 31 | } |
| 32 | $cases | ConvertTo-Json -Depth 6 | Set-Content (Join-Path $Root 'cases.json') -Encoding UTF8 |
| 33 | $app.SyncHierarchy($notebook) |
| 34 | } finally { |
| 35 | if ($notebook) { $app.CloseNotebook($notebook, $false) } |
| 36 | [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app) |
| 37 | $app = $null |
| 38 | [GC]::Collect() |
| 39 | [GC]::WaitForPendingFinalizers() |
| 40 | } |