From 2a3e48c407a7e6127c30499b28fc357b117cbda3 Mon Sep 17 00:00:00 2001 From: Hung Date: Sat, 13 Jun 2020 14:41:39 +0800 Subject: [PATCH] Strip backslash from hugo shortcode and square bracket --- ox-hugo-pandoc-cite.el | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ox-hugo-pandoc-cite.el b/ox-hugo-pandoc-cite.el index ee1317e..0a8342c 100644 --- a/ox-hugo-pandoc-cite.el +++ b/ox-hugo-pandoc-cite.el @@ -194,10 +194,21 @@ Required fixes: "\\\\>}}"))) (while (re-search-forward regexp nil :noerror) (let* ((sc-body (match-string-no-properties 1)) - (sc-body-no-newlines (replace-regexp-in-string - "\n" " " sc-body))) - (replace-match (format "{{< %s >}}" sc-body-no-newlines) - :fixedcase))))) + (sc-body-no-newlines (replace-regexp-in-string "\n" " " sc-body)) + (sc-body-no-backlash (replace-regexp-in-string + (rx "\\" (group anything)) "\\1" sc-body-no-newlines))) + (replace-match (format "{{< %s >}}" sc-body-no-backlash) :fixedcase))))) + + ;; Fix square bracket. \[ abc \] -> [ abc ] + (save-excursion + (let ((regexp (concat + "\\\\\\[" + "\\(.+\\)" + "\\\\\\]"))) + (while (re-search-forward regexp nil :noerror) + (let* ((sc-body (match-string-no-properties 1))) + ;; (message "square bracket [%s]" sc-body) + (replace-match (format "[%s]" sc-body) :fixedcase))))) (buffer-substring-no-properties (point-min) (point-max)))))