Sorry for not attaching the files. Here they are.

# Table of Contents



When exporting the following code block using indentation, it is not
possible to know where the source code ends and the results of
evaluation starts.

    echo "echo ab"
    echo "seq 1 2"

    echo ab
    seq 1 2

The language of the following code block will be `sh` because `dash`
doesn't belong to `org-md-lang-export`

    result=0
    
    for i in $(seq 1 5)
    do
      for j in $(seq 1 5)
      do
        result=$((result + i + j))
      done
    done
    
    echo "$result"

    150

The language of the following code block will be the same as the one
used in Org Mode because `R` doesn't belong to `org-md-lang-export`

    data(Loblolly)
    
    max(Loblolly $ height)

    [1] 64.1

# Table of Contents



When exporting the following code block using indentation, it is not
possible to know where the source code ends and the results of
evaluation starts.

```sh
echo "echo ab"
echo "seq 1 2"
```

```
echo ab
seq 1 2
```

The language of the following code block will be `sh` because `dash`
doesn't belong to `org-md-lang-export`

```sh
result=0

for i in $(seq 1 5)
do
  for j in $(seq 1 5)
  do
    result=$((result + i + j))
  done
done

echo "$result"
```

```
150
```

The language of the following code block will be the same as the one
used in Org Mode because `R` doesn't belong to `org-md-lang-export`

```R
data(Loblolly)

max(Loblolly $ height)
```

```
[1] 64.1
```

Attachment: mre.org
Description: Lotus Organizer

--- ox-md.el	2021-01-28 22:18:51.566067501 -0500
+++ ox-md-patched.el	2021-01-28 22:14:34.762735829 -0500
@@ -50,6 +50,14 @@
 	  (const :tag "Use \"atx\" style" atx)
 	  (const :tag "Use \"Setext\" style" setext)))
 
+(defcustom org-md-lang-export
+  '(("dash" . "sh"))
+  "Alist mapping languages to the corresponding language names in Markdown."
+  :group 'org-export-md
+  :type '(repeat
+	  (cons
+	   (string "Org Mode language name")
+	   (string "Markdown language name"))))
 
 ;;;; Footnotes
 
@@ -181,10 +189,24 @@
   "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))))
+  (let* (language
+	 (org-language
+	  (plist-get (car (cdr example-block)) :language))
+	 (markdown-language
+	  (cdr (assoc org-language org-md-lang-export))) ;
+	 (content
+	  (org-remove-indentation
+	   (org-export-format-code-default example-block info))))
+
+    (if markdown-language
+	(setq language markdown-language)
+      (setq language org-language))
+
+    (setq content (replace-regexp-in-string
+                   "\\`" (concat "```" language "\n")
+                   content))
+    
+    (replace-regexp-in-string "\\'" "```" content)))
 
 (defun org-md-export-block (export-block contents info)
   "Transcode a EXPORT-BLOCK element from Org to Markdown.
-- 
Greetings,
Rodrigo Morales.

Reply via email to