-
Notifications
You must be signed in to change notification settings - Fork 157
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
Sources/SwiftDocC/Model/Rendering/Content/RenderBlockContent.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftDocC/Model/Rendering/Content/RenderBlockContent.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftDocC/SwiftDocC.docc/Resources/RenderNode.spec.json
Outdated
Show resolved
Hide resolved
75ba751
to
96fe662
Compare
6158cba
to
5b3f31c
Compare
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 are a few parts of the code I want to take a closer look at but in general this looks good to me.
Sources/SwiftDocC/Model/Rendering/Content/RenderBlockContent.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftDocC/Model/Rendering/Content/RenderBlockContent.swift
Outdated
Show resolved
Hide resolved
…rd and other code block annotations
…y-to-clipboard and other code block annotations
… on language line, tests
…wift Co-authored-by: David Rönnqvist <[email protected]>
…wift Co-authored-by: David Rönnqvist <[email protected]>
81f406c
to
9164dc6
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:
