From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH] Fix for double-escaping # and ![ in ox-md Date: Wed, 20 Dec 2017 23:07:39 +0100 Message-ID: <87shc5hx3o.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52851) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRmWh-0007Dz-UG for emacs-orgmode@gnu.org; Wed, 20 Dec 2017 17:07:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRmWd-00042p-0l for emacs-orgmode@gnu.org; Wed, 20 Dec 2017 17:07:47 -0500 Received: from relay2-d.mail.gandi.net ([217.70.183.194]:47282) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRmWc-00041a-QI for emacs-orgmode@gnu.org; Wed, 20 Dec 2017 17:07:42 -0500 In-Reply-To: (Kaushal Modi's message of "Wed, 20 Dec 2017 18:02:33 +0000") 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" To: Kaushal Modi Cc: emacs-org list Hello, Kaushal Modi writes: > Note that the # and ![ are double-escaped. So any markdown->HTML renderer > will print that "\" as it is. > > Digging through ox-md.el, I found that the order of > replace-regexp-in-string was incorrect in org-md-plain-text. > > Here's the diff: > > ===== > diff --git a/lisp/ox-md.el b/lisp/ox-md.el > index 12188387355..927a73b780c 100644 > --- a/lisp/ox-md.el > +++ b/lisp/ox-md.el > @@ -500,14 +500,15 @@ TEXT is the string to transcode. INFO is a plist > holding > contextual information." > (when (plist-get info :with-smart-quotes) > (setq text (org-export-activate-smart-quotes text :html info))) > + ;; The below series of replacements in `text' is order sensitive. > + ;; Protect `, *, _, and \ > + (setq text (replace-regexp-in-string "[`*_\\]" "\\\\\\&" text)) > ;; 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 \ > - (setq text (replace-regexp-in-string "[`*_\\]" "\\\\\\&" text)) > ;; Handle special strings, if required. > (when (plist-get info :with-special-strings) > (setq text (org-html-convert-special-strings text))) > ===== > > After applying this patch, the same portion exported doesn't have > double-escaping before # and ![. > > If this looks good, I can commit this to maint. It looks good. Thank you. Regards, -- Nicolas Goaziou