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.
This commit is contained in:
Nicolas Goaziou 2012-07-27 14:05:44 +02:00
parent c8acf8d695
commit 536c55b644
1 changed files with 9 additions and 1 deletions

View File

@ -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 \