[CmdletBinding()] param() $ErrorActionPreference = 'Stop' $outputPath = Join-Path $PSScriptRoot 'index.html' $sourceDirectory = Join-Path $PSScriptRoot 'protocan' $documents = @( 'README.md', 'PROTOCOL.md', 'BOOTLOADER.md', 'OAP.md', 'CHANGELOG.md' ) function Convert-LocalLinks { param( [string]$Html, [string]$SourcePath ) $sourceParent = Split-Path -Parent $SourcePath $outputParent = Split-Path -Parent $outputPath $pattern = '(?href|src)="(?(?![a-z]+:|/|#)[^"]+)"' return [regex]::Replace($Html, $pattern, { param($match) $target = $match.Groups['target'].Value $parts = $target -split '#', 2 $targetPath = [Uri]::UnescapeDataString($parts[0]) $absoluteTarget = [System.IO.Path]::GetFullPath((Join-Path $sourceParent $targetPath)) $relativeTarget = [System.IO.Path]::GetRelativePath($outputParent, $absoluteTarget).Replace('\', '/') if ($parts.Count -eq 2) { $relativeTarget += '#' + $parts[1] } return $match.Groups['attribute'].Value + '="' + $relativeTarget + '"' }) } $sections = foreach ($document in $documents) { $path = Join-Path $sourceDirectory $document $markdown = Get-Content -Raw -LiteralPath $path -Encoding UTF8 $html = (ConvertFrom-Markdown -InputObject $markdown).Html $html = Convert-LocalLinks -Html $html -SourcePath $path "
$html
" } $vectorsPath = Join-Path $sourceDirectory 'examples\test-vectors.json' $vectors = [System.Net.WebUtility]::HtmlEncode( (Get-Content -Raw -LiteralPath $vectorsPath -Encoding UTF8) ) $sections += @"

Тестовые векторы

Машинные эталоны из examples/test-vectors.json.

$vectors
"@ $generatedBlock = @"

Полная документация ProtoCAN

Нормативные документы и тестовые векторы собраны в эту страницу из исходников doc/setcan/protocan.

$($sections -join "`n")
"@ $page = Get-Content -Raw -LiteralPath $outputPath -Encoding UTF8 $pattern = '(?s).*?' if ($page -notmatch $pattern) { throw 'Не найдены маркеры PROTOCAN:START/END в doc/setcan/index.html.' } $page = [regex]::Replace($page, $pattern, [System.Text.RegularExpressions.MatchEvaluator]{ param($match) $generatedBlock }, 1) $page = $page.TrimEnd("`r", "`n") + [Environment]::NewLine $utf8WithoutBom = [System.Text.UTF8Encoding]::new($false) [System.IO.File]::WriteAllText($outputPath, $page, $utf8WithoutBom) Write-Host "[DONE] Создан единый HTML: $outputPath"