From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?B?5rWF5LqVIOaUv+WkqumDjg==?= Subject: Patch for org-md, with optional GFM source code output Date: Mon, 06 May 2013 02:01:22 +0900 Message-ID: <51869062.7010701@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([208.118.235.92]:52222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZ2Jb-000479-7C for emacs-orgmode@gnu.org; Sun, 05 May 2013 13:01:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZ2JY-00017x-P9 for emacs-orgmode@gnu.org; Sun, 05 May 2013 13:01:35 -0400 Received: from mail-pb0-x22a.google.com ([2607:f8b0:400e:c01::22a]:63103) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZ2JY-00017s-HZ for emacs-orgmode@gnu.org; Sun, 05 May 2013 13:01:32 -0400 Received: by mail-pb0-f42.google.com with SMTP id up7so1614547pbc.1 for ; Sun, 05 May 2013 10:01:31 -0700 (PDT) Received: from [192.168.11.7] (h115-165-95-014.catv02.itscom.jp. [115.165.95.14]) by mx.google.com with ESMTPSA id ya4sm20304320pbb.24.2013.05.05.10.01.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 05 May 2013 10:01:30 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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/