Render non-fuzzy links without content correctly

If a link was non-fuzzy (points at a known URI scheme) and also
had no description, the parser would incorrectly wrap the text
in an <em> tag instead of displaying the link as the content.
ご主人様
not manx 3 years ago
parent 22f9437d93
commit 2de9c92881
Signed by: C-xC-c
GPG Key ID: F52ED472284EF2F4

@ -61,6 +61,11 @@
"<h1 id=\"org[[:alnum:]]\\{7\\}\">mwee</h1>" "<h1 id=\"org[[:alnum:]]\\{7\\}\">mwee</h1>"
"* mwee" '(:export-header-ids t))) "* mwee" '(:export-header-ids t)))
(ert-deftest link-without-content ()
(should-render-as
"<p><a href=\"https://flanchan.moe\">https://flanchan.moe</a></p>"
"[[https://flanchan.moe]]"))
;; Links and IDs ;; Links and IDs
(ert-deftest link () (ert-deftest link ()
(should-render-as (should-render-as

@ -3,7 +3,7 @@
;; Author: Plum <boku@plum.moe> ;; Author: Plum <boku@plum.moe>
;; Created: June 2020 ;; Created: June 2020
;; Package-Version: 1.2.0 ;; Package-Version: 1.2.1
;; Keywords: files ;; Keywords: files
;; URL: https://words.plum.moe/ox-plumhtml.html ;; URL: https://words.plum.moe/ox-plumhtml.html
;; Package-Requires: ((emacs "26.1") (ox-slimhtml "0.4.5")) ;; Package-Requires: ((emacs "26.1") (ox-slimhtml "0.4.5"))
@ -120,20 +120,18 @@ INFO is a plist holding contextual information."
(cond (cond
((ox-slimhtml--immediate-child-of-p link 'link) ((ox-slimhtml--immediate-child-of-p link 'link)
(org-element-property :raw-link link)) (org-element-property :raw-link link))
((not contents)
(format "<em>%s</em>" (org-element-property :path link)))
(t (let ((link-type (org-element-property :type link)) (t (let ((link-type (org-element-property :type link))
(href (org-element-property :raw-link link)) (href (org-element-property :raw-link link))
(attributes (if (ox-slimhtml--immediate-child-of-p link 'paragraph) (attributes (if (ox-slimhtml--immediate-child-of-p link 'paragraph)
(ox-slimhtml--attr (org-export-get-parent link)) (ox-slimhtml--attr (org-export-get-parent link))
"")) ""))
(element "<a href=\"%s\"%s>%s</a>")) (element "<a href=\"%s\"%s>%s</a>")
(path (or (org-element-property :path link) "")))
(cond (cond
((string= "file" link-type) ((string= "file" link-type)
(let ((html-extension (or (plist-get info :html-extension) "")) (let ((html-extension (or (plist-get info :html-extension) ""))
(use-abs-url (plist-get info :html-link-use-abs-url)) (use-abs-url (plist-get info :html-link-use-abs-url))
(link-org-files-as-html (plist-get info :html-link-org-as-html)) (link-org-files-as-html (plist-get info :html-link-org-as-html)))
(path (or (org-element-property :path link) "")))
(format element (format element
(concat (if (and use-abs-url (file-name-absolute-p path)) "file:" "") (concat (if (and use-abs-url (file-name-absolute-p path)) "file:" "")
(if (and link-org-files-as-html (string= "org" (downcase (or (file-name-extension path) "")))) (if (and link-org-files-as-html (string= "org" (downcase (or (file-name-extension path) ""))))
@ -142,12 +140,15 @@ INFO is a plist holding contextual information."
(file-name-sans-extension path)) (file-name-sans-extension path))
path)) path))
attributes contents))) attributes contents)))
((and (string= "fuzzy" link-type)
(not contents))
(format "<em>%s</em>" path))
((and (string= "fuzzy" link-type) ((and (string= "fuzzy" link-type)
(plist-get info :export-header-ids)) (plist-get info :export-header-ids))
(format "<a href=\"#%s\"%s>%s</a>" (format "<a href=\"#%s\"%s>%s</a>"
(org-export-get-reference (org-export-resolve-fuzzy-link link info) info) (org-export-get-reference (org-export-resolve-fuzzy-link link info) info)
attributes contents)) attributes contents))
(t (format element href attributes contents))))))) (t (format element href attributes (or contents href))))))))
;; org-export backend and export/publish functions ;; org-export backend and export/publish functions
(org-export-define-derived-backend 'plumhtml (org-export-define-derived-backend 'plumhtml

Loading…
Cancel
Save