I'd like to import a source code file (for a language such as e.g. python) into an org-mode file so that the comments in the source file become org-mode text (markdown) and the codes between comments become code blocks of the same language. Basically, this converts a source code into a Literate Programming format. It is in a sense "org file extraction" and the inverse of tangling.
Is there an automatic (or close to automatic) way to do such conversions in org-mode?
(This is with org-mode 9.4.6, Emacs 27, Ubuntu 20.04)
awk
program (e.g.) should be able to produce the Org mode file: you just switch between two states (in-comment
andin-code
) and in each state you read as much of the file as conforms to the current state; when you get to the part that does not conform, you output the block (with some transformations, e.g. strip comment markers in one case or surround the block with source code markers in the other), switch state and continue.