Добавить HTML-справочник CAN v1 и v2
This commit is contained in:
@@ -4,9 +4,22 @@ 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'
|
||||
|
||||
$markdown = Get-Content -Raw -LiteralPath $sourcePath -Encoding UTF8
|
||||
$html = (ConvertFrom-Markdown -InputObject $markdown).Html
|
||||
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 '<table>', '<div class="table-wrap"><table>'
|
||||
$html = $html -replace '</table>', '</table></div>'
|
||||
return $html
|
||||
}
|
||||
|
||||
$html = Convert-DocumentationMarkdown -Path $sourcePath
|
||||
$generatedBlock = @"
|
||||
<!-- SETPROTOCOL:START -->
|
||||
<article class="card full-doc" data-source="c/set-protocol/docs/SETPROTOCOL.md">
|
||||
@@ -15,6 +28,15 @@ $html
|
||||
<!-- SETPROTOCOL:END -->
|
||||
"@
|
||||
|
||||
$canFrameHtml = Convert-DocumentationMarkdown -Path $canFrameSourcePath
|
||||
$canFrameBlock = @"
|
||||
<!-- CAN-FRAME-PARSE:START -->
|
||||
<article class="card full-doc" data-source="doc/CAN_FRAME_PARSE_V1_V2.md">
|
||||
$canFrameHtml
|
||||
</article>
|
||||
<!-- CAN-FRAME-PARSE:END -->
|
||||
"@
|
||||
|
||||
$page = Get-Content -Raw -LiteralPath $outputPath -Encoding UTF8
|
||||
$pattern = '(?s)<!-- SETPROTOCOL:START -->.*?<!-- SETPROTOCOL:END -->'
|
||||
if ($page -notmatch $pattern) {
|
||||
@@ -26,6 +48,16 @@ $page = [regex]::Replace($page, $pattern, [System.Text.RegularExpressions.MatchE
|
||||
$generatedBlock
|
||||
}, 1)
|
||||
|
||||
$canFramePattern = '(?s)<!-- CAN-FRAME-PARSE:START -->.*?<!-- CAN-FRAME-PARSE:END -->'
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user