From 40fc0fe353ebd45eea3751356c4760758ebeabcf Mon Sep 17 00:00:00 2001 From: Robert Bennett Date: Thu, 23 Dec 2021 23:58:33 -0700 Subject: added example to docs of extending the pygments adapter to link to a custom stylesheet --- .../pygments-syntax-highlighter-with-custom-stylesheet.rb | 12 ++++++++++++ docs/modules/syntax-highlighting/pages/custom.adoc | 7 +++++++ 2 files changed, 19 insertions(+) create mode 100644 docs/modules/syntax-highlighting/examples/pygments-syntax-highlighter-with-custom-stylesheet.rb (limited to 'docs') 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] + %() + 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. -- cgit v1.2.3