Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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#