Skip to content

Commit

Permalink
Formatting code updates
Browse files Browse the repository at this point in the history
  • Loading branch information
PrzemyslawKlys committed Aug 20, 2020
1 parent 6087b2a commit eff9a8f
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions Private/Format-MarkdownCode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,54 @@
)
$SplitOverNewLines = $ContentMarkdown -split [Environment]::Newline
$MyData = [System.Text.StringBuilder]::new()
$FirstCodeTag = $false
$EmptyLineLast = $false
$InsideCodeBlock = $false
foreach ($N in $SplitOverNewLines) {
if ($N.Trim()) {
if ($N.Trim() -match '```') {
if ($FirstCodeTag -eq $true) {
$TrimmedLine = $N.Trim()
if ($TrimmedLine) {
if ($TrimmedLine -match '```') {
if ($InsideCodeBlock -eq $true) {
# this means we found closing tag so we need to add new line after
$null = $MyData.AppendLine($N)
$null = $MyData.AppendLine()
$InsideCodeBlock = $false
$EmptyLineLast = $true
} else {
# this means we found opening tag so we need to add new line before
$FirstCodeTag = $true
$null = $MyData.AppendLine()
$InsideCodeBlock = $true
if ($EmptyLineLast) {

} else {
$null = $MyData.AppendLine()
}
$null = $MyData.AppendLine($N)
$EmptyLineLast = $false
}
} elseif (($TrimmedLine.StartsWith('#') -or $TrimmedLine.StartsWith('![]'))) {
if ($InsideCodeBlock) {
# we're inside of code block. we put things without new lines
$null = $MyData.AppendLine($N.TrimEnd())
$EmptyLineLast = $false
} else {
if ($EmptyLineLast) {

} else {
$null = $MyData.AppendLine()
}
$null = $MyData.AppendLine($N.TrimEnd())
$null = $MyData.AppendLine()
$EmptyLineLast = $true
}
} else {
$null = $MyData.AppendLine($N.TrimEnd())
if ($InsideCodeBlock) {
# we're inside of code block. we put things without new lines
$null = $MyData.AppendLine($N.TrimEnd())
$EmptyLineLast = $false
} else {
$null = $MyData.AppendLine($N.TrimEnd())
$null = $MyData.AppendLine()
$EmptyLineLast = $true
}
}
}
}
Expand Down

0 comments on commit eff9a8f

Please sign in to comment.