Re: [PATCH] Add org-md-src-block for src-block formater

2020-08-27 Thread Berry, Charles
You might want to browse the ox-ravel repository[1].

It provides a collection of exporters that support reformatting src blocks and 
inline src blocks for a variety of output formats (including markdown).

Basically, it will produce a derived backend that adds source block 
reformatting to whatever the parent backend provides.

It is aimed at R flavored exports (knitr, Rmarkdown, Sweave), but customizable. 
One can, for example, allow emacs-lisp and shell src blocks to execute during 
export, but format python, C++ and R blocks for markdown and subsequent 
processing. It is easy to apply to any markdown exporter

See ox-ravel.org for details on customization.

It has plenty of stops and whistles even without customization. Check out the 
examples, such as demos.org and markdown.org.


HTH,

Chuck  

[1] 
https://github.com/chasberry/orgmode-accessories/blob/org-9-plus/markdown.org

> On Aug 26, 2020, at 10:26 PM, Naoya Yamashita  wrote:
> 
> Hi,
> I found `ox-md` exporter drop src-block language information.
> My patch fixes the behavior; to embed src-block language information
> using markdown src block grammar.
> 
> 1. Open some buffer
> 2. Tnsert below code
> 3. Turn on `org-mode`
> 4. `C-c C-e m M` (export as markdown in temp buffer)
> 
> ## org source
> ```org
> #+begin_src python
> print(1 + 2)
> #+end_src
> 
> #+begin_src emacs-lisp
> (print "hello")
> #+end_src
> 
> #+begin_src
> something source code
> #+end_src
> ```
> 
> ## before
> ```markdown
> 
> # Table of Contents
> 
> 
> 
> print(1 + 2)
> 
> (print "hello")
> 
> something source code
> 
> ```
> 
> ## after
> ```markdown
> 
> # Table of Contents
> 
> 
> 
> ```python
> print(1 + 2)
> ```
> 
> ```emacs-lisp
> (print "hello")
> ```
> 
> ```
> something source code
> ```
> 
> ```
> <0001-Add-org-md-src-block-for-src-block-formater.patch>





Re: [PATCH] Add org-md-src-block for src-block formater

2020-08-27 Thread Naoya Yamashita
> This is a feature. "ox-md" exports to vanilla Markdown, which doesn't
> support such syntax. You may want to use other back-ends, e.g.,
> "ox-gfm".

Thanks for letting me know that. I would try it.

2020年8月27日(木) 14:34 Nicolas Goaziou :

> Hello,
>
> Naoya Yamashita  writes:
>
> > I found `ox-md` exporter drop src-block language information.
> > My patch fixes the behavior.
>
> This is a feature. "ox-md" exports to vanilla Markdown, which doesn't
> support such syntax. You may want to use other back-ends, e.g.,
> "ox-gfm".
>
> Regards,
> --
> Nicolas Goaziou
>


Re: [PATCH] Add org-md-src-block for src-block formater

2020-08-26 Thread Nicolas Goaziou
Hello,

Naoya Yamashita  writes:

> I found `ox-md` exporter drop src-block language information.
> My patch fixes the behavior.

This is a feature. "ox-md" exports to vanilla Markdown, which doesn't
support such syntax. You may want to use other back-ends, e.g.,
"ox-gfm".

Regards,
-- 
Nicolas Goaziou



[PATCH] Add org-md-src-block for src-block formater

2020-08-26 Thread Naoya Yamashita
Hi,
I found `ox-md` exporter drop src-block language information.
My patch fixes the behavior; to embed src-block language information
using markdown src block grammar.

1. Open some buffer
2. Tnsert below code
3. Turn on `org-mode`
4. `C-c C-e m M` (export as markdown in temp buffer)

## org source
```org
#+begin_src python
print(1 + 2)
#+end_src

#+begin_src emacs-lisp
(print "hello")
#+end_src

#+begin_src
something source code
#+end_src
```

## before
```markdown

# Table of Contents



print(1 + 2)

(print "hello")

something source code

```

## after
```markdown

# Table of Contents



```python
print(1 + 2)
```

```emacs-lisp
(print "hello")
```

```
something source code
```

```
From 0ffa1f8f6dede26b7f1e8ce4afc1fbcd2f45755b Mon Sep 17 00:00:00 2001
From: conao3 
Date: Thu, 27 Aug 2020 13:52:50 +0900
Subject: [PATCH] Add org-md-src-block for src-block formater

* lisp/ox-md.el (org-md-src-block): Add new formater for src block
* lisp/ox-md.el (org-export-define-derived-backend 'md): use it
---
 lisp/ox-md.el | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index 1d20c04f4..59db0c765 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -110,7 +110,7 @@ The %s will be replaced by the footnote reference itself."
 		 (quote-block . org-md-quote-block)
 		 (section . org-md-section)
 		 (special-block . org-md--convert-to-html)
-		 (src-block . org-md-example-block)
+		 (src-block . org-md-src-block)
 		 (table . org-md--convert-to-html)
 		 (template . org-md-template)
 		 (verbatim . org-md-verbatim))
@@ -331,6 +331,18 @@ channel."
(org-remove-indentation
 (org-export-format-code-default example-block info
 
+(defun org-md-src-block (src-block _contents info)
+  "Transcode SRC-BLOCK element into Markdown format.
+CONTENTS is nil.  INFO is a plist used as a communication
+channel."
+  (let ((lang (pcase (plist-get info :parse-tree)
+(`(org-data ,_ (section ,_ (src-block (:language ,l . ,_ l
+(format
+ "```%s\n%s```"
+ (or lang "")
+ (org-remove-indentation
+  (org-export-format-code-default src-block info)
+
 (defun org-md-export-block (export-block contents info)
   "Transcode a EXPORT-BLOCK element from Org to Markdown.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-- 
2.28.0