From 536c55b6441872e05a675574f0d434d67f6ae9ac Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 27 Jul 2012 14:05:44 +0200 Subject: [PATCH] org-md: Be more subtle when protecting # * contrib/lisp/org-md.el (org-md-paragraph, org-md-plain-text): Make sure raw # (inserted with, for example, an export snippet) don't get escaped. A few false positives don't hurt. --- contrib/lisp/org-md.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/contrib/lisp/org-md.el b/contrib/lisp/org-md.el index aba8c1e57..6ea4eb075 100644 --- a/contrib/lisp/org-md.el +++ b/contrib/lisp/org-md.el @@ -288,7 +288,11 @@ a communication channel." "Transcode PARAGRAPH element into Markdown format. CONTENTS is the paragraph contents. INFO is a plist used as a communication channel." - contents) + (let ((first-object (car (org-element-contents paragraph)))) + ;; If paragraph starts with a #, protect it. + (if (and (stringp first-object) (string-match "\\`#" first-object)) + (replace-match "\\#" nil t first-object) + contents))) ;;;; Plain List @@ -306,6 +310,10 @@ a communication channel." "Transcode a TEXT string into Markdown format. TEXT is the string to transcode. INFO is a plist holding contextual information." + ;; Protect ambiguous #. This will protect # at the beginning of + ;; a line, but not at the beginning of a paragraph. See + ;; `org-md-paragraph'. + (setq text (replace-regexp-in-string "\n#" "\n\\\\#" text)) ;; Protect ambiguous ! (setq text (replace-regexp-in-string "\\(!\\)\\[" "\\\\!" text nil nil 1)) ;; Protect `, *, _ and \