3

I'm trying to post a babel src block that contains a babel definition since I am documenting some babel source blocks in a Hugo post written in org mode.

What I want to do is the following:

#+BEGIN_SRC
#+BEGIN_SRC dot :file my_output_file.png :cmdline -Kdot -Tpng
digraph G {
  my_start -> one_branch;
  my_start -> another_branch;
}
#+END_SRC
#+END_SRC

And the output I'd like to achieve when exporting is:

#+BEGIN_SRC dot :file my_output_file.png :cmdline -Kdot -Tpng
digraph G {
  my_start -> one_branch;
  my_start -> another_branch;
}
#+END_SRC

BUt what I get instead is

#+BEGIN_SRC dot :file my_output_file.png :cmdline -Kdot -Tpng
digraph G {
  my_start -> one_branch;
  my_start -> another_branch;
}

Since the first #+END_SRC finishes the code block.

Is there any way to escape the #+END_SRC so I can have my src block as I expect?

Thanks a lot!

Rafa de Castro
  • 1,231
  • 10
  • 14

2 Answers2

3

In general, you can include any orgmode inside a literal example (SRC or EXAMPLE blocks, or even headings).

You may need to escape headings and block delimiters with a comma. This escaping is done automatically if you edit your block in a separate buffer via C-c '.

Documentation here.

Example of block with escaped heading and source block:

* Test

#+begin_src org
  ,* this is a heading

  The following is a source code example

  ,#+begin_src emacs-lisp
  (+ 1 2 3 4)
  ,#+end_src

  ,#+RESULTS:
  : 10
#+end_src
Juancho
  • 5,455
  • 16
  • 20
1

Do you need the outer block to be a SRC block? The standard way I think of doing what you want is like this:

#+BEGIN_EXAMPLE
#+BEGIN_SRC dot ...
...
#+END_SRC
#+END_EXAMPLE
NickD
  • 29,717
  • 3
  • 27
  • 44