PageRenderTime 1610ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/html_code_syntax_highlight_examples/code-block-exports-no-color.org

https://github.com/wallyqs/org-ruby
Org | 466 lines | 375 code | 91 blank | 0 comment | 7 complexity | 2a583ed6285574ccbc3fb8256c94b249 MD5 | raw file
  1. #+TITLE: Support for :exports options from code blocks
  2. #+startup: showeverything
  3. According to the [[http://orgmode.org/manual/Exporting-code-blocks.html#Exporting-code-blocks][Org mode docs]], it is possible to customize whether
  4. the code block will be exported or not.
  5. * About the ~#+RESULTS:~ block
  6. Using Org Babel features, it is possible to set ~:results output~
  7. to a code block and render the results within a ~#+RESULTS:~ code block:
  8. #+begin_src org
  9. ,#+begin_src ruby :results output :exports both
  10. puts "Hello world"
  11. ,#+end_src
  12. ,#+RESULTS:
  13. : Hello world
  14. #+end_src
  15. One thing about the ~#+RESULTS:~ code blocks, is that they exist in several forms:
  16. 1) As an accumulated group of inline examples:
  17. #+begin_src org
  18. ,#+begin_src python :results output :exports both
  19. print "like"
  20. print "this"
  21. print "etc..."
  22. ,#+end_src
  23. ,#+RESULTS:
  24. : like
  25. : this
  26. : etc...
  27. #+end_src
  28. 2) As an example code block.
  29. #+begin_src org
  30. ,#+begin_src ruby :results output :exports both
  31. 10.times {|n| puts n }
  32. ,#+end_src
  33. ,#+RESULTS:
  34. ,#+begin_example
  35. 0
  36. 1
  37. 2
  38. 3
  39. 4
  40. 5
  41. 6
  42. 7
  43. 8
  44. 9
  45. ,#+end_example
  46. #+end_src
  47. 3) Also, in case ~:results output code~ is used, the results would
  48. be a src block of the same language as the original one.
  49. #+begin_src org
  50. ,#+begin_src ruby :results output code
  51. counter = 0
  52. 10.times { puts "puts '#{counter += 1}'" } # Displayed in first code block
  53. puts counter # Displayed in second code block
  54. ,#+end_src
  55. ,#+RESULTS:
  56. ,#+begin_src ruby
  57. puts '1'
  58. puts '2'
  59. puts '3'
  60. puts '4'
  61. puts '5'
  62. puts '6'
  63. puts '7'
  64. puts '8'
  65. puts '9'
  66. puts '10'
  67. 10
  68. ,#+end_src
  69. ,#+RESULTS:
  70. : 10
  71. #+end_src
  72. * DONE Default options
  73. The default is to export only the code blocks.
  74. The following is an code block written in Emacs Lisp
  75. and its result should not be exported.
  76. #+begin_src emacs-lisp
  77. (message "hello world")
  78. #+end_src
  79. #+RESULTS:
  80. : hello world
  81. The following is a code block written in Python
  82. and its result should not be exported.
  83. #+begin_src python :results output
  84. for i in range(0,12):
  85. print "import this"
  86. #+end_src
  87. #+RESULTS:
  88. #+begin_example
  89. import this
  90. import this
  91. import this
  92. import this
  93. import this
  94. import this
  95. import this
  96. import this
  97. import this
  98. import this
  99. import this
  100. import this
  101. #+end_example
  102. * DONE :exports code
  103. Only the code would be in the output,
  104. the same as when no option is set.
  105. #+begin_src js :exports code :results output
  106. var message = "Hello world!";
  107. console.log(message);
  108. #+end_src
  109. #+RESULTS:
  110. : Hello world!
  111. And as block example too:
  112. #+begin_src js :exports code :results output
  113. var message = "Hello world!";
  114. for (var i = 0; i< 10; i++) {
  115. console.log(message);
  116. }
  117. #+end_src
  118. #+RESULTS:
  119. #+begin_example
  120. Hello world!
  121. Hello world!
  122. Hello world!
  123. Hello world!
  124. Hello world!
  125. Hello world!
  126. Hello world!
  127. Hello world!
  128. Hello world!
  129. Hello world!
  130. #+end_example
  131. * DONE :exports none
  132. This omits both the resulting block,
  133. and the code block itself.
  134. #+begin_src python :results output :exports none
  135. print 1 # :P
  136. #+end_src
  137. #+RESULTS:
  138. : 1
  139. This should work as well when using an example block.
  140. #+begin_src python :results output :exports none
  141. for i in range(0,10):
  142. print 1 # :P
  143. #+end_src
  144. #+RESULTS:
  145. #+begin_example
  146. 1
  147. 1
  148. 1
  149. 1
  150. 1
  151. 1
  152. 1
  153. 1
  154. 1
  155. 1
  156. #+end_example
  157. * DONE :exports both
  158. #+begin_src ruby :exports both
  159. Math::PI + 1
  160. #+end_src
  161. #+RESULTS:
  162. : 4.14159265358979
  163. Should behave the same when within a block example.
  164. #+begin_src ruby :exports both
  165. hello = <<HELLO
  166. The following is a text
  167. that will contain at least 10 lines or more
  168. so that when C-c C-c is pressed
  169. and Emacs lisp
  170. evals what is inside of the block,
  171. enough lines would be created
  172. such that an example block
  173. would appear underneath the
  174. block that was executed.
  175. This happens after 10 lines by default.
  176. HELLO
  177. #+end_src
  178. #+RESULTS:
  179. #+begin_example
  180. The following is a text
  181. that will contain at least 10 lines or more
  182. so that when C-c C-c is pressed
  183. and Emacs lisp
  184. evals what is inside of the block,
  185. enough lines would be created
  186. such that an example block
  187. would appear underneath the
  188. block that was executed.
  189. This happens after 10 lines by default.
  190. #+end_example
  191. * DONE :exports results
  192. This option can't be completely supported by OrgRuby since
  193. we would have to eval the code block using :lang,
  194. so Org Babel features would have to be implemented as well.
  195. But in case the resulting block is within the Org mode file,
  196. the code block will be omitted and only the results block
  197. would appear.
  198. #+begin_src ruby :exports results
  199. Math::PI
  200. #+end_src
  201. #+RESULTS:
  202. : 3.141592653589793
  203. The same should happen when a block example is used instead:
  204. #+begin_src ruby :results output :exports results
  205. 10.times { puts "any string" }
  206. #+end_src
  207. #+RESULTS:
  208. #+begin_example
  209. any string
  210. any string
  211. any string
  212. any string
  213. any string
  214. any string
  215. any string
  216. any string
  217. any string
  218. any string
  219. #+end_example
  220. * DONE When results are graphics...
  221. A code block which is evaled within a Org mode buffer
  222. using Org babel features will have its results appear within
  223. another code block prepended with a ~#+RESULTS~ directive.
  224. A results block could also not be another example block,
  225. and just consist from a link to a file. This happens
  226. when the output is a graphic for example:
  227. - Exports none
  228. #+begin_src dot :exports none :results graphics :file workflow.png
  229. digraph workflow {
  230. a -> c;
  231. b -> c;
  232. }
  233. #+end_src
  234. #+RESULTS:
  235. [[file:workflow.png]]
  236. - Exports code
  237. #+begin_src dot :exports code :results graphics :file workflow.png
  238. digraph workflow {
  239. a -> c;
  240. b -> c;
  241. }
  242. #+end_src
  243. #+RESULTS:
  244. [[file:workflow.png]]
  245. - Exports both
  246. #+begin_src dot :exports both :results graphics :file workflow.png
  247. digraph workflow {
  248. a -> c;
  249. b -> c;
  250. }
  251. #+end_src
  252. #+RESULTS:
  253. [[file:workflow.png]]
  254. - Exports results
  255. #+begin_src dot :exports results :results graphics :file workflow.png
  256. digraph workflow {
  257. a -> c;
  258. b -> c;
  259. }
  260. #+end_src
  261. #+RESULTS:
  262. [[file:workflow.png]]
  263. * When blocks have a name, the results should be the same
  264. ** exports code
  265. #+name: hello_js_exports_code_short
  266. #+begin_src js :exports code :results output
  267. var message = "Hello world!";
  268. console.log(message);
  269. #+end_src
  270. #+RESULTS: hello_js_exports_code_short
  271. : Hello world!
  272. #+name: hello_js_exports_code_long
  273. #+begin_src js :exports code :results output
  274. var message = "Hello world!";
  275. for (var i = 0; i< 10; i++) {
  276. console.log(message);
  277. }
  278. #+end_src
  279. #+RESULTS: hello_js_exports_code_long
  280. #+begin_example
  281. Hello world!
  282. Hello world!
  283. Hello world!
  284. Hello world!
  285. Hello world!
  286. Hello world!
  287. Hello world!
  288. Hello world!
  289. Hello world!
  290. Hello world!
  291. #+end_example
  292. ** exports none
  293. #+name: hello_python_exports_none_short
  294. #+begin_src python :results output :exports none
  295. print 1 # :P
  296. #+end_src
  297. #+RESULTS: hello_python_exports_none_short
  298. : 1
  299. #+name: hello_python_exports_none_long
  300. #+begin_src python :results output :exports none
  301. for i in range(0,10):
  302. print 1 # :P
  303. #+end_src
  304. #+RESULTS: hello_python_exports_none_long
  305. #+begin_example
  306. 1
  307. 1
  308. 1
  309. 1
  310. 1
  311. 1
  312. 1
  313. 1
  314. 1
  315. 1
  316. #+end_example
  317. ** exports both
  318. #+name: hello_ruby_exports_both_short
  319. #+begin_src ruby :exports both
  320. Math::PI + 1
  321. #+end_src
  322. #+RESULTS: hello_ruby_exports_both_short
  323. : 4.141592653589793
  324. #+name: hello_ruby_exports_both_long
  325. #+begin_src ruby :exports both
  326. hello = <<HELLO
  327. The following is a text
  328. that will contain at least 10 lines or more
  329. so that when C-c C-c is pressed
  330. and Emacs lisp
  331. evals what is inside of the block,
  332. enough lines would be created
  333. such that an example block
  334. would appear underneath the
  335. block that was executed.
  336. This happens after 10 lines by default.
  337. HELLO
  338. #+end_src
  339. #+RESULTS: hello_ruby_exports_both_long
  340. #+begin_example
  341. The following is a text
  342. that will contain at least 10 lines or more
  343. so that when C-c C-c is pressed
  344. and Emacs lisp
  345. evals what is inside of the block,
  346. enough lines would be created
  347. such that an example block
  348. would appear underneath the
  349. block that was executed.
  350. This happens after 10 lines by default.
  351. #+end_example
  352. ** exports results
  353. #+name: hello_ruby_exports_results_short
  354. #+begin_src ruby :exports results
  355. Math::PI
  356. #+end_src
  357. #+RESULTS: hello_ruby_exports_results_short
  358. : 3.141592653589793
  359. #+name: hello_ruby_exports_results_long
  360. #+begin_src ruby :results output :exports results
  361. 10.times { puts "any string" }
  362. #+end_src
  363. #+RESULTS: hello_ruby_exports_results_long
  364. #+begin_example
  365. any string
  366. any string
  367. any string
  368. any string
  369. any string
  370. any string
  371. any string
  372. any string
  373. any string
  374. any string
  375. #+end_example