Skip to content

Commit 3cc84a6

Browse files
committed
Allow separate strong emphasis marker
1 parent 90a8e2e commit 3cc84a6

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
@@ -248,6 +248,7 @@ public struct MarkupFormatter: MarkupWalker {
248248
var thematicBreakCharacter: ThematicBreakCharacter
249249
var thematicBreakLength: UInt
250250
var emphasisMarker: EmphasisMarker
251+
var strongEmphasisMarker: EmphasisMarker
251252
var condenseAutolinks: Bool
252253
var preferredHeadingStyle: PreferredHeadingStyle
253254
var preferredLineLimit: PreferredLineLimit?
@@ -264,7 +265,8 @@ public struct MarkupFormatter: MarkupWalker {
264265
- defaultCodeBlockLanguage: The default language string to use when code blocks don't have a language and will be printed as fenced code blocks.
265266
- thematicBreakCharacter: The character to use for thematic breaks.
266267
- thematicBreakLength: The length of printed thematic breaks.
267-
- emphasisMarker: The character to use for emphasis and strong emphasis markers.
268+
- emphasisMarker: The character to use for emphasis markers.
269+
- strongEmphasisMarker: The character to use for strong emphasis markers.
268270
- condenseAutolinks: Print links whose link text and destination match as autolinks, e.g. `<https://swift.org>`.
269271
- preferredHeadingStyle: The preferred heading style.
270272
- lineLimit: The preferred maximum line length and method for splitting ``Text`` elements in an attempt to maintain that line length.
@@ -277,6 +279,7 @@ public struct MarkupFormatter: MarkupWalker {
277279
thematicBreakCharacter: ThematicBreakCharacter = .dash,
278280
thematicBreakLength: UInt = 5,
279281
emphasisMarker: EmphasisMarker = .star,
282+
strongEmphasisMarker: EmphasisMarker = .star,
280283
condenseAutolinks: Bool = true,
281284
preferredHeadingStyle: PreferredHeadingStyle = .atx,
282285
preferredLineLimit: PreferredLineLimit? = nil,
@@ -288,6 +291,7 @@ public struct MarkupFormatter: MarkupWalker {
288291
self.defaultCodeBlockLanguage = defaultCodeBlockLanguage
289292
self.thematicBreakCharacter = thematicBreakCharacter
290293
self.emphasisMarker = emphasisMarker
294+
self.strongEmphasisMarker = strongEmphasisMarker
291295
self.condenseAutolinks = condenseAutolinks
292296
self.preferredHeadingStyle = preferredHeadingStyle
293297
self.preferredLineLimit = preferredLineLimit
@@ -862,9 +866,9 @@ public struct MarkupFormatter: MarkupWalker {
862866
}
863867

864868
public mutating func visitStrong(_ strong: Strong) {
865-
print(String(repeating: formattingOptions.emphasisMarker.rawValue, count: 2), for: strong)
869+
print(String(repeating: formattingOptions.strongEmphasisMarker.rawValue, count: 2), for: strong)
866870
descendInto(strong)
867-
print(String(repeating: formattingOptions.emphasisMarker.rawValue, count: 2), for: strong)
871+
print(String(repeating: formattingOptions.strongEmphasisMarker.rawValue, count: 2), for: strong)
868872
}
869873

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

Tests/MarkdownTests/Visitors/MarkupFormatterTests.swift

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

534534
do {
535535
let document = Document(parsing: underline)
536-
let printed = document.format(options: .init(emphasisMarker: .star))
536+
let printed = document.format(options: .init(strongEmphasisMarker: .star))
537537
XCTAssertEqual(star, printed)
538538
}
539539

540540
do {
541541
let document = Document(parsing: star)
542-
let printed = document.format(options: .init(emphasisMarker: .underline))
542+
let printed = document.format(options: .init(strongEmphasisMarker: .underline))
543543
XCTAssertEqual(underline, printed)
544544
}
545545

Tools/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

@@ -206,6 +209,10 @@ extension MarkdownCommand {
206209
throw ArgumentParser.ValidationError("The value '\(self.emphasisMarker)' is invalid for '--emphasis-marker'")
207210
}
208211

212+
guard let strongEmphasisMarker = MarkupFormatter.Options.EmphasisMarker(argument: strongEmphasisMarker) else {
213+
throw ArgumentParser.ValidationError("The value '\(self.strongEmphasisMarker)' is invalid for '--strong-emphasis-marker'")
214+
}
215+
209216
guard let unorderedListMarker = MarkupFormatter.Options.UnorderedListMarker(argument: unorderedListMarker) else {
210217
throw ArgumentParser.ValidationError("The value '\(self.unorderedListMarker)' is invalid for '--unordered-list-marker'")
211218
}
@@ -229,6 +236,7 @@ extension MarkdownCommand {
229236
thematicBreakCharacter: thematicBreakCharacter,
230237
thematicBreakLength: thematicBreakLength,
231238
emphasisMarker: emphasisMarker,
239+
strongEmphasisMarker: strongEmphasisMarker,
232240
condenseAutolinks: condenseAutolinks,
233241
preferredHeadingStyle: preferredHeadingStyle,
234242
preferredLineLimit: preferredLineLimit,

0 commit comments

Comments
 (0)