diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2021-12-23 23:59:06 -0700 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2021-12-24 00:10:28 -0700 |
| commit | af604e90b95e2bcabf772896d994647277b81464 (patch) | |
| tree | 28318f4bc78a9587f4ec312e30da75ceb3dd7fc8 /docs/modules/syntax-highlighting | |
| parent | 40fc0fe353ebd45eea3751356c4760758ebeabcf (diff) | |
fix syntax highlighter example to fully support pygments-stylesheet attribute
Diffstat (limited to 'docs/modules/syntax-highlighting')
| -rw-r--r-- | docs/modules/syntax-highlighting/examples/pygments-syntax-highlighter-with-custom-stylesheet.rb | 17 | ||||
| -rw-r--r-- | docs/modules/syntax-highlighting/pages/custom.adoc | 2 |
2 files changed, 11 insertions, 8 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 index 9c6fdae1..ef32705e 100644 --- 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 @@ -1,12 +1,15 @@ -class MyPygmentsAdapter < (Asciidoctor::SyntaxHighlighter.for 'pygments') +class ExtendedPygmentsSyntaxHighlighter < (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}>) + stylesheet = doc.attr 'pygments-stylesheet', './pygments.css' + if opts[:linkcss] + %(<link rel="stylesheet" href="#{stylesheet}"#{opts[:self_closing_tag_slash]}>) + else + stylesheet = doc.normalize_system_path stylesheet + %(<style> +#{doc.read_asset stylesheet, label: 'stylesheet', normalize: true} +</style>) + end end end diff --git a/docs/modules/syntax-highlighting/pages/custom.adoc b/docs/modules/syntax-highlighting/pages/custom.adoc index f7229321..152a5069 100644 --- a/docs/modules/syntax-highlighting/pages/custom.adoc +++ b/docs/modules/syntax-highlighting/pages/custom.adoc @@ -52,7 +52,7 @@ 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. +If, instead, 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] ---- |
