* Patch for org-md, with optional GFM source code output
@ 2013-05-05 17:01 浅井 政太郎
2013-05-05 17:49 ` Nicolas Goaziou
0 siblings, 1 reply; 2+ messages in thread
From: 浅井 政太郎 @ 2013-05-05 17:01 UTC (permalink / raw)
To: emacs-orgmode
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/
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: Patch for org-md, with optional GFM source code output
2013-05-05 17:01 Patch for org-md, with optional GFM source code output 浅井 政太郎
@ 2013-05-05 17:49 ` Nicolas Goaziou
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2013-05-05 17:49 UTC (permalink / raw)
To: 浅井 政太郎; +Cc: emacs-orgmode
Hello,
浅井 政太郎 <guicho2.71828@gmail.com> writes:
> Not sure this will be accepted,
> but personally it is very useful when I
> output org to md and publish it with octopress.
Thanks for your patch. Though, the very point of ox-md.el is to produce
vanilla flavour, not Octopress' or Github's.
You could create a derived back-end from it instead, e.g.
ox-md-octopress.el and request to put it in contrib directory. See
`org-export-define-derived-backend' for details.
> +(defun %string-prop (prop block)
> + (let ((prop (org-element-property prop block)))
> + (if prop prop "")))
This is not needed (and the namespace used is wrong: it should be
prefixed with `org-md-....' since there's no module in elisp). I suggest
to use `org-string-nw-p' instead.
> +(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
`concat' is sufficient here.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-05-05 17:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-05 17:01 Patch for org-md, with optional GFM source code output 浅井 政太郎
2013-05-05 17:49 ` Nicolas Goaziou
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).