Login  Register

Re: How to extract the raw content of a section

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

Looking at the javascript translation, I think that .content calls .convert.

You might try .text or .lines (which will be an array of lines)

David Jencks

On Mar 7, 2020, at 3:02 PM, elmicka [via Asciidoctor :: Discussion] <[hidden email]> wrote:

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                                                                        
|===  



If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/How-to-extract-the-raw-content-of-a-section-tp7732.html
To start a new topic under Asciidoctor :: Discussion, [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML