-
Notifications
You must be signed in to change notification settings - Fork 65
Implement highlight/strikeout/wrap for code listings #965
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
I'm also curious if you've considered adding the ability to configure line number display on/off with a custom setting like this? I feel like it would be super useful in combination with the new wrapping feature to more easily distinguish between soft wrapped line vs purposeful newlines in the actual code. |
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.
Hi @DebugSteven , amazing work! thank you so much for your PR!
I left some suggestions to refactor the code a bit but everything else is great!
As @mportiz08 mentioned, I also think that you should consider changing the code of the highlighting to match the tutorials ones :)
Excited for this PR!
@marinaaisa @mportiz08 I was the source for the different coloration - I wanted an option that was significantly more like a highlighter so that it would pull more attention, especially in a an article context where a reader is more likely to be skimming, so that it drew their attention to the relevant sections quickly. I totally get wanting to keep it consistent though, my biggest concern, especially with the dark mode viewing, is that the highlighting is too subtle - and only if you're really focused on the content will you capture that detail. We also wanted to extend beyond what the tutorial offers - for example, the tutorial content doesn't display a deleted line, which is sometimes a critical piece of what's happening in an explanation, hence reaching for the strikeout flavoring. |
cc63a57
to
9b73675
Compare
9b73675
to
a74d9a1
Compare
break-word is deprecated according to mdn and has the same effect as overflow-wrap: anywhere combined with word-break: normal.
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, code listings will have access tohighlight
,strikeout
, andwrap
properties forwarded in the render JSON.User Experience
highlight
appear with the same highlight seen in tutorials.strikeout
appear with a strikethrough line.wrap
is present and greater than 0, code lines are soft-wrapped near the specified width.showLineNumbers
option is used on a code block, line numbers will render.Implementation Overview
highlight: [Int]?
,strikeout: [Int]?
,wrap: Int?
, andshowLineNumbers
(boolean) fromRenderBlockContent.codeListing
Dependencies
This PR depends on associated changes in
swift-docc
to actually render and handle thehighlight
,strikeout
,wrap
, andshowLineNumbers
options. The associatedswift-docc
PR is here: swiftlang/swift-docc#1287Testing
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
npm test
, and it succeededThese new options looks like the below:


Compared to without these options:
