Skip to content

Commit 96f6980

Browse files
authored
Merge pull request swiftlang#225 from google/update-cmark
Update cmark submodule to latest version.
2 parents a2a2796 + e6a6d7c commit 96f6980

10 files changed

+118
-116
lines changed

Diff for: Package.swift

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ let package = Package(
3333
// We must exclude main.c or SwiftPM will treat this target as an executable target instead
3434
// of a library, and we won't be able to import it from the CommonMark Swift module.
3535
"cmark/src/main.c",
36+
"cmark/test",
3637
]
3738
),
3839
.target(name: "CommonMark", dependencies: ["CCommonMark"]),

Diff for: Sources/CCommonMark/cmark

Submodule cmark updated from d875488 to 32fa496

Diff for: Sources/CommonMark/CMarkInterop.swift

+21-21
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,12 @@ fileprivate func makeNode(from cNode: OpaquePointer) -> MarkdownNode {
4343
node = EmphasisNode(
4444
children: makeNodes(fromChildrenOf: cNode) as! [InlineContent],
4545
sourceRange: sourceRange)
46-
case CMARK_NODE_HEADER:
47-
node = HeaderNode(
48-
level: HeaderNode.Level(rawValue: numericCast(cmark_node_get_header_level(cNode)))!,
46+
case CMARK_NODE_HEADING:
47+
node = HeadingNode(
48+
level: HeadingNode.Level(rawValue: numericCast(cmark_node_get_heading_level(cNode)))!,
4949
children: makeNodes(fromChildrenOf: cNode) as! [InlineContent],
5050
sourceRange: sourceRange)
51-
case CMARK_NODE_HRULE:
52-
node = HorizontalRuleNode(sourceRange: sourceRange)
53-
case CMARK_NODE_HTML:
51+
case CMARK_NODE_HTML_BLOCK:
5452
node = HTMLBlockNode(
5553
literalContent: String(cString: cmark_node_get_literal(cNode)),
5654
sourceRange: sourceRange)
@@ -60,7 +58,7 @@ fileprivate func makeNode(from cNode: OpaquePointer) -> MarkdownNode {
6058
title: String(cString: cmark_node_get_title(cNode)),
6159
children: makeNodes(fromChildrenOf: cNode) as! [InlineContent],
6260
sourceRange: sourceRange)
63-
case CMARK_NODE_INLINE_HTML:
61+
case CMARK_NODE_HTML_INLINE:
6462
node = InlineHTMLNode(
6563
literalContent: String(cString: cmark_node_get_literal(cNode)),
6664
sourceRange: sourceRange)
@@ -106,6 +104,8 @@ fileprivate func makeNode(from cNode: OpaquePointer) -> MarkdownNode {
106104
node = TextNode(
107105
literalContent: String(cString: cmark_node_get_literal(cNode)),
108106
sourceRange: sourceRange)
107+
case CMARK_NODE_THEMATIC_BREAK:
108+
node = ThematicBreakNode(sourceRange: sourceRange)
109109
default:
110110
fatalError("Unexpected node type \(type) encountered")
111111
}
@@ -180,8 +180,7 @@ extension PrimitiveNode: CMarkNodeConvertible {
180180
case .codeBlock(let node): return node.makeCNode()
181181
case .document(let node): return node.makeCNode()
182182
case .emphasis(let node): return node.makeCNode()
183-
case .header(let node): return node.makeCNode()
184-
case .horizontalRule(let node): return node.makeCNode()
183+
case .heading(let node): return node.makeCNode()
185184
case .htmlBlock(let node): return node.makeCNode()
186185
case .image(let node): return node.makeCNode()
187186
case .inlineCode(let node): return node.makeCNode()
@@ -194,6 +193,7 @@ extension PrimitiveNode: CMarkNodeConvertible {
194193
case .softBreak(let node): return node.makeCNode()
195194
case .strong(let node): return node.makeCNode()
196195
case .text(let node): return node.makeCNode()
196+
case .thematicBreak(let node): return node.makeCNode()
197197
}
198198
}
199199
}
@@ -233,31 +233,24 @@ extension EmphasisNode: CMarkNodeConvertible {
233233
extension HTMLBlockNode: CMarkNodeConvertible {
234234

235235
func makeCNode() -> OpaquePointer {
236-
let cNode = cmark_node_new(CMARK_NODE_HTML)!
236+
let cNode = cmark_node_new(CMARK_NODE_HTML_BLOCK)!
237237
cmark_node_set_literal(cNode, literalContent)
238238
return cNode
239239
}
240240
}
241241

242-
extension HeaderNode: CMarkNodeConvertible {
242+
extension HeadingNode: CMarkNodeConvertible {
243243

244244
func makeCNode() -> OpaquePointer {
245-
let cNode = cmark_node_new(CMARK_NODE_HEADER)!
246-
cmark_node_set_header_level(cNode, numericCast(level.rawValue))
245+
let cNode = cmark_node_new(CMARK_NODE_HEADING)!
246+
cmark_node_set_heading_level(cNode, numericCast(level.rawValue))
247247
for child in children {
248248
cmark_node_append_child(cNode, child.primitiveRepresentation.makeCNode())
249249
}
250250
return cNode
251251
}
252252
}
253253

254-
extension HorizontalRuleNode: CMarkNodeConvertible {
255-
256-
func makeCNode() -> OpaquePointer {
257-
return cmark_node_new(CMARK_NODE_HRULE)!
258-
}
259-
}
260-
261254
extension ImageNode: CMarkNodeConvertible {
262255

263256
func makeCNode() -> OpaquePointer {
@@ -283,7 +276,7 @@ extension InlineCodeNode: CMarkNodeConvertible {
283276
extension InlineHTMLNode: CMarkNodeConvertible {
284277

285278
func makeCNode() -> OpaquePointer {
286-
let cNode = cmark_node_new(CMARK_NODE_INLINE_HTML)!
279+
let cNode = cmark_node_new(CMARK_NODE_HTML_INLINE)!
287280
cmark_node_set_literal(cNode, literalContent)
288281
return cNode
289282
}
@@ -388,3 +381,10 @@ extension TextNode: CMarkNodeConvertible {
388381
return cNode
389382
}
390383
}
384+
385+
extension ThematicBreakNode: CMarkNodeConvertible {
386+
387+
func makeCNode() -> OpaquePointer {
388+
return cmark_node_new(CMARK_NODE_THEMATIC_BREAK)!
389+
}
390+
}

Diff for: Sources/CommonMark/HeaderNode.swift renamed to Sources/CommonMark/HeadingNode.swift

+14-14
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// A block element that represents a section header.
14-
public struct HeaderNode: BlockContent {
13+
/// A block element that represents a section heading.
14+
public struct HeadingNode: BlockContent {
1515

16-
/// The level of a header, which describes its position in the hierarchy of a document and the
17-
/// size at which the header is rendered.
16+
/// The level of a heading, which describes its position in the hierarchy of a document and the
17+
/// size at which the heading is rendered.
1818
public enum Level: Int {
1919
case h1 = 1
2020
case h2 = 2
@@ -24,20 +24,20 @@ public struct HeaderNode: BlockContent {
2424
case h6 = 6
2525
}
2626

27-
/// The level of the header.
27+
/// The level of the heading.
2828
public let level: Level
2929

3030
/// The children of the receiver.
3131
public let children: [InlineContent]
3232

3333
public let sourceRange: Range<SourceLocation>?
3434

35-
public var primitiveRepresentation: PrimitiveNode { return .header(self) }
35+
public var primitiveRepresentation: PrimitiveNode { return .heading(self) }
3636

37-
/// Creates a new header node.
37+
/// Creates a new heading node.
3838
///
3939
/// - Parameters:
40-
/// - level: The level of the header. If omitted, `.h1` is used.
40+
/// - level: The level of the heading. If omitted, `.h1` is used.
4141
/// - children: Inline content nodes that are children of the new node.
4242
/// - sourceRange: The source range from which the node was parsed, if known.
4343
public init(
@@ -55,25 +55,25 @@ public struct HeaderNode: BlockContent {
5555
///
5656
/// - Parameter level: The new level.
5757
/// - Returns: The new node.
58-
public func replacingLevel(_ level: Level) -> HeaderNode {
59-
return HeaderNode(level: level, children: children, sourceRange: sourceRange)
58+
public func replacingLevel(_ level: Level) -> HeadingNode {
59+
return HeadingNode(level: level, children: children, sourceRange: sourceRange)
6060
}
6161

6262
/// Returns a new node equivalent to the receiver, but whose children have been replaced with the
6363
/// given list of nodes.
6464
///
6565
/// - Parameter children: The new list of children.
6666
/// - Returns: The new node.
67-
public func replacingChildren(_ children: [InlineContent]) -> HeaderNode {
68-
return HeaderNode(level: level, children: children, sourceRange: sourceRange)
67+
public func replacingChildren(_ children: [InlineContent]) -> HeadingNode {
68+
return HeadingNode(level: level, children: children, sourceRange: sourceRange)
6969
}
7070

7171
/// Returns a new node equivalent to the receiver, but whose source range has been replaced with
7272
/// the given value.
7373
///
7474
/// - Parameter sourceRange: The new source range.
7575
/// - Returns: The new node.
76-
public func replacingSourceRange(_ sourceRange: Range<SourceLocation>?) -> HeaderNode {
77-
return HeaderNode(children: children, sourceRange: sourceRange)
76+
public func replacingSourceRange(_ sourceRange: Range<SourceLocation>?) -> HeadingNode {
77+
return HeadingNode(children: children, sourceRange: sourceRange)
7878
}
7979
}

Diff for: Sources/CommonMark/MarkdownRewriter.swift

+14-14
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ open class MarkdownRewriter {
3636
case let castNode as CodeBlockNode: return visit(castNode)
3737
case let castNode as EmphasisNode: return visit(castNode)
3838
case let castNode as HTMLBlockNode: return visit(castNode)
39-
case let castNode as HeaderNode: return visit(castNode)
40-
case let castNode as HorizontalRuleNode: return visit(castNode)
39+
case let castNode as HeadingNode: return visit(castNode)
4140
case let castNode as ImageNode: return visit(castNode)
4241
case let castNode as InlineCodeNode: return visit(castNode)
4342
case let castNode as InlineHTMLNode: return visit(castNode)
@@ -50,6 +49,7 @@ open class MarkdownRewriter {
5049
case let castNode as SoftBreakNode: return visit(castNode)
5150
case let castNode as StrongNode: return visit(castNode)
5251
case let castNode as TextNode: return visit(castNode)
52+
case let castNode as ThematicBreakNode: return visit(castNode)
5353
case let castNode as BlockContent: return visit(extension: castNode)
5454
case let castNode as InlineContent: return visit(extension: castNode)
5555
default:
@@ -121,28 +121,18 @@ open class MarkdownRewriter {
121121
return node
122122
}
123123

124-
/// Called when a `HeaderNode` is visited, replacing it in the AST with the returned node.
124+
/// Called when a `HeadingNode` is visited, replacing it in the AST with the returned node.
125125
///
126126
/// The base class implementation of this method automatically visits the children of the node and
127127
/// returns a node whose children have been replaced by the results of that visitation. If you
128128
/// override it, you must call `super.visit(node)` if you wish to visit the children as well.
129129
///
130130
/// - Parameter node: The node being visited.
131131
/// - Returns: The node that should replace the given node in the AST.
132-
open func visit(_ node: HeaderNode) -> BlockContent {
132+
open func visit(_ node: HeadingNode) -> BlockContent {
133133
return node.replacingChildren(visitAll(node.children))
134134
}
135135

136-
/// Called when a `HorizontalRuleNode` is visited, replacing it in the AST with the returned node.
137-
///
138-
/// The base class implementation of this method simply returns the same node.
139-
///
140-
/// - Parameter node: The node being visited.
141-
/// - Returns: The node that should replace the given node in the AST.
142-
open func visit(_ node: HorizontalRuleNode) -> BlockContent {
143-
return node
144-
}
145-
146136
/// Called when a `ImageNode` is visited, replacing it in the AST with the returned node.
147137
///
148138
/// The base class implementation of this method automatically visits the children of the node and
@@ -277,6 +267,16 @@ open class MarkdownRewriter {
277267
return node
278268
}
279269

270+
/// Called when a `ThematicBreakNode` is visited, replacing it in the AST with the returned node.
271+
///
272+
/// The base class implementation of this method simply returns the same node.
273+
///
274+
/// - Parameter node: The node being visited.
275+
/// - Returns: The node that should replace the given node in the AST.
276+
open func visit(_ node: ThematicBreakNode) -> BlockContent {
277+
return node
278+
}
279+
280280
/// Visits a custom block extension node, replacing it in the AST with the returned node.
281281
///
282282
/// If you have defined custom extension nodes and use them in your AST, then this method will be

Diff for: Sources/CommonMark/MarkdownVisitor.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ open class MarkdownVisitor {
3333
case let castNode as CodeBlockNode: visit(castNode)
3434
case let castNode as EmphasisNode: visit(castNode)
3535
case let castNode as HTMLBlockNode: visit(castNode)
36-
case let castNode as HeaderNode: visit(castNode)
37-
case let castNode as HorizontalRuleNode: visit(castNode)
36+
case let castNode as HeadingNode: visit(castNode)
3837
case let castNode as ImageNode: visit(castNode)
3938
case let castNode as InlineCodeNode: visit(castNode)
4039
case let castNode as InlineHTMLNode: visit(castNode)
@@ -47,6 +46,7 @@ open class MarkdownVisitor {
4746
case let castNode as SoftBreakNode: visit(castNode)
4847
case let castNode as StrongNode: visit(castNode)
4948
case let castNode as TextNode: visit(castNode)
49+
case let castNode as ThematicBreakNode: visit(castNode)
5050
default: visit(extension: node)
5151
}
5252
afterVisit(node)
@@ -104,23 +104,16 @@ open class MarkdownVisitor {
104104
/// - Parameter node: The node being visited.
105105
open func visit(_ node: HTMLBlockNode) {}
106106

107-
/// Called when a `HeaderNode` is visited.
107+
/// Called when a `HeadingNode` is visited.
108108
///
109109
/// The base class implementation of this method automatically visits the children of the node. If
110110
/// you override it, you must call `super.visit(node)` if you wish to visit the children as well.
111111
///
112112
/// - Parameter node: The node being visited.
113-
open func visit(_ node: HeaderNode) {
113+
open func visit(_ node: HeadingNode) {
114114
visitAll(node.children)
115115
}
116116

117-
/// Called when a `HorizontalRuleNode` is visited.
118-
///
119-
/// The base class implementation of this method does nothing.
120-
///
121-
/// - Parameter node: The node being visited.
122-
open func visit(_ node: HorizontalRuleNode) {}
123-
124117
/// Called when a `ImageNode` is visited.
125118
///
126119
/// The base class implementation of this method automatically visits the children of the node. If
@@ -226,6 +219,13 @@ open class MarkdownVisitor {
226219
/// - Parameter node: The node being visited.
227220
open func visit(_ node: TextNode) {}
228221

222+
/// Called when a `ThematicBreakNode` is visited.
223+
///
224+
/// The base class implementation of this method does nothing.
225+
///
226+
/// - Parameter node: The node being visited.
227+
open func visit(_ node: ThematicBreakNode) {}
228+
229229
/// Visits a custom extension node.
230230
///
231231
/// If you have defined custom extension nodes and use them in your AST, then this method will be

Diff for: Sources/CommonMark/PrimitiveNode.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ public enum PrimitiveNode {
3131

3232
case emphasis(EmphasisNode)
3333

34-
case header(HeaderNode)
35-
36-
case horizontalRule(HorizontalRuleNode)
34+
case heading(HeadingNode)
3735

3836
case htmlBlock(HTMLBlockNode)
3937

@@ -58,4 +56,6 @@ public enum PrimitiveNode {
5856
case strong(StrongNode)
5957

6058
case text(TextNode)
59+
60+
case thematicBreak(ThematicBreakNode)
6161
}

Diff for: Sources/CommonMark/HorizontalRuleNode.swift renamed to Sources/CommonMark/ThematicBreakNode.swift

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// A block element that represents a horizontal rule.
14-
public struct HorizontalRuleNode: BlockContent {
13+
/// A block element that represents a thematic break between large ranges of Markdown content (which
14+
/// is typically rendered as a horizontal rule).
15+
public struct ThematicBreakNode: BlockContent {
1516

1617
public let sourceRange: Range<SourceLocation>?
1718

18-
public var primitiveRepresentation: PrimitiveNode { return .horizontalRule(self) }
19+
public var primitiveRepresentation: PrimitiveNode { return .thematicBreak(self) }
1920

20-
/// Creates a new horizontal rule node.
21+
/// Creates a new thematic break node.
2122
///
2223
/// - Parameter sourceRange: The source range from which the node was parsed, if known.
2324
public init(sourceRange: Range<SourceLocation>? = nil) {
@@ -29,7 +30,7 @@ public struct HorizontalRuleNode: BlockContent {
2930
///
3031
/// - Parameter sourceRange: The new source range.
3132
/// - Returns: The new node.
32-
public func replacingSourceRange(_ sourceRange: Range<SourceLocation>?) -> HorizontalRuleNode {
33-
return HorizontalRuleNode(sourceRange: sourceRange)
33+
public func replacingSourceRange(_ sourceRange: Range<SourceLocation>?) -> ThematicBreakNode {
34+
return ThematicBreakNode(sourceRange: sourceRange)
3435
}
3536
}

0 commit comments

Comments
 (0)