feat: Working on node builder
This commit is contained in:
32
Sources/CliDoc/Nodes/Header.swift
Normal file
32
Sources/CliDoc/Nodes/Header.swift
Normal file
@@ -0,0 +1,32 @@
|
||||
@preconcurrency import Rainbow
|
||||
|
||||
public struct Header: NodeRepresentable {
|
||||
|
||||
@usableFromInline
|
||||
let node: Text
|
||||
|
||||
@usableFromInline
|
||||
let styles: [Style]
|
||||
|
||||
@inlinable
|
||||
public init(
|
||||
_ text: String,
|
||||
color: NamedColor? = .yellow,
|
||||
styles: [Style] = [.bold]
|
||||
) {
|
||||
var text = Text(text)
|
||||
if let color {
|
||||
text = text.color(color)
|
||||
}
|
||||
self.node = text
|
||||
self.styles = styles
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func render() -> String {
|
||||
styles.reduce(node) { node, style in
|
||||
node.style(style)
|
||||
}
|
||||
.render()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user