---
tags:
  - type/guide
  - topic/hobbies/digitizing
title: Converting Documents to Markdown
---
# Converting Documents to Markdown

```powershell
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

```powershell
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
```

## Semantic Line Breaks

[[semantic-line-breaks]]