-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to access command line params from Preprocessor #72
Comments
You can access the commandline parameters via the global variable ARGV. That is an array of flags which is otherwise unparsed. However, since we use a commandline parser, additional flags such as A better way to specify options is to pass them through document attributes. Document attributes are schemaless, so you can introduce any number of them as long as they don't collide with built-in attributes. For example, something like:
You can access the document attributes via the Happy hacking! |
For an example of a preprocessor that manipulates values on the Document object, see https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/enable-sourcemap-preprocessor.rb. |
Thanks, this is very helpful. I've complete the coding successfully for this part. Is it possible to register or save the file to some location so that asciidoctor can load it automatically without using |
@atbest Not at the moment. The |
I think it should go either Because I don't want to set Original lines 208-219 in html5.rb: case highlighter
when 'highlightjs', 'highlight.js'
highlightjs_path = node.attr 'highlightjsdir', %(#{cdn_base}/highlight.js/8.9.1)
result << %(<link rel="stylesheet" href="#{highlightjs_path}/styles/#{node.attr 'highlightjs-theme', 'github'}.min.css"#{slash}>)
result << %(<script src="#{highlightjs_path}/highlight.min.js"></script>
<script>hljs.initHighlighting()</script>)
when 'prettify'
prettify_path = node.attr 'prettifydir', %(#{cdn_base}/prettify/r298)
result << %(<link rel="stylesheet" href="#{prettify_path}/#{node.attr 'prettify-theme', 'prettify'}.min.css"#{slash}>)
result << %(<script src="#{prettify_path}/prettify.min.js"></script>
<script>prettyPrint()</script>)
end Backward-compatible addition of case highlighter
when 'highlightjs', 'highlight.js'
highlighter_path = node.attr('highlightjsdir', nil) || node.attr('highlighterdir', %(#{cdn_base}/highlight.js/8.9.1))
highlighter_theme = node.attr('highlightjs-theme', nil) || node.attr('highlighter-theme', 'github')
result << %(<link rel="stylesheet" href="#{highlighter_path}/styles/#{highlighter_theme}.min.css"#{slash}>)
result << %(<script src="#{highlighter_path}/highlight.min.js"></script>
<script>hljs.initHighlighting()</script>)
when 'prettify'
highlighter_path = node.attr('prettifydir', nil) || node.attr('highlighterdir', %(#{cdn_base}/prettify/r298))
highlighter_theme = node.attr('prettify-theme', nil) || node.attr('highlighter-theme', 'prettify')
result << %(<link rel="stylesheet" href="#{highlighter_path}/#{highlighter_theme}.min.css"#{slash}>)
result << %(<script src="#{highlighter_path}/prettify.min.js"></script>
<script>prettyPrint()</script>)
end This is moderate implement than the preprocessor, and will not change anything for old documents. The last optional attribute, |
Technically, you only need one That's why I think the ASCIIDOCTOR_OPTS env variable is the right way to go to set up an environment that passes additional flags to the cli options parser. For example:
The config loader can then register your preprocessor to push additional attributes into Asciidoctor. I do think that the cli parser needs to be extensible though. The problem is that the cli options declarations are buried inside the parse! method. I've made a note to file an issue to make that reachable. We also need this for other converters such as Asciidoctor PDF. Keep in mind, I still plan on implementing asciidoctor/asciidoctor#566. But it's good to write it first as an extension to explore ideas and get the design right. |
Yes, that's why I said that it can go to Asciidoctor::Cli::Options.parse! (for cmd use only). Then if you want the ruby API and others to have similar behavior, you'll find some mechanism for them. |
I am planning to write a preprocessor to parse attributes from a yaml file as described in 566. In order to maximize the use of the config file, I am planing to implement a theme feature from the config file, which contains common attributes (overidable) and theme specific attributes.
Example:
Then the cli command is
asciidoctor --config-file=conf.yml --theme=dark -a stylesdir=new_style input.adoc
.The order of the attributes is
cli > theme > common
. It's easier to implementtheme > common
, but forcli > theme
,config-file
andtheme
, the preprocessor need to read the command params.The text was updated successfully, but these errors were encountered: