forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Add syntax highlighting to code tags #2457
Open
Plastikmensch
wants to merge
6
commits into
glitch-soc:main
Choose a base branch
from
Plastikmensch:redo/add-syntax-highlighting-to-code-blocks
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.
Open
Add syntax highlighting to code tags #2457
Plastikmensch
wants to merge
6
commits into
glitch-soc:main
from
Plastikmensch:redo/add-syntax-highlighting-to-code-blocks
Conversation
This file contains 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
Just noticed that highlight.js now adds a "data-highlighted" attribute to highlighted elements. |
This pull request has merge conflicts that must be resolved before it can be merged. |
highlight.js will be used to do the highlighting in the web interface Signed-off-by: Plastikmensch <[email protected]>
Imports necessary styles from highlight.js Github style has been chosen as a default, because it is what most people will be familiar with. Signed-off-by: Plastikmensch <[email protected]>
Allows users to set the language on code tags, which was previously discarded. Also allows this attribute on incoming toots. Signed-off-by: Plastikmensch <[email protected]>
Adds a new yml file containing all valid code languages which are supported by highlight.js This file has been created by a script as the list of supported languages is unreliable. This is not ideal, but highlight.js made it clear they won't add new languages natively. Instead additional language support is provided by third-party packages. If such a third-party package is installed, this file needs to be updated to support the new aliases. When an unsupported language is given, the `data-codelang` attribute is removed using a new transformer. Signed-off-by: Plastikmensch <[email protected]>
Adds a new function to add syntax highlighting on `contentHtml` Also supports translated content. Signed-off-by: Plastikmensch <[email protected]>
Add tests to make sure valid `code-lang` attributes are kept and invalid ones removed. Signed-off-by: Plastikmensch <[email protected]>
Plastikmensch
force-pushed
the
redo/add-syntax-highlighting-to-code-blocks
branch
from
November 17, 2023 13:32
4b77682
to
5416d99
Compare
This pull request has resolved merge conflicts and is ready for review. |
This pull request has merge conflicts that must be resolved before it can be merged. |
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.
Closes #2011
Supersedes #2015
The old PR was a mess, so I redid it.
Overview of changes:
highlight.js
node dependencycode-languages.yml
containing supported languages to/config
MASTODON_STRICT
and advanced text formatter to allowdata-codelang
attributedata-codelang
andtitle
attributes to code tags in web UIPreview:
Code blocks in the reply indicator are not highlighted as it uses a light background.
Unfortunately this is also the case for the report modal, where code blocks are highlighted.
Adding a background to code blocks would mitigate this problem, but it has been suggested multiple times, but not implemented.
code-languages.yml
has been created with the output of the following script:This script has to be run again when adding third-party language support packages.