summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bennett <rltbennett@icloud.com>2021-12-23 23:58:33 -0700
committerDan Allen <dan.j.allen@gmail.com>2021-12-23 23:59:16 -0700
commit40fc0fe353ebd45eea3751356c4760758ebeabcf (patch)
tree868b4c0f6d6a96dba1afabe279f652bf97b03307
parentde54df6307c2b1ad6db5a7f0b305b730b7afb096 (diff)
added example to docs of extending the pygments adapter to link to a custom stylesheet
-rw-r--r--docs/modules/syntax-highlighting/examples/pygments-syntax-highlighter-with-custom-stylesheet.rb12
-rw-r--r--docs/modules/syntax-highlighting/pages/custom.adoc7
2 files changed, 19 insertions, 0 deletions
diff --git a/docs/modules/syntax-highlighting/examples/pygments-syntax-highlighter-with-custom-stylesheet.rb b/docs/modules/syntax-highlighting/examples/pygments-syntax-highlighter-with-custom-stylesheet.rb
new file mode 100644
index 00000000..9c6fdae1
--- /dev/null
+++ b/docs/modules/syntax-highlighting/examples/pygments-syntax-highlighter-with-custom-stylesheet.rb
@@ -0,0 +1,12 @@
+class MyPygmentsAdapter < (Asciidoctor::SyntaxHighlighter.for 'pygments')
+ register_for :pygments
+
+ def write_stylesheet? doc
+ false
+ end
+
+ def docinfo location, doc, opts
+ slash = opts[:self_closing_tag_slash]
+ %(<link rel="stylesheet" href="/styles/syntax-theme.css"#{slash}>)
+ end
+end
diff --git a/docs/modules/syntax-highlighting/pages/custom.adoc b/docs/modules/syntax-highlighting/pages/custom.adoc
index 9c390d14..f7229321 100644
--- a/docs/modules/syntax-highlighting/pages/custom.adoc
+++ b/docs/modules/syntax-highlighting/pages/custom.adoc
@@ -52,6 +52,13 @@ Then, require this file when invoking Asciidoctor, setting `source-highlighter=p
$ asciidoctor -r ./extended-pygments-syntax-highlighter.rb -a source-highlighter=pygments document.adoc
+If you wanted to modify the built-in adapter to honor the location of a custom stylesheet specified by the `pygments-stylesheet` attribute, you can do so by extending the adapter and overriding the `docinfo` method.
+
+[,ruby]
+----
+include::example$pygments-syntax-highlighter-with-custom-stylesheet.rb[]
+----
+
If you want to decorate built-in behavior, you can invoke the `super` method anywhere inside the method to delegate to the behavior provided by the built-in adapter.
Let's say you always want lines to be numbered, regardless of the setting in the document.