[CmdletBinding()]
param()
$ErrorActionPreference = 'Stop'
$outputPath = Join-Path $PSScriptRoot 'setprotocol.html'
$sourcePath = Join-Path $PSScriptRoot '..\c\set-protocol\docs\SETPROTOCOL.md'
$canFrameSourcePath = Join-Path $PSScriptRoot 'CAN_FRAME_PARSE_V1_V2.md'
function Convert-DocumentationMarkdown {
param([string]$Path)
$markdown = Get-Content -Raw -LiteralPath $Path -Encoding UTF8
$html = (ConvertFrom-Markdown -InputObject $markdown).Html
# Wide protocol tables must scroll horizontally instead of squeezing their
# contents into unreadable one-character columns on a narrow viewport.
$html = $html -replace '
', ''
$html = $html -replace '
', '
'
return $html
}
$html = Convert-DocumentationMarkdown -Path $sourcePath
$generatedBlock = @"
$html
"@
$canFrameHtml = Convert-DocumentationMarkdown -Path $canFrameSourcePath
$canFrameBlock = @"
$canFrameHtml
"@
$page = Get-Content -Raw -LiteralPath $outputPath -Encoding UTF8
$pattern = '(?s).*?'
if ($page -notmatch $pattern) {
throw 'Не найдены маркеры SETPROTOCOL:START/END в doc/setprotocol.html.'
}
$page = [regex]::Replace($page, $pattern, [System.Text.RegularExpressions.MatchEvaluator]{
param($match)
$generatedBlock
}, 1)
$canFramePattern = '(?s).*?'
if ($page -notmatch $canFramePattern) {
throw 'Не найдены маркеры CAN-FRAME-PARSE:START/END в doc/setprotocol.html.'
}
$page = [regex]::Replace($page, $canFramePattern, [System.Text.RegularExpressions.MatchEvaluator]{
param($match)
$canFrameBlock
}, 1)
$page = $page.TrimEnd("`r", "`n") + [Environment]::NewLine
$utf8WithoutBom = [System.Text.UTF8Encoding]::new($false)
[System.IO.File]::WriteAllText($outputPath, $page, $utf8WithoutBom)
Write-Host "[DONE] SETProtocol HTML: $outputPath"