Skip to content

Commit

Permalink
Update README for syntax highlighting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Dec 2, 2023
1 parent fef7d87 commit 1a168f3
Showing 1 changed file with 46 additions and 10 deletions.
56 changes: 46 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ providing further niceties.
code = <<~CODE
```ruby
def hello
puts "hello"
puts "hello"
end
CODE

# pass in a theme name from a pre-existing set
puts Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: "InspiredGitHub" } })

# <pre style="background-color:#ffffff;" lang="ruby"><code>
Expand All @@ -123,24 +124,32 @@ puts Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: "Inspire
# </code></pre>
````

To disable this plugin, pass `nil`:
By default, the plugin uses the `"base16-ocean.dark"` theme.

To disable this plugin, set the value to `nil`:

```ruby
Commonmarker.to_html(code, plugins: { syntax_highlighter: nil })
# or
Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: nil } })
```

You can also provide a `path` to a directory containing `.tmtheme` files to load:
To use CSS classes, set a key named `theme` to `nil`:

```ruby
````ruby
code = <<~CODE
```ruby
def hello
puts "hello"
end
CODE

Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: "Monokai", path: "./themes" } })
```
Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: "" } })

##### Available themes
# <pre class="syntax-highlighting"><code><span class="source ruby"><span class="meta function ruby"><span class="keyword control def ruby">def</span></span><span class="meta function ruby"> # <span class="entity name function ruby">hello</span></span>
# <span class="support function builtin ruby">puts</span> <span class="string quoted double ruby"><span class="punctuation definition string begin ruby">&quot;</span>hello<span class="punctuation definition string end ruby">&quot;</span></span>
# <span class="keyword control ruby">end</span>\n</span></code></pre>
````

Here's [a list of themes available by default](https://docs.rs/syntect/5.0.0/syntect/highlighting/struct.ThemeSet.html#implementations):
The library also comes with [a set of pre-existing themes:(https://docs.rs/syntect/5.0.0/syntect/highlighting/struct.ThemeSet.html#implementations) :

- `"base16-ocean.dark"`
- `"base16-eighties.dark"`
Expand All @@ -150,6 +159,18 @@ Here's [a list of themes available by default](https://docs.rs/syntect/5.0.0/syn
- `"Solarized (dark)"`
- `"Solarized (light)"`

```ruby
# pass in a theme name from a pre-existing set
puts Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: "InspiredGitHub" } })
```

To use a custome theme, you can provide a `path` to a directory containing `.tmtheme` files to load:

```ruby

Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: "Monokai", path: "./themes" } })
```

## Output formats

Commonmarker can currently only generate output in one format: HTML.
Expand Down Expand Up @@ -198,3 +219,18 @@ Comparison:
commonmarker with to_html: 5.8 i/s - 3.84x (± 0.00) slower
kramdown: 0.3 i/s - 68.30x (± 0.00) slower
```

```
```

````
```
```
```
```
````

0 comments on commit 1a168f3

Please sign in to comment.