Skip to content

Commit

Permalink
Mask broken link err during pre-process if `broken-links' is non-nil
Browse files Browse the repository at this point in the history
Add a broken link test.

Fixes #587
  • Loading branch information
kaushalmodi committed Mar 14, 2022
1 parent d709f56 commit 920000a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 "))
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/site/content/posts/allow-broken-links.md
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 920000a

Please sign in to comment.