-
Notifications
You must be signed in to change notification settings - Fork 220
Add link title support for commonmark #140
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
Conversation
|
||
XCTAssertEqual(try XCTUnwrap(linkWithoutTitle.child(at: 0) as? Text).string, "Example2") | ||
XCTAssertEqual(linkWithoutTitle.destination, "example2.com") | ||
XCTAssertEqual(linkWithoutTitle.title, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I expect this to be
XCTAssertEqual(linkWithoutTitle.title, "") | |
XCTAssertEqual(linkWithoutTitle.title, nil) |
But that's how destination
and title
is computed.
cmark_node_get_title
andcmark_node_get_url
will usecmark_chunk_to_cstr
which will produce an empty string for a nil input.
We can fix it by updating the getter logic on Link.title
. The question is should we update the destination's getter accordingly? If so, it may break the downstream since it was a public symbol.
/// The link's title.
var title: String? {
get {
guard case let .link(_, title) = _data.raw.markup.data else {
fatalError("\(self) markup wrapped unexpected \(_data.raw)")
}
if let t = title, t.isEmpty {
return nil
} else {
return title
}
}
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively we could check if the cmark_node_get_title
value was empty in CommonMarkConverter.swift before passing the title to the MarkupConversion
initializer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I agree that I would also expect nil
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both implementations are fine for me. The only question is should we sync such logic to Link.destination
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively we could check if the
cmark_node_get_title
value was empty in CommonMarkConverter.swift before passing the title to theMarkupConversion
initializer
+1 for this since we've already similar operations for language
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with 2766399
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems good to me but I'm not familiar enough with the details to know the potential pitfalls.
Got it. Thanks for your review. Maybe we can wait for @QuietMisdreavus 's review suggestion. |
I would be fine with merging this and addressing any concerns from @QuietMisdreavus later, if there are any. |
2766399
to
6ee1221
Compare
@swift-ci please test |
6ee1221
to
e76778f
Compare
@swift-ci please test |
Ping @QuietMisdreavus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
It looks like this is breaking tests in Swift-DocC: https://ci.swift.org/job/oss-swift-package-amazon-linux-2/2319/consoleText @Kyle-Ye Are you able to take a look? |
I will revert this change to unblock Swift toolchains from being built and we can land this change back alongside the Swift-DocC changes once they're ready. |
This reverts commit e5ab909.
Got it. I'll look at it now. @franklinsch |
The breaking is expected. See discussion here #140 (comment) Sorry I forgot to update the test case for swift-docc. Here is the fix PR: swiftlang/swift-docc#708 |
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [apple/swift-markdown](https://redirect.github.com/apple/swift-markdown) | minor | `0.4.0` -> `0.5.0` | --- ### Release Notes <details> <summary>apple/swift-markdown (apple/swift-markdown)</summary> ### [`v0.5.0`](https://redirect.github.com/swiftlang/swift-markdown/releases/tag/0.5.0): Swift-Markdown 0.5.0 [Compare Source](https://redirect.github.com/apple/swift-markdown/compare/0.4.0...0.5.0) This release is based on the code that shipped into Swift 6.0. #### What's Changed - Add link title support for commonmark by [@​Kyle-Ye](https://redirect.github.com/Kyle-Ye) in [https://github.com/swiftlang/swift-markdown/pull/140](https://redirect.github.com/swiftlang/swift-markdown/pull/140) - Remove dependency on argument-parser by [@​ethan-kusters](https://redirect.github.com/ethan-kusters) in [https://github.com/swiftlang/swift-markdown/pull/149](https://redirect.github.com/swiftlang/swift-markdown/pull/149) - Fix utf8 decode by [@​zunda-pixel](https://redirect.github.com/zunda-pixel) in [https://github.com/swiftlang/swift-markdown/pull/145](https://redirect.github.com/swiftlang/swift-markdown/pull/145) - Fix multi line symbol link source range issue by [@​Kyle-Ye](https://redirect.github.com/Kyle-Ye) in [https://github.com/swiftlang/swift-markdown/pull/151](https://redirect.github.com/swiftlang/swift-markdown/pull/151) - Fix multiline directive without content parsing range issue by [@​Kyle-Ye](https://redirect.github.com/Kyle-Ye) in [https://github.com/swiftlang/swift-markdown/pull/154](https://redirect.github.com/swiftlang/swift-markdown/pull/154) - build: add a CMake based build by [@​compnerd](https://redirect.github.com/compnerd) in [https://github.com/swiftlang/swift-markdown/pull/141](https://redirect.github.com/swiftlang/swift-markdown/pull/141) - Add 2024 as an accepted year number by [@​Kyle-Ye](https://redirect.github.com/Kyle-Ye) in [https://github.com/swiftlang/swift-markdown/pull/160](https://redirect.github.com/swiftlang/swift-markdown/pull/160) - Fix Directive argument name and value ranges on non-first line by [@​Kyle-Ye](https://redirect.github.com/Kyle-Ye) in [https://github.com/swiftlang/swift-markdown/pull/79](https://redirect.github.com/swiftlang/swift-markdown/pull/79) - Add support for Doxygen discussion/note tags by [@​j-f1](https://redirect.github.com/j-f1) in [https://github.com/swiftlang/swift-markdown/pull/159](https://redirect.github.com/swiftlang/swift-markdown/pull/159) - Add support for formatting the new Doxygen types using MarkupFormatter by [@​j-f1](https://redirect.github.com/j-f1) in [https://github.com/swiftlang/swift-markdown/pull/163](https://redirect.github.com/swiftlang/swift-markdown/pull/163) - Support Windows ARM64 builds by [@​hjyamauchi](https://redirect.github.com/hjyamauchi) in [https://github.com/swiftlang/swift-markdown/pull/164](https://redirect.github.com/swiftlang/swift-markdown/pull/164) - build: silence warning about CMakeLists.txt from SPM by [@​compnerd](https://redirect.github.com/compnerd) in [https://github.com/swiftlang/swift-markdown/pull/167](https://redirect.github.com/swiftlang/swift-markdown/pull/167) #### New Contributors - [@​zunda-pixel](https://redirect.github.com/zunda-pixel) made their first contribution in [https://github.com/swiftlang/swift-markdown/pull/145](https://redirect.github.com/swiftlang/swift-markdown/pull/145) - [@​j-f1](https://redirect.github.com/j-f1) made their first contribution in [https://github.com/swiftlang/swift-markdown/pull/159](https://redirect.github.com/swiftlang/swift-markdown/pull/159) - [@​hjyamauchi](https://redirect.github.com/hjyamauchi) made their first contribution in [https://github.com/swiftlang/swift-markdown/pull/164](https://redirect.github.com/swiftlang/swift-markdown/pull/164) **Full Changelog**: swiftlang/swift-markdown@0.4.0...0.5.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://redirect.github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44OS4xIiwidXBkYXRlZEluVmVyIjoiMzguODkuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: cgrindel-self-hosted-renovate[bot] <139595543+cgrindel-self-hosted-renovate[bot]@users.noreply.github.com>
Bug/issue #, if applicable: Close #67
Summary
Add link title support for CommonMark
Dependencies
None
Testing
See new test case in
LinkTests.swift
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeeded