diff options
Diffstat (limited to 'Sources/NorgKit/Models/InlineStyle.swift')
| -rw-r--r-- | Sources/NorgKit/Models/InlineStyle.swift | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Sources/NorgKit/Models/InlineStyle.swift b/Sources/NorgKit/Models/InlineStyle.swift new file mode 100644 index 0000000..807de7b --- /dev/null +++ b/Sources/NorgKit/Models/InlineStyle.swift @@ -0,0 +1,28 @@ +/// Composable inline styles that may be applied to a single run of text. +public struct InlineStyle: OptionSet, Hashable, Sendable, Codable { + public let rawValue: Int + + public init(rawValue: Int) { + self.rawValue = rawValue + } + + public static let bold = InlineStyle(rawValue: 1 << 0) + public static let italic = InlineStyle(rawValue: 1 << 1) + public static let underline = InlineStyle(rawValue: 1 << 2) + public static let strikethrough = InlineStyle(rawValue: 1 << 3) + public static let verbatim = InlineStyle(rawValue: 1 << 4) + public static let superscript = InlineStyle(rawValue: 1 << 5) + public static let `subscript` = InlineStyle(rawValue: 1 << 6) + public static let spoiler = InlineStyle(rawValue: 1 << 7) + public static let math = InlineStyle(rawValue: 1 << 8) + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.init(rawValue: try container.decode(Int.self)) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(rawValue) + } +} |