emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "浅井 政太郎" <guicho2.71828@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Patch for org-md, with optional GFM source code output
Date: Mon, 06 May 2013 02:01:22 +0900	[thread overview]
Message-ID: <51869062.7010701@gmail.com> (raw)

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: guicho2.71828@gmail.com
Website(private): http://guicho271828.github.io/

             reply	other threads:[~2013-05-05 17:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-05 17:01 浅井 政太郎 [this message]
2013-05-05 17:49 ` Patch for org-md, with optional GFM source code output Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51869062.7010701@gmail.com \
    --to=guicho2.71828@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).