Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for footnotes #14

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Node: CustomStringConvertible {
public init?(markdown: String) {
core_extensions_ensure_registered()

guard let parser = cmark_parser_new(0) else { return nil }
guard let parser = cmark_parser_new(CMARK_OPT_FOOTNOTES) else { return nil }
defer { cmark_parser_free(parser) }

if let ext = cmark_find_syntax_extension("table") {
Expand Down
23 changes: 22 additions & 1 deletion cmark_gfm_swiftTests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Tests: XCTestCase {
let blocks = rootNode.elements
XCTAssertEqual(blocks.count, 1)
}

func testMarkdownCodeBlock() {
let markdown = """
```swift
Expand Down Expand Up @@ -368,6 +368,27 @@ class Tests: XCTestCase {
XCTAssertEqual(cells[1].string, "bim")
}

func testFootnotes() {
let markdown = """
Lorem ipsum[^1]
[^1]: Test footnote
"""
let html = Node(markdown: markdown)!.html
let expected = """
<p>Lorem ipsum<sup class="footnote-ref"><a href="#fn1" id="fnref1">1</a></sup></p>
<section class="footnotes">
<ol>
<li id="fn1">
<p>Test footnote <a href="#fnref1" class="footnote-backref">↩</a></p>
</li>
</ol>
</section>

"""
XCTAssertEqual(html, expected)

}

func testEmailNotAMention() {
let markdown = "me@google"
let node = Node(markdown: markdown)!
Expand Down