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
Hard breaks aren't reflected in output #477
Hard breaks aren't reflected in output #477
Comments
Thanks for filing this @amartini51! CC: @QuietMisdreavus It looks like this fix should be in swift-docc/Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift Lines 227 to 229 in 61100a4
|
DocC doesn't support subscripts, so instead of using subscript "opt" for optionality, use a postfix question mark. Alternatives considered included text like "OPT" or "(opt)" and Unicode subscript characters. The former are hard to read and interrupt the flow of the grammar. The latter render poorly because they're intended for phonetic annotation, so the different letters don't share a baseline in many fonts. It's a known issue that DocC doesn't support hard breaks [1], so insert a paragraph break between each grammar production for now. I added a "double" paragraph break between groups, where there used to be a blank line, to preserve that information for when DocC adds hard break support in the future. 1: https://github.com/apple/swift-docc/issues/412 Fixes #3 Fixes rdar://101001280
It looks to be a swift-markdown bug for me. import Markdown
let string = """
This text should\
appear on two lines.
This is the second paragraph.
"""
let document = Document(parsing: string)
print(document.debugDescription())
// Document
// ├─ Paragraph
// │ └─ Text "This text shouldappear on two lines."
// └─ Paragraph
// └─ Text "This is the second paragraph." Also even if I add such text to a docc markdown file, and run docc preview on it. The method |
Hm okay. Let's transfer this issue over there for now then. We can file a new issue on Swift-DocC if it turns out a fix is needed across both repos. |
Works fine for swift-markdown. Notice that you escape with let source = """
Paragraph.\\
Still the same paragraph.
Different paragraph
"""
let document = Document(parsing: source)
print(document.debugDescription())
// Document
// ├─ Paragraph
// │ ├─ Text "Paragraph."
// │ ├─ LineBreak
// │ └─ Text "Still the same paragraph."
// └─ Paragraph
// └─ Text "Different paragraph" |
import Markdown
// Two space at the end of line 4 of string
let string = #"""
This text should\
appear on two lines.
This text should
appear on two lines.
This is the second paragraph.
"""#
let document = Document(parsing: string)
print(document.debugDescription())
As @Iikeli explained, I forgot to escape the "\". So the markdown has no problem identifying linebreak for 2 spaces and "\".
If we change the function to return "\n" for RenderInlineContent mutating func visitLineBreak(_ lineBreak: LineBreak) -> [RenderContent] {
return [RenderInlineContent.text("\n)]
}
the output json file in
But swift-docc-render (Xcode 14.2 Swift toolchain) will still render the paragraph in one line. So maybe the issue needs a swift-docc and swift-docc-render cross PR to fix. Could you help transform the issue back to swift-docc @ethan-kusters ? And when the cross PR is ready, I'll file a new issue on swift-docc-render repo. |
Is there any hope of some motion on this? Still hasn't been fixed as of the Xcode 15 beta/Swift 5.9 |
Sorry, I almost forgot the issue 😢. Thanks for the reminding. |
I've added the swift-docc PR via #633 and created the corresponding issue to swift-docc-render via apple/swift-docc-render#697. When both of them are ready, the issue will be closed. Then we may consider cherry-pick this back to the release/5.9 branch. |
The fix had landed on main branch of swift-docc and swift-docc-render. And we are cherry-picking it back to release/5.9. |
Both PRs have been merged and also cherry-picked to release/5.9 now :) |
Description
The CommonMark spec allows writers to specify a line break (not a paragraph break) by writing two or more spaces at the end of the line, or by writing a backslash (
\
) at the end of the line. Currently, the rendered content from DocC doesn't break the line at that location.Example input:
Checklist
main
branch of this package.rdar://101684224
The text was updated successfully, but these errors were encountered: