Closed obilodeau closed 10 months ago
The only extension point that can be used to control this flag is a Preprocessor. That's because the Preprocessor runs before the document is parsed.
Here's how you'd do it:
Asciidoctor::Extensions.register do
preprocessor do
process do |doc, reader|
doc.instance_variable_set :@options, (doc.options.merge header_footer: true)
nil
end
end
end
(Modifying the options isn't a supported operation in the public API, hence the low-level assignment).
However, if you have control over adding an extension, I'm not sure why you wouldn't just pass the header_footer
option to the call to Asciidoctor.convert
.
Btw, you could just use the -s
flag instead of --no-header-footer
.
However, if you have control over adding an extension, I'm not sure why you wouldn't just pass the
header_footer
option to the call toAsciidoctor.convert
.
It isn't clear how to accomplish that with an extension from the documentation. The only "convert" from the extension repository is this.
I'm wondering what is the process
method's objective. If I return a string instead of nil
what will happen?
For example, this doesn't work:
Asciidoctor::Extensions.register do
preprocessor do
process do |doc, reader|
::Asciidoctor.convert doc.attributes['docfile'], header_footer: false
end
end
end
Sorry to have confused you. The option name is standalone
(e.g., standalone: false
). However, a preprocessor should never call Asciidoctor#convert on the file that is being converted. That's going to result in a mess. A preprocessor should set properties on the Document object and that's it.
I believe the answer I provided above is the correct one.
I tried creating an extension that would generate HTML ready to be pasted into a Wordpress post in source form (minimal HTML).
For it to work without setting the
--no-header-footer
in addition to the-r
flag I would have liked to set the:header_footer = false
option directly when the extension is registered.I've tried several ways and it didn't work. Including subclassing and overloading
initialize
and trying to access the@options
field and add the option to it (but the hash is frozen).I need guidance. Here's the code with attempts commented out: https://github.com/asciidoctor/asciidoctor-extensions-lab/compare/master...obilodeau:wordpress-extension?expand=1