diff --git a/Sources/MarkdownUI/Theme/BlockStyle/TableBorderStyle.swift b/Sources/MarkdownUI/Theme/BlockStyle/TableBorderStyle.swift index 06a6921a..08782333 100644 --- a/Sources/MarkdownUI/Theme/BlockStyle/TableBorderStyle.swift +++ b/Sources/MarkdownUI/Theme/BlockStyle/TableBorderStyle.swift @@ -31,15 +31,37 @@ import SwiftUI /// /// ![](CustomTableBorders) public struct TableBorderStyle { - /// The visible table borders. - public var visibleBorders: TableBorderSelector + public struct Border { + /// The visible table borders. + public var visibleBorders: TableBorderSelector - /// The table border color. - public var color: Color + /// The table border color. + public var color: Color + + public init(visibleBorders: TableBorderSelector, color: Color) { + self.visibleBorders = visibleBorders + self.color = color + } + } + + /// The table's list of borders + public var borders: [Border] /// The table border stroke style. public var strokeStyle: StrokeStyle + /// Creates a table border style with the given borders and stroke style. + /// - Parameters: + /// - borders: The visible table borders. + /// - strokeStyle: The table border stroke style. + public init( + _ borders: [Border], + strokeStyle: StrokeStyle + ) { + self.borders = borders + self.strokeStyle = strokeStyle + } + /// Creates a table border style with the given visible borders, color, and stroke style. /// - Parameters: /// - visibleBorders: The visible table borders. @@ -50,8 +72,7 @@ public struct TableBorderStyle { color: Color, strokeStyle: StrokeStyle ) { - self.visibleBorders = visibleBorders - self.color = color + self.borders = [.init(visibleBorders: visibleBorders, color: color)] self.strokeStyle = strokeStyle } diff --git a/Sources/MarkdownUI/Views/Blocks/TableBorderSelector.swift b/Sources/MarkdownUI/Views/Blocks/TableBorderSelector.swift index 9b85d8a0..ccdf5109 100644 --- a/Sources/MarkdownUI/Views/Blocks/TableBorderSelector.swift +++ b/Sources/MarkdownUI/Views/Blocks/TableBorderSelector.swift @@ -57,6 +57,78 @@ extension TableBorderSelector { } } + /// A table border selector that selects the inside borders of a table's first row. + public static var insideBordersFirstRow: TableBorderSelector { + TableBorderSelector { tableBounds, borderWidth in + guard tableBounds.rowCount > 0 else { return [] } + let firstRowBounds = tableBounds.bounds(forRow: 0) + + return [ + CGRect( + origin: .init(x: firstRowBounds.minX, y: firstRowBounds.maxY - borderWidth), + size: .init(width: firstRowBounds.width, height: borderWidth) + ) + ] + (0.. 1 else { return [] } + return (1.. 1 else { return [] } + let firstRowBounds = tableBounds.bounds(forRow: 0) + return (0..