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,
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 |=== |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
David,
Thank you for your answer. I tried to use 'level2_block.text' and 'level2_block.lines', but it seems that there is no such method for this object (undefined method error) |
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
|
The API does not make the raw source of a section available. The source is only stored at the block level. What I've done in the past to extract the source of the section is to leverage the sourcemap. By enabling the sourcemap option, you get the file and line number for each section. Then, you take that information and go back to the original source of the document and use it to cut out the source for the second. Here's some really rough code to show you what I'm talking about: require 'asciidoctor' source = <<~'EOS' = Document Title == First Section content == Second Section content EOS doc = Asciidoctor.load source, sourcemap: true section_source = doc.source_lines[(doc.sections[0].lineno - 1)..(doc.sections[1].lineno - 2)].join ?\n Best Regards, -Dan On Sat, Mar 7, 2020 at 5:27 PM elmicka [via Asciidoctor :: Discussion] <[hidden email]> wrote: David, -- Dan Allen | @mojavelinux | https://twitter.com/mojavelinux |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Dan,
Thank you so much, I managed to make it works with your snippet. Regards |
Free forum by Nabble | Edit this page |