title: Org-mode get the content of src block during export
body: <p>Here's what I'm trying to do:</p>
  
  <p>I have a snippet of JavaScript code that I want to both display in the HTML generated from an org document and I want that code to be executed in the HTML page. For a simplistic example, let it be something like</p>
  
  <pre><code>  #+NAME: block-name
    #+BEGIN_SRC javascript
    alert("Ding!");
    #+END_SRC
  
    #+NAME: insert-script
    #+BEGIN_SRC emacs-lisp :export results
    (format "&lt;script type=\"text/javascript\"&gt;%s&lt;/script&gt;" block-name)
    #+END_SRC
  
    #+CALL: insert-script()
  </code></pre>
  
  <p>But this complains about undefined symbol <code>block-name</code>. </p>
  
  <p>I've found this question, which is very similar, but the answer given there doesn't work for me. <a href="https://stackoverflow.com/questions/9074967/make-the-source-code-from-one-code-block-the-input-to-another-code-block-in-emac">Make the source code from one code block the input to another code block in Emacs org-mode</a></p>
  
  <p>What is the syntax for referring to the content / name of the block?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I'm getting closer, but still not there:</p>
  
  <pre><code>   #+NAME: block-name
     #+BEGIN_SRC javascript :exports code
     alert("Ding!");
     #+END_SRC
  
     #+BEGIN_SRC emacs-lisp :exports results :var script=block-name
     (print (format "&lt;script type=\"text/javascript\"&gt;%s&lt;/script&gt;" script))
     #+END_SRC
  
     #+RESULTS:
  </code></pre>
  
  <p>This has two problems. The value of <code>script</code> variable is <code>nil</code> and the script tags are being escaped (angle brackets being replaced by <code>&amp;lt;</code> and <code>&amp;gt;</code>. I could find this particular case of replacement by putting the script tags outside the evaluation, but I won't be able to prevent this as a general rule (if there is a less-then or greater-then signs in the script, they will get replaced).</p>
  
  <p><strong>EDIT1:</strong></p>
  
  <p>Almost there!</p>
  
  <p>Advised the <code>org-babel-get-src-block-info</code> to have it store locally the content of the block of code, if it is named into a variable <code>&lt;name&gt;-text</code>, so I can get it later.</p>
  
  <pre><code>(defadvice org-babel-get-src-block-info (after org-babel-store-info)
    (let* ((info-copy ad-return-value)
           (block-name (nth 4 info-copy))
           (block-text (nth 1 info-copy)))
      (when block-name
        (set (make-local-variable
              (intern (format "%s-text" block-name))) block-text))
      info-copy))
  (ad-activate 'org-babel-get-src-block-info)
  </code></pre>
  
  <p>Example usage:</p>
  
  <pre><code>   #+NAME: block-name
     #+BEGIN_SRC javascript :exports code
     alert("Ding!");
     #+END_SRC
  
     #+NAME: insert-script
     #+BEGIN_SRC emacs-lisp :exports results :results html
       (print (format "&lt;script type=\"text/javascript\"&gt;%s&lt;/script&gt;"
                      block-name-text))
     #+END_SRC
  
     #+RESULTS:
  </code></pre>
  
  <p>The escaping is handled with <code>:results html</code> option - this causes Org to insert the HTML literally.</p>
  
  <hr>
  
  <pre><code>  #+NAME: math
    #+BEGIN_SRC js :exports none :noweb yes
      // Logarithm of base two:
      var y = Math.log(x) / Math.log(2);
    #+END_SRC
  
    #+BEGIN_SRC emacs-lisp :tagnle example :exports results :noweb yes :results html
      (print (format "&lt;script&gt;%s&lt;/script&gt;" "&lt;&lt;math&gt;&gt;"))
    #+END_SRC
  
    #+RESULTS:
  </code></pre>
  
  <p>Here's the minimal example that fails.</p>
  
  <p>but this will work and produce the "expected" result:</p>
  
  <pre><code>  #+NAME: math
    #+BEGIN_SRC js :exports none :noweb yes
      // Logarithm of base two:
      var y = Math.log(x) / Math.log(2);
    #+END_SRC
  
    #+BEGIN_SRC emacs-lisp :tagnle example :exports both :noweb yes :results html
      ; &lt;&lt;math&gt;&gt;
      (print (format "&lt;script&gt;%s&lt;/script&gt;" "your script could be here"))
    #+END_SRC
  </code></pre>
  
  <p>with the output of <code>&lt;script&gt;your script could be here&lt;/script&gt;</code> and the JavaScript code in the comments of eLisp code block.</p>