Skip to content

Commit dcfb3be

Browse files
committed
Update Rouge README
1 parent 0da9b9f commit dcfb3be

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

Rouge/README.md

+33-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Testing how to employ custom [Rouge] lexers in [Asciidoctor] projects.
1414
- [Challenges](#challenges)
1515
- [Info](#info)
1616
- [Custom Lexers with Rougify via CLI](#custom-lexers-with-rougify-via-cli)
17+
- [Custom Lexers via Rouge API](#custom-lexers-via-rouge-api)
1718
- [Custom Lexers with Asciidoctor](#custom-lexers-with-asciidoctor)
1819
- [Links](#links)
1920
- [Rouge](#rouge)
@@ -64,14 +65,39 @@ To highlight an Alan source file using a custom Rouge lexer from the command lin
6465
$ rougify sample.alan --require ./alan3.rb
6566
```
6667

68+
From rougify help:
69+
70+
```
71+
$ rougify help highlight
72+
usage: rougify highlight <filename> [options...]
73+
rougify highlight [options...]
74+
75+
[...]
76+
77+
--require|-r <filename> require a filename or library before
78+
highlighting
79+
```
80+
81+
82+
## Custom Lexers via Rouge API
83+
84+
I'm still not entirely sure how to instruct the Rouge API to require a custom lexer, but here's how the command line parameter `--require` is being handled by [`lib/rouge/cli.rb`][cli.rb] (L235):
85+
86+
```ruby
87+
when '-r', '--require'
88+
opts[:requires] << argv.shift
89+
```
90+
6791
## Custom Lexers with Asciidoctor
6892

6993
As for Asciidoctor, there doesn't seem to be a way to enforce the `--require` option on Rouge.
70-
My best guess right now is we might need to write a custom Rouge extension and override Asciidoctor's native API for Rouge:
94+
My best guess right now is that we might need to either:
95+
96+
1. Write a [custom syntax highlighter adapter] for Rouge, and override Asciidoctor's native API for Rouge:
7197

72-
- [`lib/asciidoctor/syntax_highlighter/rouge.rb`][rouge.rb]
98+
- [`lib/asciidoctor/syntax_highlighter/rouge.rb`][rouge.rb]
7399

74-
Or invoke Asciidoctor via Ruby, passing extra setting to the Rouge library.
100+
2. Invoke Asciidoctor via Ruby, passing extra setting to the Rouge library (not quite sure this would override the default behaviour).
75101

76102
-------------------------------------------------------------------------------
77103

@@ -82,6 +108,7 @@ Or invoke Asciidoctor via Ruby, passing extra setting to the Rouge library.
82108
- [Rouge website][Rouge]
83109
- [Rouge repository]
84110
- [Rouge documentation]
111+
- [Redcarpet]
85112

86113
## Asciidoctor
87114

@@ -102,6 +129,8 @@ Or invoke Asciidoctor via Ruby, passing extra setting to the Rouge library.
102129
[Rouge repository]: https://github.com/rouge-ruby/rouge "Rouge repository on GitHub"
103130
[Rouge documentation]: https://rouge-ruby.github.io/docs/ "Rouge online documentation"
104131

132+
[cli.rb]: https://github.com/rouge-ruby/rouge/blob/master/lib/rouge/cli.rb#L235 "View source file at Rouge repository"
133+
105134
<!-- Asciidoctor -->
106135

107136
[Asciidoctor]: https://asciidoctor.org "Asciidoctor website"
@@ -119,6 +148,7 @@ Or invoke Asciidoctor via Ruby, passing extra setting to the Rouge library.
119148
[asciidoctor-fopub]: https://github.com/asciidoctor/asciidoctor-fopub
120149
[asciidoctor-pdf]: https://github.com/asciidoctor/asciidoctor-pdf
121150
[Highlight]: http://www.andre-simon.de "Highlight website"
151+
[Redcarpet]: https://github.com/vmg/redcarpet "Redcarpet repository on GitHub"
122152

123153
<!-- project files and folders -->
124154

0 commit comments

Comments
 (0)