Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Hi,
I'm either missing the instruction to do this and you may direct me to the instruction or point me where to enter a feature request, as appropriate. I have an adoc file which contains many include files to make the final document. Is there a way to output a single adoc file which contains the contents of the various include files via the asciidoctor command? Thanks, Chuck |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Administrator
|
Hi Chuck,
You can output a single adoc file using the following Ruby script. Just replace the sample.adoc names with your file name, and remove the -- from the top and bottom of the script. -- require 'asciidoctor' source = File.read 'sample.adoc' doc = Asciidoctor::Document.new reader = Asciidoctor::PreprocessorReader.new doc, source combined_source = reader.read File.open('sample-combined.adoc', 'w') {|f| f.write combined_source } -- Save the script with the extension .rb in the directory with your docs. Then, in your terminal, navigate to the directory where you saved the ruby script and type the following command to execute the file with Ruby: ruby <script-name>.rb Note: I didn't write the script, it's courtesy of @mojavelinux, because I'm also rendering lots of files with lots of includes :D I don't know how to preprocess includes from the CLI alone, but maybe @mojavelinux will have some tips. Cheers, Sarah |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Administrator
|
Chuck, I realized there is a little bit more to this story after having used it myself. It's necessary to parse the header of the document before passing it to the reader.Here's the script I'm using. [source,ruby] -- require 'asciidoctor' source_file = ARGV[0] if !source_file warn 'You must provide a source file' exit 1 end output_file = source_file.sub(/\.adoc$/, '-preprocessed.adoc') source = File.read source_file doc = Asciidoctor.load_file ARGV[0], :safe => :safe, :parse_header_only => true reader = Asciidoctor::PreprocessorReader.new doc, source preprocessed_source = reader.read.gsub(/^include::/, '\\include::') File.open(output_file, 'w') {|f| f.write preprocessed_source } -- I think this would be a nice feature to put into the Asciidoctor API. Perhaps an option `:preprocess_only => true` and a corresponding cli flag. wdyt? On Tue, Oct 15, 2013 at 10:24 PM, graphitefriction [via Asciidoctor :: Discussion] <[hidden email]> wrote: Hi Chuck, ... [show rest of quote] -- Dan Allen | http://google.com/profiles/dan.j.allen |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Hi, I have been reading this entry and I think I am missing something important. Let me explain:
I have a project with 4 AsciiDoc file. One parent file which has three include directives, that includes each file. Then I render the parent file using Asciidoctor-Maven-Plugin and the output is only one html file with content of all files rendered inside. So I think I am missing something about the problem presented here. |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Administrator
|
Alex, This is more about diagnostics. It's when you want to see, or retrieve, the effective AsciiDoc source as the processor sees it once all the preprocessor directives are evaluated (e.g., include, ifdef, etc) For instance, I needed a single source file version of the quick reference for the asciidoctor.js example since includes don't (yet) work in that environment. For typical use of Asciidoctor, this isn't something you would need. -Dan On Nov 29, 2013 1:45 PM, "asotobu [via Asciidoctor :: Discussion]" <[hidden email]> wrote:
Hi, I have been reading this entry and I think I am missing something important. Let me explain: |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Thank you so much Dan for the clarification. At first I thought it was what you have explained me bit then I reread again and I started to doubt to finally see I was missing something. Thank you
El divendres 29 de novembre de 2013, mojavelinux [via Asciidoctor :: Discussion] ha escrit:
... [show rest of quote] -- Enviat amb Gmail Mobile |
Free forum by Nabble | Edit this page |