From 037cff56926cd6a615f33908acc732485b1483dd Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Fri, 18 Mar 2022 01:20:00 -0400 Subject: [PATCH 1/4] fix: Detecting `broken-links:t` in `:EXPORT_OPTIONS:` now works This fix was possible after the AST looping was moved outside the `with-temp-buffer` construct: https://github.com/kaushalmodi/ox-hugo/pull/595 Fixes https://github.com/kaushalmodi/ox-hugo/issues/587. --- ox-hugo.el | 8 +++++++- test/site/content-org/issues/issue-587-2.org | 5 ----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ox-hugo.el b/ox-hugo.el index 2f7572ef..e8edad18 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -4495,7 +4495,13 @@ links." (condition-case err (org-export-resolve-fuzzy-link el info) (org-link-broken - (unless (plist-get info :with-broken-links) + (unless (or (plist-get info :with-broken-links) + ;; Parse the `:EXPORT_OPTIONS' property if set + ;; in a parent heading. + (plist-get + (org-export--parse-option-keyword + (cdr (org-hugo--get-elem-with-prop :EXPORT_OPTIONS))) + :with-broken-links)) (user-error "Unable to resolve link: %S" (nth 1 err)))))) (org-export-resolve-id-link el (org-export--collect-tree-properties ast info)))) (source-path (org-hugo--heading-get-slug el info :inherit-export-file-name)) diff --git a/test/site/content-org/issues/issue-587-2.org b/test/site/content-org/issues/issue-587-2.org index 28b9a53d..a5969590 100644 --- a/test/site/content-org/issues/issue-587-2.org +++ b/test/site/content-org/issues/issue-587-2.org @@ -3,11 +3,6 @@ #+author: #+macro: issue ~ox-hugo~ Issue #[[https://github.com/kaushalmodi/ox-hugo/issues/$1][$1]] -# Tue Mar 15 13:26:37 EDT 2022 - kmodi -# Workaround: "#+options: broken-links:t" works, but the -# ":EXPORT_OPTIONS: broken-links:t" property does not work for now. -#+options: broken-links:t - * Allow broken links (Subtree based export) :broken_links: :PROPERTIES: :EXPORT_FILE_NAME: issue-587-subtree-based-export From 0a28ae98357e464568b96272f4c97a850e2ff7da Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Fri, 18 Mar 2022 01:26:28 -0400 Subject: [PATCH 2/4] Cleanup: Remove some commented out debug code --- ox-hugo.el | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ox-hugo.el b/ox-hugo.el index e8edad18..e6cea647 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -1979,20 +1979,10 @@ Return nil if none of the above are true." bundle slug) ;; (message "[org-hugo--heading-get-slug DBG] EXPORT_FILE_NAME: %S" file) (when file - ;; (message "buffer : %S" (current-buffer)) - ;; (message "point min : %S" (point-min)) - ;; (message "point max : %S" (point-max)) (setq bundle (let* ((elem-pval (org-hugo--get-elem-with-prop :EXPORT_HUGO_BUNDLE)) (pval (when elem-pval (cdr elem-pval)))) pval)) - ;; (setq bundle (org-string-nw-p (or (org-export-get-node-property :EXPORT_HUGO_BUNDLE heading :inherited) - ;; (plist-get info :hugo-bundle) - ;; (cdr (org-hugo--get-elem-with-prop :EXPORT_HUGO_BUNDLE))))) - - ;; (message "[org-hugo--heading-get-slug DBG] EXPORT_HUGO_BUNDLE: %S" bundle) - ;; (message "[org-hugo--heading-get-slug DBG] point %S" (point)) - ;; (message "[org-hugo--heading-get-slug DBG] bundle 2: %S" (cdr (org-hugo--get-elem-with-prop :EXPORT_HUGO_BUNDLE))) (cond ;; Leaf or branch bundle landing page. From a5a110b9faefdf63fe221783004f1d5be4b3d2ca Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Fri, 18 Mar 2022 01:36:15 -0400 Subject: [PATCH 3/4] fix: Don't allow `org-export--parse-option-keyword` input to be nil --- ox-hugo.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ox-hugo.el b/ox-hugo.el index e6cea647..a5482c51 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -4477,7 +4477,6 @@ links." (let ((type (org-element-property :type el))) (when (member type '("custom-id" "id" "fuzzy")) (let* ((raw-link (org-element-property :raw-link el)) - (destination (if (string= type "fuzzy") (progn ;; Derived from ox.el -> `org-export-data'. If a broken link is seen @@ -4490,7 +4489,7 @@ links." ;; in a parent heading. (plist-get (org-export--parse-option-keyword - (cdr (org-hugo--get-elem-with-prop :EXPORT_OPTIONS))) + (or (cdr (org-hugo--get-elem-with-prop :EXPORT_OPTIONS)) "")) :with-broken-links)) (user-error "Unable to resolve link: %S" (nth 1 err)))))) (org-export-resolve-id-link el (org-export--collect-tree-properties ast info)))) From c8c9cb8339f1df10522b27f8410855c82c774ccf Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Fri, 18 Mar 2022 01:55:31 -0400 Subject: [PATCH 4/4] fix: Set the starting position to search for EXPORT_OPTIONS When the target file is not open, the start position defaults to 1 and so the EXPORT_OPTIONS in the heading where we intend to search is never found. --- ox-hugo.el | 18 ++++++++++++++---- test/ert/telement.el | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/ox-hugo.el b/ox-hugo.el index a5482c51..fd290622 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -1910,12 +1910,15 @@ This function will never return nil." ""))) (substring (md5 title) 0 hash-len))) -(defun org-hugo--get-elem-with-prop (prop &optional _info) +(defun org-hugo--get-elem-with-prop (prop &optional pom _info) "Find the first element with PROP property in the current tree. PROP is a property symbol with a : prefix, example: `:EXPORT_FILE_NAME'. +Optional argument POM is the position or marker from which the +upward search for PROP should begin. + Return a cons of type (ELEM . PVAL) where ELEM is the element containing the property PROP and PVAL is the property's value. @@ -1926,13 +1929,17 @@ versions for the issue that `org-element-at-point' does not return an element with all the inherited properties. That issue is fixed in Org main branch at least as of 2022-03-17." (org-with-wide-buffer + ;; (message (format "[search prop DBG] point 1 : %S" (point))) + (when pom + (goto-char pom)) + ;; (message (format "[search prop DBG] point 2 : %S" (point))) (org-back-to-heading-or-point-min :invisible-ok) (let ((elem (org-element-at-point)) (level t) pval) (catch :found (while elem - ;; (message (format "[search prop DBG] elem : %S" elem )) + ;; (message (format "[search prop DBG] prop %S, elem : %S" prop elem)) (setq pval (org-element-property prop elem)) ;; (message "[search prop DBG] level %S, pval %S" level pval) (when (or pval (null level)) @@ -1973,7 +1980,7 @@ INFO is a plist used as a communication channel. Return nil if none of the above are true." (org-with-wide-buffer (let ((heading-begin (org-element-property :begin heading))) - (when (numberp heading-begin) + (when heading-begin (goto-char heading-begin))) (let ((file (org-string-nw-p (org-export-get-node-property :EXPORT_FILE_NAME heading inherit-export-file-name))) bundle slug) @@ -4489,7 +4496,10 @@ links." ;; in a parent heading. (plist-get (org-export--parse-option-keyword - (or (cdr (org-hugo--get-elem-with-prop :EXPORT_OPTIONS)) "")) + (or (cdr (org-hugo--get-elem-with-prop + :EXPORT_OPTIONS + (org-element-property :begin el))) + "")) :with-broken-links)) (user-error "Unable to resolve link: %S" (nth 1 err)))))) (org-export-resolve-id-link el (org-export--collect-tree-properties ast info)))) diff --git a/test/ert/telement.el b/test/ert/telement.el index ef3c8750..8ac7a9e2 100644 --- a/test/ert/telement.el +++ b/test/ert/telement.el @@ -111,5 +111,33 @@ " (cdr (org-hugo--get-elem-with-prop :EXPORT_HUGO_SECTION)))))) +(ert-deftest test-elem/starting-position () + "Test property lookup by specifying the starting position." + + ;; Here, the needed property is not found because the starting + ;; position for search is set to the beginning of the buffer. + (should + (equal nil + (org-test-with-parsed-data + " +* Heading 1 +:PROPERTIES: +:EXPORT_OPTIONS: toc:t +:END:" + (cdr (org-hugo--get-elem-with-prop :EXPORT_OPTIONS 1))))) + + ;; Here, the needed property *is* found because the starting + ;; position for search is set correctly, and that overrides the init + ;; position set by in this test. + (should + (string= "toc:t" + (org-test-with-parsed-data + " +* Heading 2 +:PROPERTIES: +:EXPORT_OPTIONS: toc:t +:END:" + (cdr (org-hugo--get-elem-with-prop :EXPORT_OPTIONS 2)))))) + (provide 'telement)