* [PATCH] Fix for double-escaping # and ![ in ox-md
@ 2017-12-20 18:02 Kaushal Modi
2017-12-20 22:07 ` Nicolas Goaziou
0 siblings, 1 reply; 3+ messages in thread
From: Kaushal Modi @ 2017-12-20 18:02 UTC (permalink / raw
To: emacs-org list
[-- Attachment #1: Type: text/plain, Size: 2878 bytes --]
Hello,
I have this test case; export it by doing C-c C-e C-s m M (assuming ox-md
is required.. I think it is required by default).
=====
* Escaping hashes and exclamations correctly in body
:PROPERTIES:
:EXPORT_FILE_NAME: escaping-hashes-and-exclamations-in-body
:END:
I intend to show these # characters verbatim; they should not render
as Markdown headings. They also shouldn't show up with a leading =\=
in the final rendered output.
# This is an Org comment
#This is not an Org comment. It has a hash char at beginning of a
paragraph which must be escaped just once i.e. show up as =\#= in
Markdown.
blah # This isn't an Org comment either
This * will be escaped just once i.e. show up as =\*= in Markdown.
This _ will be escaped just once i.e. show up as =\_= in Markdown.
This \ will be escaped just once i.e. show up as =\\= in Markdown.
Hash char at beginning of a continued line
#like this must be escaped just once i.e. show up as =\#= in Markdown.
![this exclamation must be escaped just once i.e. show up as =\!= in
Markdown]
This ! does not need to be escaped as there is no ambiguity.
=====
Here's the relevant excerpt of the export that is erroneous:
=====
Hash char at beginning of a continued line
\\#like this must be escaped just once i.e. show up as `\#` in Markdown.
\\![this exclamation must be escaped just once i.e. show up as `\!` in
Markdown]
=====
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.
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 3510 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix for double-escaping # and ![ in ox-md
2017-12-20 18:02 [PATCH] Fix for double-escaping # and ![ in ox-md Kaushal Modi
@ 2017-12-20 22:07 ` Nicolas Goaziou
2017-12-20 22:17 ` Kaushal Modi
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2017-12-20 22:07 UTC (permalink / raw
To: Kaushal Modi; +Cc: emacs-org list
Hello,
Kaushal Modi <kaushal.modi@gmail.com> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix for double-escaping # and ![ in ox-md
2017-12-20 22:07 ` Nicolas Goaziou
@ 2017-12-20 22:17 ` Kaushal Modi
0 siblings, 0 replies; 3+ messages in thread
From: Kaushal Modi @ 2017-12-20 22:17 UTC (permalink / raw
To: Nicolas Goaziou; +Cc: emacs-org list
[-- Attachment #1: Type: text/plain, Size: 242 bytes --]
On Wed, Dec 20, 2017 at 5:07 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:
> > If this looks good, I can commit this to maint.
>
> It looks good. Thank you.
>
Thanks. It's now committed to maint and merged to master.
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 635 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-12-20 22:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-20 18:02 [PATCH] Fix for double-escaping # and ![ in ox-md Kaushal Modi
2017-12-20 22:07 ` Nicolas Goaziou
2017-12-20 22:17 ` Kaushal Modi
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.