emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ox-md.el: enhance example/src blocks support
@ 2016-12-14 10:17 Lungang Fang
  2016-12-14 12:22 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Lungang Fang @ 2016-12-14 10:17 UTC (permalink / raw)
  To: emacs-orgmode

* lisp/ox-md.el (org-md-example-block):
Use "```" instead of 4-whitespace indentation for example/src blocks.
The 4-whitespace has difficulty handling blocks under list items.
The new code also allows syntax highlights for Programming languages

The following org mode snippet is a test input:

- Python src block within a list item
  #+BEGIN_SRC python
    for each in collection.find():
        count += 1
    print "Total number:", count
  #+END_SRC

#+BEGIN_EXAMPLE
  OOPS! This is a first level example block
#+END_EXAMPLE

Output of the old version of org-md-example-block does not show as expected
in Salsforce case editor or MacDown (http://macdown.uranusjr.com).

In comparsion, it is coverted to the following by the new version and is
handled by Salsforce and MacDown as expected:

-   Python src block within a list item

    ```python
    for each in collection.find():
        count += 1
    print "Total number:", count
    ```

```
OOPS! This is a first level example block
```

TINYCHANGE
---
 lisp/ox-md.el | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index b8c4704..a176a8f 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -181,10 +181,11 @@ channel."
   "Transcode EXAMPLE-BLOCK element into Markdown format.
 CONTENTS is nil.  INFO is a plist used as a communication
 channel."
-  (replace-regexp-in-string
-   "^" "    "
-   (org-remove-indentation
-    (org-export-format-code-default example-block info))))
+  (concat
+   "```" (org-element-property :language example-block)
+   "\n"
+   (org-export-format-code-default example-block info)
+   "```"))

 (defun org-md-export-block (export-block contents info)
   "Transcode a EXPORT-BLOCK element from Org to Markdown.
-- 
2.9.3 (Apple Git-75)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-12-14 21:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-14 10:17 [PATCH] ox-md.el: enhance example/src blocks support Lungang Fang
2016-12-14 12:22 ` Nicolas Goaziou
2016-12-14 21:43   ` Lungang Fang

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).