diff --git a/ox-hugo.el b/ox-hugo.el index a546e53c..d8947aad 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -4327,6 +4327,8 @@ INFO is a plist holding export options." (defun org-hugo--get-pre-processed-buffer () "Return a pre-processed copy of the current buffer. +This function is called only exporting valid Hugo post subtrees. + Internal links to other subtrees are converted to external links." (let ((pre-processed-buffer-prefix "*Ox-hugo Pre-processed ")) @@ -4342,9 +4344,9 @@ links." (org-use-property-inheritance (org-hugo--selective-property-inheritance)) (info (org-combine-plists (list :parse-tree ast) - (org-export--get-export-attributes 'hugo) + (org-export--get-export-attributes 'hugo :subtreep) (org-export--get-buffer-attributes) - (org-export-get-environment 'hugo))) + (org-export-get-environment 'hugo :subtreep))) (local-variables (buffer-local-variables)) (bound-variables (org-export--list-bound-variables)) vars) @@ -4379,9 +4381,15 @@ links." (let ((type (org-element-property :type link))) (when (member type '("custom-id" "id" "fuzzy")) (let* ((raw-link (org-element-property :raw-link link)) - (destination (if (string= type "fuzzy") - (org-export-resolve-fuzzy-link link info) + (progn + ;; Derived from ox.el -> `org-export-data'. If a broken link is seen + ;; and if `broken-links' option is not nil, ignore the error. + (condition-case err + (org-export-resolve-fuzzy-link link info) + (org-link-broken + (unless (plist-get info :with-broken-links) + (user-error "Unable to resolve link: %S" (nth 1 err)))))) (progn ;; Update `org-id-locations' if it's nil or empty hash table ;; to avoid broken link. diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 1a4a4bed..664657b3 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -3746,6 +3746,24 @@ Below links are invalid, they are there just for test purpose. - [[https://jira.example.com/issues/?jql=(project=MYPRJ)AND(assignee=currentUser())][A dummy Jira JQL link]] - [[https://jira.example.com/issues/?jql=(project=MYPRJ)AND(assignee=currentUser())AND(labels in (foo))][A dummy Jira JQL link with spaces]] +** Allow broken links (dummy parent heading) +:PROPERTIES: +:EXPORT_OPTIONS: broken-links:t +:END: +The ~broken-links:t~ export option needs to be set in the parent +heading because of [[https://lists.gnu.org/r/emacs-orgmode/2022-03/msg00149.html][this issue]] in upstream ~ox.el~. Remove this extra +heading nesting once that is fixed. +*** Allow broken links :broken_links: +:PROPERTIES: +:EXPORT_FILE_NAME: allow-broken-links +:EXPORT_OPTIONS: broken-links:t +:END: +#+begin_description +Test that export finishes without any error even when the post has +broken links. +#+end_description +- something [[foo:bar]] something +- something [[roam:git]] something * Equations :equations: ** MathJax :mathjax: *** Inline equations diff --git a/test/site/content/posts/allow-broken-links.md b/test/site/content/posts/allow-broken-links.md new file mode 100644 index 00000000..50dd4d68 --- /dev/null +++ b/test/site/content/posts/allow-broken-links.md @@ -0,0 +1,12 @@ ++++ +title = "Allow broken links (dummy parent heading)" +description = """ + Test that export finishes without any error even when the post has + broken links. + """ +tags = ["links", "broken-links"] +draft = false ++++ + +- something [{{< relref "" >}}]({{< relref "" >}}) something +- something [{{< relref "" >}}]({{< relref "" >}}) something