Private/Convert-JiraMarkdownInlineToADF.ps1
|
function Convert-JiraMarkdownInlineToADF { <# .SYNOPSIS Parst Inline-Markdown (**bold**, *italic*, `code`, [text](url)) in ein Array von ADF-Text-Nodes. #> [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [AllowEmptyString()] [string] $Text ) process { $nodes = [System.Collections.Generic.List[hashtable]]::new() $remaining = $Text while ($remaining.Length -gt 0) { # Link [text](url) if ($remaining -match '^\[([^\]]+)\]\(([^)]+)\)') { $nodes.Add(@{ type = 'text' text = $Matches[1] marks = @(@{ type = 'link'; attrs = @{ href = $Matches[2] } }) }) $remaining = $remaining.Substring($Matches[0].Length) } # Bold **text** or __text__ elseif ($remaining -match '^\*\*([^*]+)\*\*' -or $remaining -match '^__([^_]+)__') { $nodes.Add(@{ type = 'text' text = $Matches[1] marks = @(@{ type = 'strong' }) }) $remaining = $remaining.Substring($Matches[0].Length) } # Italic *text* or _text_ elseif ($remaining -match '^\*([^*]+)\*' -or $remaining -match '^_([^_]+)_') { $nodes.Add(@{ type = 'text' text = $Matches[1] marks = @(@{ type = 'em' }) }) $remaining = $remaining.Substring($Matches[0].Length) } # Inline code `text` elseif ($remaining -match '^`([^`]+)`') { $nodes.Add(@{ type = 'text' text = $Matches[1] marks = @(@{ type = 'code' }) }) $remaining = $remaining.Substring($Matches[0].Length) } else { $next = [regex]::Match($remaining, '\[|\*\*|__|\*|_|`') if ($next.Success -and $next.Index -gt 0) { $nodes.Add(@{ type = 'text'; text = $remaining.Substring(0, $next.Index) }) $remaining = $remaining.Substring($next.Index) } else { $nodes.Add(@{ type = 'text'; text = $remaining }) $remaining = '' } } } return , $nodes.ToArray() } } |