AtCoder Better Highlighter
This is a script that highlight codes in submission pages with highlight.js.
https://gist.github.com/shouth/1d40c814231ad712725b97eeb78c62ab
Language to be replaced by default
- Bash
- C
- C++
- C#
- Go.
- Java
- JavaScript
- Kotlin
- Objective-C
- PHP
- Perl
- Python
- Ruby
- Rust
- Swift
- TypeScript
To replace codes in other languages
First, let's open this script's edit screen. There are two methods.
Method 1: Adding a dependency library
Copy the URL of the script for your language from the list at https://cdnjs.com/libraries/highlight.js.
Next, find this line in the top of the script.
// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/highlight.min.js
Then add the line below after the line above. Replace {copied URL here}
with the URL you just copied.
// @require {copied URL here}
Method 2 Using eval()
.
By this method, you can highlight any languages that highlight.js supports. However, as is well known, it is dangerous to use eval()
. Be careful of using this method.
Find these lines near line 84.
if (!hljs.getLanguage(name)) {
// const response = await fetch(`https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/languages/${name}.min.js`);
// eval(await response.text());
return;
}
Then rewrite them as follows.
if (!hljs.getLanguage(name)) {
const response = await fetch(`https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/languages/${name}.min.js`);
eval(await response.text());
// return;
}
To use another themes
By default, default.css of highlight.js is used. To change themes, choose and copy the URL of css from https://cdnjs.com/libraries/highlight.js .
Next, find this line in the top of the script.
// @resource css https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/styles/default.min.css
Then replace the line above with the line below. Replace {copied URL here}
with the URL you just copied.
// @resource css {copied URL here}