[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] Patch for org-md, with optional GFM source code output
From: |
浅井 政太郎 |
Subject: |
[O] Patch for org-md, with optional GFM source code output |
Date: |
Mon, 06 May 2013 02:01:22 +0900 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 |
Hi all,
Not sure this will be accepted,
but personally it is very useful when I
output org to md and publish it with octopress.
I understood that the commits to org-mode should possess some quality.
Modified lisp/ox-md.el
diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index 61f42b8..4188694 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -89,7 +89,7 @@ This variable can be set to either `atx' or `setext'."
(quote-block . org-md-quote-block)
(quote-section . org-md-example-block)
(section . org-md-section)
- (src-block . org-md-example-block)
+ (src-block . org-md-src-block)
(template . org-md-template)
(verbatim . org-md-verbatim)))
@@ -142,7 +142,7 @@ channel."
value)))
-;;;; Example Block and Src Block
+;;;; Example Block
(defun org-md-example-block (example-block contents info)
"Transcode EXAMPLE-BLOCK element into Markdown format.
@@ -153,6 +153,61 @@ channel."
(org-remove-indentation
(org-element-property :value example-block))))
+;;;; Src Block
+
+(defcustom org-md-src-style 'indent
+ "Style used to format the source.
+This variable can be set to either `indent', `github-flavored'
+ or `octopress'.
+ For the information about github-flavored markdown, see
+\"https://help.github.com/articles/github-flavored-markdown\".
+
+The main difference between github-flavored and octopress is that
+the latter recognizes #+CAPTION as a title."
+ :group 'org-export-md
+ :type '(choice
+ (const :tag "Use ordinary markdown style" indent)
+ (const :tag "Use Github flavored markdown style"
+ github-flavored)
+ (const :tag "Use Octopress flavored markdown style"
+ octopress)))
+
+
+(defun %string-prop (prop block)
+ (let ((prop (org-element-property prop block)))
+ (if prop prop "")))
+
+(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."
+ (case org-md-src-style
+ (indent (org-md-example-block src-block contents info))
+ (github-flavored
+ (concatenate
+ 'string
+ "```"
+ (%string-prop :language src-block)
+ "\n"
+ (org-remove-indentation
+ (org-element-property :value src-block))
+ "```"))
+ (octopress
+ (concatenate
+ 'string
+ "```"
+ (%string-prop :language src-block)
+ " "
+ (let ((caption (org-element-property :caption src-block)))
+ (if caption
+ (org-export-data
+ (org-export-get-caption src-block) info)
+ ""))
+ "\n"
+ (org-remove-indentation
+ (org-element-property :value src-block))
+ "```"))))
+
;;;; Headline
--
浅井 政太郎
東京大学大学院 総合文化研究科広域システム科学科 1年
福永研究室(http://metahack.org/)
東京大学運動会自動車部
Tel: 044-856-9009
Mail: address@hidden
Website(private): http://guicho271828.github.io/
- [O] Patch for org-md, with optional GFM source code output,
浅井 政太郎 <=