{"action":"created","issue":{"url":"https://api.github.com/repos/asciidoctor/asciidoctor/issues/1340","labels_url":"https://api.github.com/repos/asciidoctor/asciidoctor/issues/1340/labels{/name}","comments_url":"https://api.github.com/repos/asciidoctor/asciidoctor/issues/1340/comments","events_url":"https://api.github.com/repos/asciidoctor/asciidoctor/issues/1340/events","html_url":"https://github.com/asciidoctor/asciidoctor/issues/1340","id":75475345,"number":1340,"title":"Dynamic Content Creation | 2 parse document generation (ADoc -> Semi Processed -> Final format)","user":{"login":"sirinath","id":637415,"avatar_url":"https://avatars.githubusercontent.com/u/637415?v=3","gravatar_id":"","url":"https://api.github.com/users/sirinath","html_url":"https://github.com/sirinath","followers_url":"https://api.github.com/users/sirinath/followers","following_url":"https://api.github.com/users/sirinath/following{/other_user}","gists_url":"https://api.github.com/users/sirinath/gists{/gist_id}","starred_url":"https://api.github.com/users/sirinath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sirinath/subscriptions","organizations_url":"https://api.github.com/users/sirinath/orgs","repos_url":"https://api.github.com/users/sirinath/repos","events_url":"https://api.github.com/users/sirinath/events{/privacy}","received_events_url":"https://api.github.com/users/sirinath/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-12T05:51:39Z","updated_at":"2015-05-13T02:14:17Z","closed_at":null,"body":"It would be good if there is a way to use AsciiDoctor for dynamic document creation.\r\n\r\nTo ensure speed of processing perhaps it should be good have parts of the document pre processed and parts that are dynamically processed. The dynamic part can be in AsciiDoctor format which will be converted to the native raw format. The semi processed docs can have a format of its own. A second parse will fully process it replacing the parts which need to be dynamically determined."},"comment":{"url":"https://api.github.com/repos/asciidoctor/asciidoctor/issues/comments/101483570","html_url":"https://github.com/asciidoctor/asciidoctor/issues/1340#issuecomment-101483570","issue_url":"https://api.github.com/repos/asciidoctor/asciidoctor/issues/1340","id":101483570,"user":{"login":"mojavelinux","id":79351,"avatar_url":"https://avatars.githubusercontent.com/u/79351?v=3","gravatar_id":"","url":"https://api.github.com/users/mojavelinux","html_url":"https://github.com/mojavelinux","followers_url":"https://api.github.com/users/mojavelinux/followers","following_url":"https://api.github.com/users/mojavelinux/following{/other_user}","gists_url":"https://api.github.com/users/mojavelinux/gists{/gist_id}","starred_url":"https://api.github.com/users/mojavelinux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mojavelinux/subscriptions","organizations_url":"https://api.github.com/users/mojavelinux/orgs","repos_url":"https://api.github.com/users/mojavelinux/repos","events_url":"https://api.github.com/users/mojavelinux/events{/privacy}","received_events_url":"https://api.github.com/users/mojavelinux/received_events","type":"User","site_admin":false},"created_at":"2015-05-13T02:14:17Z","updated_at":"2015-05-13T02:14:17Z","body":"I'd like to start out by saying that Asciidoctor is already ridiculously fast :) It's so inexpensive time-wise to convert a full document that attempts to short-circuit (and cache something) often result in a slower conversion.\r\n\r\nTo some degree, Asciidoctor already works the way you describe. Asciidoctor parses the block-level AsciiDoc content into an abstract syntax tree (AST). It then passes that to the converter, which translates the AST to the final format.\r\n\r\nThere are two limitations at the moment that keep the AST from being a true intermediary format. \r\n\r\n1) We are not parsing inline content into the AST prior to conversion. Instead, it happens in a streaming fashion (since that's how AsciiDoc Python worked). There are plans to fix this issue. See #61.\r\n\r\n2) The AST cannot be converted more than once without some slight side effects. This is due to the fact that document-level attributes are not stored as nodes in the tree. There are also plans to fix this issue. See #692.\r\n\r\nHaving said that, it's still possible to do what you are proposing. You can parse the document to an AST, then manipulate the AST to swap in dynamic or replacement content and convert again.\r\n\r\n```ruby\r\ndoc = Asciidoctor.load_file 'document.adoc', safe: :safe\r\nputs doc.convert\r\nlisting_1 = (doc.find_by context: :listing)[0]\r\nlisting_1.lines = 'public class Foo {\r\n}'.split(\"\\n\")\r\nputs doc.convert\r\n```"}}