Skip to content

Commit da0ec2f

Browse files
committed
Fixed for updated emphasis rule.
1 parent f5f10af commit da0ec2f

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

CommonMarkdown/CommonMarkdown/InlineParser.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,23 +317,31 @@ class InlineParser {
317317

318318
while true {
319319
var (closeDelimiterCount, _, canClose) = scanDelims(text, character)
320-
if closeDelimiterCount >= 1 && closeDelimiterCount <= 3 && canClose && (firstClose == nil || closeDelimiterCount != firstClose.delimiterCount) {
321-
if closeDelimiterCount == 3 {
322-
// If we opened with ***, then we interpret *** as * followed by **
323-
// giving us <strong><em>
324-
closeDelimiterCount = 1
325-
}
326-
text.skip(closeDelimiterCount)
320+
if canClose && (firstClose == nil || closeDelimiterCount != firstClose.delimiterCount) {
327321

328322
if firstClose != nil { // if we've already passed the first closer:
329323

324+
if closeDelimiterCount > 3 - firstClose.delimiterCount {
325+
closeDelimiterCount = 3 - firstClose.delimiterCount
326+
}
327+
text.skip(closeDelimiterCount)
328+
330329
let deepInlines = Array(inlines[delimiterPosition+1..<firstClose.position])
331330
let shallowInlines = Array(inlines[firstClose.position+1..<inlines.endIndex])
332331
let subinlines = [firstClose.delimiterCount == 1 ? .Emphasis(deepInlines) : .Strong(deepInlines)] + shallowInlines
333332
inlines[delimiterPosition] = firstClose.delimiterCount == 1 ? .Strong(subinlines) : .Emphasis(subinlines)
334333
inlines.removeRange(delimiterPosition+1..<inlines.endIndex)
335334
break
336-
} else { // this is the first closer; for now, add literal string;
335+
} else {
336+
337+
if closeDelimiterCount == 3 {
338+
// If we opened with ***, then we interpret *** as * followed by **
339+
// giving us <strong><em>
340+
closeDelimiterCount = 1
341+
}
342+
text.skip(closeDelimiterCount)
343+
344+
// this is the first closer; for now, add literal string;
337345
// we'll change this when he hit the second closer
338346
inlines.append(.Str(text.prev(closeDelimiterCount)))
339347
firstClose = (inlines.endIndex - 1, closeDelimiterCount)

0 commit comments

Comments
 (0)