Re: write syntax highlighting block content to file
Posted by
mojavelinux on
Nov 21, 2018; 8:45pm
URL: https://discuss.asciidoctor.org/write-syntax-highlighting-block-content-to-file-tp6582p6590.html
Bernhard,
It seems like a treeprocessor is what you want. With a treeprocessor, you can query for all the source blocks like so:
doc.find_by context: :listing, style: 'source'
Then you can either get the raw source of the block using .source or the highlighted source using .content. Invoking these methods will not prevent the processor from outputting the blocks as normal.
Cheers,
-Dan
On Tue, Nov 6, 2018 at 2:12 PM ttmetro [via Asciidoctor :: Discussion] <
[hidden email]> wrote:
I'd like to output the code (raw, not formatted) to a file. E.g.
```python
def abc():
pass
```
should get rendered in the output as usual with syntax highlighting, but the code also should be passed to an extension so it can be written to a file.
Alternatively, I know how to create an extension that gets the code, but then I do not know how to also have it appear formatted in the asciidoctor output.
Thanks,
Bernhard
--