-
Notifications
You must be signed in to change notification settings - Fork 153
Add experimental code block options: highlight, strikeout, wrap, showLineNumbers #1287
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
base: main
Are you sure you want to change the base?
Conversation
e2c790d
to
fbe197e
Compare
@swift-ci please test |
1 similar comment
@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.
There's a few places of either API breaking changes or API that's designed in a way where it's likely to break in the future. That needs to be addressed.
Also, I have serious concerns about the way that the new code block attributes is encoded in the Render Node specification. We don't have a process for handling breaking changes to that specification today, so that format needs to be rethought to ensure that it's flexible and extensible for the type of information we want to encode there.
Sources/SwiftDocC/Model/Rendering/Content/RenderBlockContent.swift
Outdated
Show resolved
Hide resolved
public var metadata: RenderContentMetadata? | ||
public var copyToClipboard: Bool = true | ||
public var wrap: Int = 100 | ||
public var highlight: [Int] = [Int]() |
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 going to be quite limiting going forward. If we require in public API that the highlight is a list of integers then we can't represent partially highlighted lines without either:
- API breaking changes
- having to different arrays for different types of highlights.
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.
Also, with this API design, each time we need to add a new type of highlight we need to add a new public property. It would be more flexible if this was represented differently (for example making the style
a property of the "highlight").
Sources/SwiftDocC/Model/Rendering/Content/RenderBlockContent.swift
Outdated
Show resolved
Hide resolved
"highlight": { | ||
"type": "array", | ||
"items": { | ||
"type": "integer" | ||
} | ||
}, | ||
"strikeout": { | ||
"type": "array", | ||
"items": { | ||
"type": "integer" | ||
} |
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.
Similar to the API design, I have serious concerns about this scaling to either new styles of highlight style or partial highlight ranges.
Unlike the Swift API, we have no process at all for breaking changes to the Render Node specification so we need to really think this through so that the JSON format is flexible and extensible for the type of information we want to encode 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.
Although this is rather technical, it might be good to discuss this in the forums to get greater visibility and to get inputs from a wider audience.
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.
Reference to forums discussion: https://forums.swift.org/t/rfc-additional-options-for-code-blocks-highlight-strikeout-wrap-line-numbers/82065/11
ec3f677
to
e1ac76a
Compare
…rd and other code block annotations
… on language line, tests
e1ac76a
to
b7b9d35
Compare
Summary
This PR implements new code block options for line highlighting, line striking, line wrapping, and showing line numbers. When the
enable-experimental-code-block
flag is enabled, authors can specify options in the code block language line to control presentation:highlight=[1, 2, 3]
— highlight the given line numbersstrikeout=[3]
— strikethrough the given line numberswrap=80
— wrap code lines to the specified character widthshowLineNumbers
— turn on line numbersThese options may appear after a specified language or alone.
User Experience
With the
enable-experimental-code-block
flag, authors can annotate code listings with these new options using the language line.
or without a language
highlight
andstrikeout
accept 1-indexed arrayswrap
takes an integer and applies soft wrapping at that widthImplementation Overview
swift-docc
, this change parsesshowLineNumbers
,highlight=[Int]
,strikeout=[Int]
, andwrap=Int
from the language line in triple-backtick code blocks, where language (optionally) should be specified as the first option when it’s included.OptionName
enum on theCodeListing
struct for available options.RenderNode.spec.json
to document the newCodeListing
fields.Utility/ParseLanguageString.swift
for parsing the language string and option arrays.InvalidCodeBlockOption
checker to identify typos in options, suggest an unknown option might be the language (when it’s not placed first), and validate array indices forhighlight
andstrikeout
are within the bounds of a code block.Dependencies
This PR builds on top of #1273 and depends on associated changes in
swift-docc-render
to actually render and handle thehighlight
,strikeout
,wrap
, andshowLineNumbers
options. The associated swift-docc-render PR is here: swiftlang/swift-docc-render#965Testing
Setup
Use the additional-metadata branches for
swift-docc
andswift-docc-render
with the newhighlight
,strikeout
,wrap
andshowLineNumbers
changes.Rebuild documentation using
swift-docc
and the feature flagenable-experimental-code-block
. Serve it using a local build ofswift-docc-render
.How to Test
highlight
, `strikeout`, `wrap` and/or `showLineNumbers` options after the language (optionally) like this:Checklist
./bin/test
script and it succeededRenderNode.spec.json
, holding off on documentation for experimental featuresThese new options looks like the below:


Compared to without these options:
