1

I want to export an org-mode document to markdown. My document contains some content like this:

#+BEGIN_SRC
* User-defined Markers
** MARKER_1
#+END_SRC

I would like to demonstrate how someone could write something in an org-mode document, but when this is exported to markdown, it is interpreted as org-mode text, i.e. instead of seeing a gray code field, the export tries to structure the markdown using 'User-defined Markers' as a headline. Is there any way of exporting so that what's inside of #BEGIN_SRC is not evaluated?

6
  • Should source blocks open an escape route from the stars ?
    – Flint
    Apr 21, 2020 at 20:01
  • 1
    If you add the language header argument like #+BEGIN_SRC org you even get nice highlighting of the org source code when you export to HTML.
    – Tobias
    Apr 21, 2020 at 20:11
  • @Tobias Thanks for the tip about syntax highlighting, but the org-mode code inside the source blocks was still being evaluated when I exported. NickD's suggestion worked.
    – David J.
    Apr 22, 2020 at 6:29
  • 1
    Using #+BEGIN_SRC org was not a solution to your question but a comment what you could do additional to NickD's solution.
    – Tobias
    Apr 22, 2020 at 9:49
  • 1
    @DavidJ. if you use #+BEGIN_SRC org and then edit that block as usual with C-c C-c the , is added for you if needed and the export works as it should.
    – Hubisan
    Apr 22, 2020 at 20:32

1 Answer 1

3

Any lines that could be confused as Org mode markup (e.g. both of the lines in your example block) can be quoted by preceding them with a ,:

#+BEGIN_SRC
,* User-defined Markers
,** MARKER_1
#+END_SRC

See Literal Examples in the manual.

As @Tobias and @Hubisan point out in the comments, it's a very good idea to mark the source block as an org source block:

#+BEGIN_SRC org
,* User-defined Markers
,** MARKER_1
#+END_SRC

There are several advantages:

  • You get nice highlighting when exporting to HTML (and possibly other formats).
  • C-c ' (bound to org-edit-special) knows to edit the contents of the source block using the org-mode major mode. It also knows to strip the commas when entering and adding them back when exiting, so you don't have to worry about them any more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.