1.4 KiB
1.4 KiB
id, aliases, tags, title, dg-publish
| id | aliases | tags | title | dg-publish | ||||
|---|---|---|---|---|---|---|---|---|
|
Converting Documents to Markdown | true |
Converting Documents to Markdown
param(
[string]$Path
)
$content = Get-Content -Path $Path
$newContent = $content
$newContent -replace "foos", "ball"
$newContent -replace "foo", "bar"
# ...
Set-Content -Path $Path -Value $newContent
Converting NFPA Code
param(
[string]$Path,
[string]$DestinationPath
)
$content = Get-Content -Path $Path
$newContent = $content
# "210.17(B)(3)" -> h5
$newContent = $newContent -replace '^(\d{3}\.\d+\([A-Z]\)\(\d\) .+)$', "`n##### `$1`n"
# "210.17(B)" -> h4
$newContent = $newContent -replace '^(\d{3}\.\d+\([A-Z]\) .+)$', "`n#### `$1`n"
# "210.17" -> h3
$newContent = $newContent -replace '^(\d{3}\.\d+ .+)$', "`n### `$1`n"
# "Part I. General" -> h2
$newContent = $newContent -replace '^(Part [IVX]+\. .+)$', "`n## `$1`n"
# "(1)" -> "1."
$newContent = $newContent -replace '^\((\d\d?)\)', "`$1."
# "(41⁄ 2 ft)" -> "(4 1/2 ft)"
# TODO: \u2044
# "Informational Note: Types NM, NMC..."
# "Informational Note No. 1:"
New-Item -Type File -Path $DestinationPath -ErrorAction SilentlyContinue | Out-Null
Set-Content -Path $DestinationPath -Value $newContent