Skip to content

Commit

Permalink
refactor: reuse the functions inside the computed properties
Browse files Browse the repository at this point in the history
  • Loading branch information
MojtabaHs committed Oct 14, 2024
1 parent 1d85283 commit 297674a
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions Sources/MarkdownUI/Theme/BlockStyle/ListMarkerConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,37 @@ public struct ListMarkerConfiguration {
extension BlockStyle where Configuration == ListMarkerConfiguration {
/// A list marker style that uses decimal numbers beginning with 1.
public static var decimal: Self {
BlockStyle { configuration in
Text("\(configuration.itemNumber).")
.monospacedDigit()
.relativeFrame(minWidth: .em(1.5), alignment: .trailing)
}
decimal(minWidth: .em(1.5), alignment: .trailing)
}

/// A list marker style that uses uppercase roman numerals beginning with `I`.
public static var upperRoman: Self {
BlockStyle { configuration in
Text(configuration.itemNumber.roman + ".")
.relativeFrame(minWidth: .em(1.5), alignment: .trailing)
}
upperRoman(minWidth: .em(1.5), alignment: .trailing)
}

/// A list marker style that uses lowercase roman numerals beginning with `i`.
public static var lowerRoman: Self {
BlockStyle { configuration in
Text(configuration.itemNumber.roman.lowercased() + ".")
.relativeFrame(minWidth: .em(1.5), alignment: .trailing)
}
lowerRoman(minWidth: .em(1.5), alignment: .trailing)
}

/// A list marker style that uses a dash.
public static var dash: Self {
BlockStyle { _ in
Text("-")
.relativeFrame(minWidth: .em(1.5), alignment: .trailing)
}
dash(minWidth: .em(1.5), alignment: .trailing)
}

/// A list marker style that uses a filled circle.
public static var disc: Self {
BlockStyle { _ in
ListBullet.disc
.relativeFrame(minWidth: .em(1.5), alignment: .trailing)
}
disc(minWidth: .em(1.5), alignment: .trailing)
}

/// A list marker style that uses a hollow circle.
public static var circle: Self {
BlockStyle { _ in
ListBullet.circle
.relativeFrame(minWidth: .em(1.5), alignment: .trailing)
}
circle(minWidth: .em(1.5), alignment: .trailing)
}

/// A list marker style that uses a filled square.
public static var square: Self {
BlockStyle { _ in
ListBullet.square
.relativeFrame(minWidth: .em(1.5), alignment: .trailing)
}
square(minWidth: .em(1.5), alignment: .trailing)
}

/// A list marker style that alternates between disc, circle, and square, depending on the list level.
Expand All @@ -78,6 +56,7 @@ extension BlockStyle where Configuration == ListMarkerConfiguration {
.makeBody(configuration: configuration)
}
}
}

// MARK: Dynamic

Expand Down

0 comments on commit 297674a

Please sign in to comment.