Login  Register

How to extract the raw content of a section

Posted by elmicka on Mar 07, 2020; 11:02pm
URL: https://discuss.asciidoctor.org/How-to-extract-the-raw-content-of-a-section-tp7732.html

Hi,

First of all, I'm new to asciidoctor and ruby, so maybe I'm missing something easy there.

I'm trying to write a script to extract the content from a document.
I came with this script, but "puts level2_block.content" prints out an html formated content
instead of the asciidoc content.

Is it possible to get the asciidoc content ?

Thanks

require 'asciidoctor'                                                                                                                            
include Asciidoctor                                                                 
                                                                                    
document = Asciidoctor.load_file("demo.adoc")                                       
                                                                                    
document.blocks.each do|level1_block|                                               
  puts level1_block.title                                                           
  level1_block.blocks.each do|level2_block|                                         
    page_name = level2_block.title.tr(" ","-")                                      
    puts "===============================================>"                         
    puts "\t #{page_name}"                                                          
    puts level2_block.content                                                                    
  end                                                                               
end  


My test file.

= Title 1                                                                           
                                                                                    
== Subtitle 1                                                                       
                                                                                    
=== My section 1.1                                                                  
My content goes here.                                                               
                                                                                                
== Subtitle 2                                                                       
                                                                                  
=== My section 2.1                                                                  
|===                                                                                
|header1|header2                                                                    
|cell1|cell2                                                                        
|===