Add syntax highlighting to code tags - #2457
Open
Plastikmensch wants to merge 6 commits into
Open
Conversation
Author
|
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 <plastikmensch@users.noreply.github.com>
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 <plastikmensch@users.noreply.github.com>
Allows users to set the language on code tags, which was previously discarded. Also allows this attribute on incoming toots. Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>
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 <plastikmensch@users.noreply.github.com>
Adds a new function to add syntax highlighting on `contentHtml` Also supports translated content. Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>
Add tests to make sure valid `code-lang` attributes are kept and invalid ones removed. Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>
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. |
ClearlyClaire
force-pushed
the
main
branch
2 times, most recently
from
September 25, 2025 16:38
11bd515 to
7821634
Compare
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
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.jsnode dependencycode-languages.ymlcontaining supported languages to/configMASTODON_STRICTand advanced text formatter to allowdata-codelangattributedata-codelangandtitleattributes 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.ymlhas been created with the output of the following script:This script has to be run again when adding third-party language support packages.