-
Notifications
You must be signed in to change notification settings - Fork 162
emit table column alignments into Render JSON #389
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
|
@swift-ci Please test |
Sources/SwiftDocC/Model/Rendering/Content/RenderBlockContent.swift
Outdated
Show resolved
Hide resolved
| self.rows = rows | ||
| self.extendedData = extendedData | ||
| self.metadata = metadata | ||
| if let alignments = alignments, !alignments.allSatisfy({ $0 == .unset }) { |
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.
It seems odd to not assign to the property if they're all unset here. Is there a technical reason that's needed? As a user of the API, I'd expect my argument to get assigned to the property.
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 is mainly for backwards compatibility with existing DocC-Render - the absence of the alignments list is the same as when they're all unset, so i decided to drop it to save on encoding space.
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.
Not emitting it in the encoder seems to be handled in the encode function though, right? It doesn't seem like the extra check here is required.
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.
Without this check, the assertRoundTripCoding would fail, because [.unset, .unset...] is not equal to nil. I could change the Equatable conformance to allow these things to compare equal, but i decided to have the check here as well to use the default conformance instead.
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.
I see, then it seems like we should implement this filtering in the decoder, rather than the initializer, that way clients that use the Swift model directly aren't affected by this.
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.
I added some filtering to the decoder and left the initializer alone, to allow all the means of creating the Table struct to get the same results. I've also added some comments describing the behavior of the initializer.
Didn't meant to hit the approval button
922f580 to
ca36f1b
Compare
|
@swift-ci Please test |
1 similar comment
|
@swift-ci Please test |
| /// A `nil` value for this property is the same as all the columns being | ||
| /// ``RenderBlockContent/ColumnAlignment/unset``. |
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 could be inferred as this type's Equatable conformance implementing this behavior. Maybe we can mention that this is the behavior in practice or something like that.
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.
Or we can actually override == and implement the behavior there.
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.
Should a Table (with 3 rows and alignments are [.unset, .unset, .unset]) equal to a Table (with the same 3 rows but alignments are nil)?
Their actual behavior is the same but the current default Equatable implementation is false.
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.
I've pushed up a new commit that implements this behavior into the Equatable conformance, and adds some tests to ensure that the behavior holds.
|
@swift-ci Please test |
rdar://77749746
adada36 to
ef38e3a
Compare
|
@swift-ci Please test |
Bug/issue #, if applicable: rdar://77749746
Summary
This PR takes the table alignment info from Swift-Markdown and emits it into Render JSON, so that Markdown tables' column alignment information can be reflected in the final rendering.
Dependencies
swiftlang/swift-docc-render#441
Testing
Use the following table as test information:
Steps:
Sources/SwiftDocC/SwiftDocC.docc/SwiftDocC.md.DOCC_HTML_DIR=/path/to/swift-docc-render/dist bin/preview-docsChecklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/testscript and it succeeded