PageRenderTime 81ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/html_code_syntax_highlight_examples/code-block-exports-pygments.html

https://github.com/wallyqs/org-ruby
HTML | 165 lines | 159 code | 6 blank | 0 comment | 0 complexity | ed670de6017eaa3e10ed62023d5ea53b MD5 | raw file
  1. <h1 class="title">Support for :exports options from code blocks</h1>
  2. <p>According to the <a href="http://orgmode.org/manual/Exporting-code-blocks.html#Exporting-code-blocks">Org mode docs</a>, it is possible to customize whether
  3. the code block will be exported or not.</p>
  4. <h1>About the <code>#+RESULTS:</code> block</h1>
  5. <p>Using Org Babel features, it is possible to set <code>:results output</code>
  6. to a code block and render the results within a <code>#+RESULTS:</code> code block:</p>
  7. <div class="highlight"><pre><span></span>#+begin_src ruby :results output :exports both
  8. puts &quot;Hello world&quot;
  9. #+end_src
  10. #+RESULTS:
  11. : Hello world
  12. </pre></div>
  13. <p>One thing about the <code>#+RESULTS:</code> code blocks, is that they exist in several forms:</p>
  14. <ol>
  15. <li>As an accumulated group of inline examples:
  16. <div class="highlight"><pre><span></span>#+begin_src python :results output :exports both
  17. print &quot;like&quot;
  18. print &quot;this&quot;
  19. print &quot;etc...&quot;
  20. #+end_src
  21. #+RESULTS:
  22. : like
  23. : this
  24. : etc...
  25. </pre></div>
  26. </li>
  27. <li>As an example code block.
  28. <div class="highlight"><pre><span></span>#+begin_src ruby :results output :exports both
  29. 10.times {|n| puts n }
  30. #+end_src
  31. #+RESULTS:
  32. #+begin_example
  33. 0
  34. 1
  35. 2
  36. 3
  37. 4
  38. 5
  39. 6
  40. 7
  41. 8
  42. 9
  43. #+end_example
  44. </pre></div>
  45. </li>
  46. <li>Also, in case <code>:results output code</code> is used, the results would
  47. be a src block of the same language as the original one.
  48. <div class="highlight"><pre><span></span>#+begin_src ruby :results output code
  49. counter = 0
  50. 10.times { puts &quot;puts &#39;#{counter += 1}&#39;&quot; } # Displayed in first code block
  51. puts counter # Displayed in second code block
  52. #+end_src
  53. #+RESULTS:
  54. #+begin_src ruby
  55. puts &#39;1&#39;
  56. puts &#39;2&#39;
  57. puts &#39;3&#39;
  58. puts &#39;4&#39;
  59. puts &#39;5&#39;
  60. puts &#39;6&#39;
  61. puts &#39;7&#39;
  62. puts &#39;8&#39;
  63. puts &#39;9&#39;
  64. puts &#39;10&#39;
  65. 10
  66. #+end_src
  67. #+RESULTS:
  68. : 10
  69. </pre></div>
  70. </li>
  71. </ol>
  72. <h1>Default options</h1>
  73. <p>The default is to export only the code blocks.</p>
  74. <p>The following is an code block written in Emacs Lisp
  75. and its result should not be exported.</p>
  76. <div class="highlight"><pre><span></span><span class="p">(</span><span class="nf">message</span> <span class="s">&quot;hello world&quot;</span><span class="p">)</span>
  77. </pre></div>
  78. <p>The following is a code block written in Python
  79. and its result should not be exported.</p>
  80. <div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">12</span><span class="p">):</span>
  81. <span class="k">print</span> <span class="s2">&quot;import this&quot;</span>
  82. </pre></div>
  83. <p>
  84. </p>
  85. <h1>:exports code</h1>
  86. <p>Only the code would be in the output,
  87. the same as when no option is set.</p>
  88. <div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">message</span> <span class="o">=</span> <span class="s2">&quot;Hello world!&quot;</span><span class="p">;</span>
  89. <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">message</span><span class="p">);</span>
  90. </pre></div>
  91. <p>And as block example too:</p>
  92. <div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">message</span> <span class="o">=</span> <span class="s2">&quot;Hello world!&quot;</span><span class="p">;</span>
  93. <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span><span class="o">&lt;</span> <span class="mi">10</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
  94. <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">message</span><span class="p">);</span>
  95. <span class="p">}</span>
  96. </pre></div>
  97. <p>
  98. </p>
  99. <h1>:exports none</h1>
  100. <p>This omits both the resulting block,
  101. and the code block itself.</p>
  102. <p>This should work as well when using an example block.</p>
  103. <p>
  104. </p>
  105. <h1>:exports both</h1>
  106. <div class="highlight"><pre><span></span><span class="no">Math</span><span class="o">::</span><span class="no">PI</span> <span class="o">+</span> <span class="mi">1</span>
  107. </pre></div>
  108. <pre class="example">
  109. 4.14159265358979
  110. </pre>
  111. <p>Should behave the same when within a block example.</p>
  112. <div class="highlight"><pre><span></span><span class="n">hello</span> <span class="o">=</span> <span class="o">&lt;&lt;</span><span class="dl">HELLO</span>
  113. <span class="sh">The following is a text</span>
  114. <span class="sh">that will contain at least 10 lines or more</span>
  115. <span class="sh">so that when C-c C-c is pressed</span>
  116. <span class="sh">and Emacs lisp</span>
  117. <span class="sh">evals what is inside of the block,</span>
  118. <span class="sh">enough lines would be created</span>
  119. <span class="sh">such that an example block </span>
  120. <span class="sh">would appear underneath the</span>
  121. <span class="sh">block that was executed.</span>
  122. <span class="sh">This happens after 10 lines by default.</span>
  123. <span class="dl">HELLO</span>
  124. </pre></div>
  125. <pre class="example">
  126. The following is a text
  127. that will contain at least 10 lines or more
  128. so that when C-c C-c is pressed
  129. and Emacs lisp
  130. evals what is inside of the block,
  131. enough lines would be created
  132. such that an example block
  133. would appear underneath the
  134. block that was executed.
  135. This happens after 10 lines by default.
  136. </pre>
  137. <h1>:exports results</h1>
  138. <p>This option can&#8217;t be completely supported by OrgRuby since
  139. we would have to eval the code block using :lang,
  140. so Org Babel features would have to be implemented as well.</p>
  141. <p>But in case the resulting block is within the Org mode file,
  142. the code block will be omitted and only the results block
  143. would appear.</p>
  144. <pre class="example">
  145. 3.141592653589793
  146. </pre>
  147. <p>The same should happen when a block example is used instead:</p>
  148. <pre class="example">
  149. any string
  150. any string
  151. any string
  152. any string
  153. any string
  154. any string
  155. any string
  156. any string
  157. any string
  158. any string
  159. </pre>