I can export Markdown from Org (using C-c C-e) but #+BEGIN_SRC lang ... #+END_SRC is not exported as i expected as: ```lang ... ```.

I would like that the code source will be replaced with ``` (markdown syntax), any suggestion?

  • I don't know whether tagging source code blocks with languages is standardized in markdown, and whether language names are consistent. Your best bet is probably looking through ox-md.el and looking whether there's any option to customize it the way you like it. – DoMiNeLa10 Jul 10 '18 at 16:07

You could also just use ox-pandoc, which does all this properly. Though you need to have pandoc installed.


I have found a workaround using ox-gfm


It is relatively simple to derive a new exporter backend (e.g., mymd) from the md backend and only override the translation function for example blocks.

The function org-mymd-example-block formats its elements as you like it.

All other functions in the following elisp code are almost verbatim copies from ox-md.el and one only needs to steal a small part of ox-md.el. All other stuff is automatically inherited from the md backend.

(org-export-define-derived-backend 'mymd 'md
  '(?y "Export to My Markdown"
       ((?M "To temporary buffer"
            (lambda (a s v b) (org-mymd-export-as-markdown a s v)))
        (?m "To file" (lambda (a s v b) (org-mymd-export-to-markdown a s v)))
        (?o "To file and open"
            (lambda (a s v b)
              (if a (org-mymd-export-to-markdown t s v)
                (org-open-file (org-mymd-export-to-markdown nil s v)))))))
  :translate-alist '((example-block . org-mymd-example-block)
                     (fixed-width . org-mymd-example-block)
                     (src-block . org-mymd-example-block)))

(defun org-mymd-example-block (example-block _content info)
  "Transcode element EXAMPLE-BLOCK as ```lang ...'''."
  (format "```%s\n%s\n'''"
          (org-element-property :language example-block)
           (org-export-format-code-default example-block info))))

(defun org-mymd-export-as-markdown (&optional async subtreep visible-only)
  "See `org-md-export-as-markdown'."
  (org-export-to-buffer 'mymd "*Org My MD Export*"
    async subtreep visible-only nil nil (lambda () (text-mode))))

(defun org-mymd-convert-region-to-md ()
  "See `org-md-convert-region-to-md'."
  (org-export-replace-region-by 'mymd))

(defun org-mymd-export-to-markdown (&optional async subtreep visible-only)
  "See `org-md-export-to-markdown'."
  (let ((outfile (org-export-output-file-name ".md" subtreep)))
    (org-export-to-file 'mymd outfile async subtreep visible-only)))

(defun org-mymd-publish-to-md (plist filename pub-dir)
  "Analogous to `org-md-publish-to-md'."
  (org-publish-org-to 'mymd filename ".md" plist pub-dir))

An alternative would be to write an :override advice for org-md-example-block. You can use org-mymd-example-block above as replacement of org-md-example-block. But in that way you loose the original md backend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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