0

I am taking notes on a course in org-mode. I am using HTML source-blocks to write down examples of html code. This serves me because I have text and code in one file and it will be easier to export it to a blog for example.

#+begin_src html
  #some html code
#+end_src 

However, sometimes I want to test the code in a source block and would want to export it to a separate html file. Any tipps on how to achieve this quickly? Exporting via C-c C-e h o always exports the whole buffer or the subtree. But I want to export only the code in the source block.

Any tipps on how to do this?

1
  • Search for Tangling in the Org mode manual: do C-h i g (org)Extracting Source Code RET.
    – NickD
    Commented Feb 28, 2021 at 13:09

2 Answers 2

1

C-c C-v C-t runs org-babel-tangle and exports all code blocks to the current buffer name plus the correct code extension (e.g. html blocks get .html, python blocks get .py). You can specify the tangled filename with the :tangle property at the header, section, or file level.

Run C-u C-c C-v C-t to only tangle the current code block containing the point.

0

Just realized the answer to my question:

hit C-c ' for org-edit-special and then save the buffer to a new file.

2
  • 3
    Faster: C-v C-v C-t runs org-babel-tangle. Add the prefix arg C-u to only tangle the current babel block
    – mankoff
    Commented Feb 28, 2021 at 15:10
  • @mankoff: please make your comment into an answer (adding some detail if you can).
    – NickD
    Commented Mar 2, 2021 at 20:51

Your Answer

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

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