MarkdownBlockNode is an enum that represents all block-level elements in a parsed markdown document. Block nodes are structural elements like paragraphs, headings, lists, and code blocks.
Definition
public enum MarkdownBlockNode: Hashable, Equatable, Codable
Enum Cases
paragraph
A paragraph containing inline content.
case paragraph(content: [MarkdownInlineNode])
content
[MarkdownInlineNode]
required
Array of inline nodes (text, emphasis, links, etc.) that make up the paragraph content
Example
// Markdown: "This is **bold** text."
.paragraph(content: [
.text("This is "),
.strong(children: [.text("bold")]),
.text(" text.")
])
heading
A heading with a specific level (1-6).
case heading(level: Int, content: [MarkdownInlineNode])
Heading level from 1 to 6 (corresponding to H1 through H6)
content
[MarkdownInlineNode]
required
Inline content of the heading
Example
// Markdown: "# Hello World"
.heading(level: 1, content: [.text("Hello World")])
// Markdown: "### Section 3.1"
.heading(level: 3, content: [.text("Section 3.1")])
blockquote
A blockquote containing nested block elements.
case blockquote(children: [MarkdownBlockNode])
children
[MarkdownBlockNode]
required
Nested block nodes contained within the blockquote
Example
// Markdown: "> This is a quote\n> with two lines"
.blockquote(children: [
.paragraph(content: [
.text("This is a quote"),
.softBreak,
.text("with two lines")
])
])
bulletedList
An unordered list with bullet points.
case bulletedList(isTight: Bool, items: [RawListItem])
true if the list is tight (no blank lines between items), false if loose
Array of list items, each containing nested block nodes
Example
// Markdown: "- Item 1\n- Item 2"
.bulletedList(isTight: true, items: [
RawListItem(children: [.paragraph(content: [.text("Item 1")])]),
RawListItem(children: [.paragraph(content: [.text("Item 2")])])
])
numberedList
An ordered list with numbers.
case numberedList(isTight: Bool, start: Int, items: [RawListItem])
true if the list is tight (no blank lines between items), false if loose
Starting number for the list (typically 1)
Array of list items, each containing nested block nodes
Example
// Markdown: "1. First\n2. Second\n3. Third"
.numberedList(isTight: true, start: 1, items: [
RawListItem(children: [.paragraph(content: [.text("First")])]),
RawListItem(children: [.paragraph(content: [.text("Second")])]),
RawListItem(children: [.paragraph(content: [.text("Third")])])
])
taskList
A task list with checkable items (GitHub Flavored Markdown extension).
case taskList(isTight: Bool, items: [RawTaskListItem])
true if the list is tight (no blank lines between items), false if loose
items
[RawTaskListItem]
required
Array of task list items with completion status
Example
// Markdown: "- [x] Completed task\n- [ ] Incomplete task"
.taskList(isTight: true, items: [
RawTaskListItem(isCompleted: true, children: [
.paragraph(content: [.text("Completed task")])
]),
RawTaskListItem(isCompleted: false, children: [
.paragraph(content: [.text("Incomplete task")])
])
])
codeBlock
A fenced or indented code block.
case codeBlock(fenceInfo: String?, content: String)
Language identifier or other metadata from the fence (e.g., “swift”, “javascript”). nil for indented code blocks.
Raw text content of the code block
Example
// Markdown: "```swift\nlet x = 42\n```"
.codeBlock(fenceInfo: "swift", content: "let x = 42\n")
// Markdown: " indented code"
.codeBlock(fenceInfo: nil, content: "indented code\n")
table
A table (GitHub Flavored Markdown extension).
case table(columnAlignments: [RawTableColumnAlignment], rows: [RawTableRow])
columnAlignments
[RawTableColumnAlignment]
required
Array specifying the alignment for each column (.left, .center, .right, or .none)
Array of table rows, including the header row. Each row contains cells with inline content.
Example
// Markdown:
// | Name | Age |
// |------|----:|
// | Alice | 30 |
.table(
columnAlignments: [.none, .right],
rows: [
RawTableRow(cells: [
RawTableCell(content: [.text("Name")]),
RawTableCell(content: [.text("Age")])
]),
RawTableRow(cells: [
RawTableCell(content: [.text("Alice")]),
RawTableCell(content: [.text("30")])
])
]
)
thematicBreak
A horizontal rule or thematic break.
Example
// Markdown: "---" or "***" or "___"
.thematicBreak
Properties
children
Returns the child blocks for container nodes.
var children: [MarkdownBlockNode] { get }
Returns child blocks for .blockquote, .bulletedList, .numberedList, and .taskList. Returns empty array for leaf nodes.
isParagraph
Checks if the node is a paragraph.
var isParagraph: Bool { get }
Returns true only for .paragraph nodes.
Supporting Types
RawListItem
public struct RawListItem: Hashable, Equatable, Codable {
public let children: [MarkdownBlockNode]
public init(children: [MarkdownBlockNode])
}
Represents a single item in a bulleted or numbered list.
RawTaskListItem
public struct RawTaskListItem: Hashable, Equatable, Codable {
public let isCompleted: Bool
public let children: [MarkdownBlockNode]
public init(isCompleted: Bool, children: [MarkdownBlockNode])
}
Represents a task list item with completion status.
RawTableColumnAlignment
public enum RawTableColumnAlignment: Character, Equatable, Codable {
case none = "\0"
case left = "l"
case center = "c"
case right = "r"
}
Specifies text alignment for a table column.
RawTableRow
public struct RawTableRow: Hashable, Equatable, Codable {
public let cells: [RawTableCell]
public init(cells: [RawTableCell])
}
Represents a row in a table.
RawTableCell
public struct RawTableCell: Hashable, Equatable, Codable {
public let content: [MarkdownInlineNode]
public init(content: [MarkdownInlineNode])
}
Represents a single cell in a table containing inline content.
Related Types