Uh oh!
There was an error while loading. Please reload this page.
🚀 [Minor]: Markdown documents can now be parsed into objects and regenerated - #18
🚀 [Minor]: Markdown documents can now be parsed into objects and regenerated#18Marius Storhaug (MariusStorhaug) wants to merge 6 commits into
Conversation
Super-linter summary
Super-linter detected linting errors For more information, see the GitHub Actions workflow run Powered by Super-linter NATURAL_LANGUAGEPOWERSHELL |
Super-linter summary
Super-linter detected linting errors For more information, see the GitHub Actions workflow run Powered by Super-linter NATURAL_LANGUAGEPOWERSHELL |
Super-linter summary
Super-linter detected linting errors For more information, see the GitHub Actions workflow run Powered by Super-linter NATURAL_LANGUAGE |
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
Markdown documents can now be parsed into a structured, AST-like object tree and converted back to well-formatted markdown strings. This enables programmatic inspection, transformation, and round-tripping of markdown content using the standard PowerShell
ConvertFrom-/ConvertTo-verb pattern — the same convention used byConvertFrom-JsonandConvertTo-Json.New: Parse markdown into structured objects
ConvertFrom-Markdownaccepts a markdown string (via-InputObjector pipeline) and returns aMarkdownDocumentobject tree where each element is a typed node.Supported node types:
MarkdownHeader(levels 1–6 with nested content),MarkdownCodeBlock(fenced code blocks with language),MarkdownParagraph(with optional<p>tags),MarkdownTable(rows as PSCustomObjects),MarkdownDetails(collapsible<details>sections), andMarkdownText(plain text).New: Generate markdown from object trees
ConvertTo-Markdownaccepts aMarkdownDocumentobject and renders it back to a markdown string.Documents can also be constructed programmatically:
New: Round-trip markdown preservation
Parsing a markdown string and converting it back preserves the structural content of the document:
Technical Details
src/classes/:MarkdownDocument,MarkdownHeader,MarkdownCodeBlock,MarkdownParagraph,MarkdownTable,MarkdownDetails,MarkdownText. Uses PowerShell classes for type safety and IntelliSense. NoParentreferences (avoids circular serialization issues).ConvertFrom-Markdown): Line-by-line state machine using a stack to track container nesting. Handles heading hierarchy (auto-nests by level), fenced code blocks,<details>/<summary>blocks with nested<p>structural tags, pipe-delimited tables, and<p>-tagged paragraphs.ConvertTo-Markdown): Recursive node visitor usingStringBuilder. Each node type has its own rendering logic.ConvertFrom-Markdown(13 tests),ConvertTo-Markdown(10 tests), and round-trip integration (5 tests). Covers all node types, nesting, edge cases (empty documents, level jumps), and pipeline input.Set-Markdown*functions (DSL approach) and theConvertFrom-/ConvertTo-functions (object approach) are complementary and independent. The DSL remains the imperative way to compose markdown; the Convert functions add parse/serialize capabilities.ConvertFrom-MarkdownMarkdown/ConvertTo-MarkdownDSL) but significantly redesigned: proper class hierarchy instead of PSCustomObjects, string input instead of file paths, markdown output instead of DSL script blocks.