-
Notifications
You must be signed in to change notification settings - Fork 154
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
Open
DebugSteven
wants to merge
23
commits into
swiftlang:main
Choose a base branch
from
DebugSteven:additional-metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 tasks
…rd and other code block annotations
… on language line, tests
e2c790d
to
fbe197e
Compare
@swift-ci please test |
@swift-ci please test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
