Skip to content

Commit c36c140

Browse files
committed
Allow separate strong emphasis marker
1 parent 3b0f6f9 commit c36c140

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Sources/Markdown/Walker/Walkers/MarkupFormatter.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ public struct MarkupFormatter: MarkupWalker {
239239
var thematicBreakCharacter: ThematicBreakCharacter
240240
var thematicBreakLength: UInt
241241
var emphasisMarker: EmphasisMarker
242+
var strongEmphasisMarker: EmphasisMarker
242243
var condenseAutolinks: Bool
243244
var preferredHeadingStyle: PreferredHeadingStyle
244245
var preferredLineLimit: PreferredLineLimit?
@@ -254,7 +255,8 @@ public struct MarkupFormatter: MarkupWalker {
254255
- defaultCodeBlockLanguage: The default language string to use when code blocks don't have a language and will be printed as fenced code blocks.
255256
- thematicBreakCharacter: The character to use for thematic breaks.
256257
- thematicBreakLength: The length of printed thematic breaks.
257-
- emphasisMarker: The character to use for emphasis and strong emphasis markers.
258+
- emphasisMarker: The character to use for emphasis markers.
259+
- strongEmphasisMarker: The character to use for strong emphasis markers.
258260
- condenseAutolinks: Print links whose link text and destination match as autolinks, e.g. `<https://swift.org>`.
259261
- preferredHeadingStyle: The preferred heading style.
260262
- lineLimit: The preferred maximum line length and method for splitting ``Text`` elements in an attempt to maintain that line length.
@@ -267,6 +269,7 @@ public struct MarkupFormatter: MarkupWalker {
267269
thematicBreakCharacter: ThematicBreakCharacter = .dash,
268270
thematicBreakLength: UInt = 5,
269271
emphasisMarker: EmphasisMarker = .star,
272+
strongEmphasisMarker: EmphasisMarker = .star,
270273
condenseAutolinks: Bool = true,
271274
preferredHeadingStyle: PreferredHeadingStyle = .atx,
272275
preferredLineLimit: PreferredLineLimit? = nil,
@@ -277,6 +280,7 @@ public struct MarkupFormatter: MarkupWalker {
277280
self.defaultCodeBlockLanguage = defaultCodeBlockLanguage
278281
self.thematicBreakCharacter = thematicBreakCharacter
279282
self.emphasisMarker = emphasisMarker
283+
self.strongEmphasisMarker = strongEmphasisMarker
280284
self.condenseAutolinks = condenseAutolinks
281285
self.preferredHeadingStyle = preferredHeadingStyle
282286
self.preferredLineLimit = preferredLineLimit
@@ -841,9 +845,9 @@ public struct MarkupFormatter: MarkupWalker {
841845
}
842846

843847
public mutating func visitStrong(_ strong: Strong) {
844-
print(String(repeating: formattingOptions.emphasisMarker.rawValue, count: 2), for: strong)
848+
print(String(repeating: formattingOptions.strongEmphasisMarker.rawValue, count: 2), for: strong)
845849
descendInto(strong)
846-
print(String(repeating: formattingOptions.emphasisMarker.rawValue, count: 2), for: strong)
850+
print(String(repeating: formattingOptions.strongEmphasisMarker.rawValue, count: 2), for: strong)
847851
}
848852

849853
public mutating func visitText(_ text: Text) {

Sources/markdown-tool/Commands/FormatCommand.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ extension MarkdownCommand {
9696
@Option(help: "Emphasis marker; choices: \(MarkupFormatter.Options.EmphasisMarker.allCases.map { $0.rawValue }.joined(separator: ", "))")
9797
var emphasisMarker: String = "*"
9898

99+
@Option(help: "Strong emphasis marker; choices: \(MarkupFormatter.Options.EmphasisMarker.allCases.map { $0.rawValue }.joined(separator: ", "))")
100+
var strongEmphasisMarker: String = "*"
101+
99102
@Flag(inversion: .prefixedNo, exclusivity: .chooseLast, help: "Condense links whose text matches their destination to 'autolinks' e.g. <https://swift.org>")
100103
var condenseAutolinks: Bool = true
101104

@@ -208,6 +211,10 @@ extension MarkdownCommand {
208211
throw ArgumentParser.ValidationError("The value '\(self.emphasisMarker)' is invalid for '--emphasis-marker'")
209212
}
210213

214+
guard let strongEmphasisMarker = MarkupFormatter.Options.EmphasisMarker(argument: strongEmphasisMarker) else {
215+
throw ArgumentParser.ValidationError("The value '\(self.strongEmphasisMarker)' is invalid for '--strong-emphasis-marker'")
216+
}
217+
211218
guard let unorderedListMarker = MarkupFormatter.Options.UnorderedListMarker(argument: unorderedListMarker) else {
212219
throw ArgumentParser.ValidationError("The value '\(self.emphasisMarker)' is invalid for '--unordered-list-marker'")
213220
}
@@ -231,6 +238,7 @@ extension MarkdownCommand {
231238
thematicBreakCharacter: thematicBreakCharacter,
232239
thematicBreakLength: thematicBreakLength,
233240
emphasisMarker: emphasisMarker,
241+
strongEmphasisMarker: strongEmphasisMarker,
234242
condenseAutolinks: condenseAutolinks,
235243
preferredHeadingStyle: preferredHeadingStyle,
236244
preferredLineLimit: preferredLineLimit,

Tests/MarkdownTests/Visitors/MarkupFormatterTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,13 @@ class MarkupFormatterOptionsTests: XCTestCase {
433433

434434
do {
435435
let document = Document(parsing: underline)
436-
let printed = document.format(options: .init(emphasisMarker: .star))
436+
let printed = document.format(options: .init(strongEmphasisMarker: .star))
437437
XCTAssertEqual(star, printed)
438438
}
439439

440440
do {
441441
let document = Document(parsing: star)
442-
let printed = document.format(options: .init(emphasisMarker: .underline))
442+
let printed = document.format(options: .init(strongEmphasisMarker: .underline))
443443
XCTAssertEqual(underline, printed)
444444
}
445445

0 commit comments

Comments
 (0)