all messages for Emacs-related lists mirrored at yhetil.org
 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

* Re: [PATCH] ox-md.el: enhance example/src blocks support
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2016-12-14 12:22 UTC (permalink / raw)
  To: Lungang Fang; +Cc: emacs-orgmode

Hello,

Lungang Fang <lungang.fang@gmail.com> writes:

> * lisp/ox-md.el (org-md-example-block):
> Use "```" instead of 4-whitespace indentation for example/src blocks.

Thank you.

Unfortunately, this syntax is not recognized in vanilla Markdown syntax
(http://daringfireball.net/projects/markdown/syntax#precode), which
"ox-md.el" handles.

For special needs, you can create a derived back-end. There is already
"ox-gfm.el" somewhere.

Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] ox-md.el: enhance example/src blocks support
  2016-12-14 12:22 ` Nicolas Goaziou
@ 2016-12-14 21:43   ` Lungang Fang
  0 siblings, 0 replies; 3+ messages in thread
From: Lungang Fang @ 2016-12-14 21:43 UTC (permalink / raw)
  To: Lungang Fang, emacs-orgmode

Hi Nicolas,

On Wed, Dec 14, 2016 at 11:22 PM, Nicolas Goaziou
<mail@nicolasgoaziou.fr> wrote:
> Unfortunately, this syntax is not recognized in vanilla Markdown syntax
> (http://daringfireball.net/projects/markdown/syntax#precode), which
> "ox-md.el" handles.
>
> For special needs, you can create a derived back-end. There is already
> "ox-gfm.el" somewhere.

Thank you. ox-gfm.el and seems to be what I am looking for.

Regards,
Lungang

^ permalink raw reply	[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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.