Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timhaj/syntaxhighlighter.js
CustomizableSyntaxHighlighter.js
https://github.com/timhaj/syntaxhighlighter.js
color-scheme css javascript javascript-library syntax-highlighting
Last synced: 6 days ago
JSON representation
CustomizableSyntaxHighlighter.js
- Host: GitHub
- URL: https://github.com/timhaj/syntaxhighlighter.js
- Owner: timhaj
- Created: 2024-09-12T12:16:47.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-16T17:39:16.000Z (4 months ago)
- Last Synced: 2024-11-08T09:44:03.509Z (about 2 months ago)
- Topics: color-scheme, css, javascript, javascript-library, syntax-highlighting
- Language: JavaScript
- Homepage:
- Size: 69.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CSH.js
CustomizableSyntaxHighlighter.js# Usage:
- Donwload main.js and your preferred syntax highlighting color theme (incase you have to much overhead (weird, but ok), you also have .min versions).
- You also may define your own color scheme, by manually editing the `user.css` file.
- Link both files in the `` tag:
- ``
- ``
- Notice: to use the syntax highlighting, you have to define a `` block with your code, and add the `highlight_[language]` class to it, eg. if you have some python code, it should look something like this:
- ```html
def factorial(n):
if n == 0 or n == 1:
return 1
return n * factorial(n - 1)
def main():
try:
num = int(input("Enter a number: "))
print(f"Factorial of {num} is {factorial(num)}")
except ValueError:
print("Please enter a valid integer.")
if __name__ == "__main__":
main()
```
- Incase the language you specified isn't supported, you get a default black background & white-ish text color scheme.
- Now, you can use the library in 3 different ways:
1. Calling `highlightCode()` anywhere in the program, will automatically select all `` tags in the document, search for the language in which the code is in, and apply the syntax highlighting for it + add line numbers.
2. Calling `highlightCodes(node)` will automatically select all `` tags in the node you passed in as an argument, and do the same as the line above.
3. With `node = highlightCodes(node)` you can apply the syntax highlighting before the node is added to the document (dynamic).
- After calling one of above ways, you get this result in your browser:![screenshot](demo/result.png)
## Currently supports the following languages (evolving list):
- R
- Python
- SQL
- C#