diff --git a/ChangeLog b/ChangeLog index 6204b640..4177aba3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2026-02-15 Mats Lidell + +* hywiki.el (hywiki--org-link-html-format): Use + `hpath:dashes-to-spaces-markup-anchor' to make header match target. +* test/hywiki-tests.el (hywiki-tests--action-key-moves-to-word-and-section-using-dash-to-space-conversion): + Add test for headers with dashes. + (hywiki-tests--published-html-links-to-word-and-section): Update test to + the dash to space conversion in headers. + 2026-02-15 Bob Weiner * hywiki.el (hywiki-word-highlight-in-current-buffer): Fix bug that added diff --git a/hywiki.el b/hywiki.el index 62df7997..b5223f0b 100644 --- a/hywiki.el +++ b/hywiki.el @@ -3072,7 +3072,8 @@ If not found, set it up and return the new project properties." (defun hywiki--org-link-html-format (path-stem suffix desc info) "Format an html link using Org ids." - (let* ((heading (and suffix (not (string-empty-p suffix)) (substring suffix 1))) + (let* ((raw-heading (and suffix (not (string-empty-p suffix)) (substring suffix 1))) + (heading (and raw-heading (hpath:dashes-to-spaces-markup-anchor raw-heading))) (link-obj (org-element-create 'link (list diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el index a9aa5ac4..f3afe1c1 100644 --- a/test/hywiki-tests.el +++ b/test/hywiki-tests.el @@ -877,7 +877,7 @@ body B (condition-case err-msg (dolist (w words) (setq wiki-link (car w) - expected-str-at-pos (cdr w)) + expected-str-at-pos (regexp-quote (cdr w))) (erase-buffer) (hywiki-tests--insert wiki-link) (goto-char 4) @@ -887,6 +887,41 @@ body B (error (error "'%s', '%s' - Error: %s" wiki-link expected-str-at-pos err-msg)))))))) +(ert-deftest hywiki-tests--action-key-moves-to-word-and-section-using-dash-to-space-conversion () + "Verify action key on a WikiWord with section, line and column works. +Verify dash in the header matches a target with dash replaced by space." + (hywiki-tests--preserve-hywiki-mode + (let ((words '(("WikiWord#first" . "* first") + ("WikiWord#header-one" . "* header one") + ("WikiWord#first one" . "* first") + ("(WikiWord#header one)" . "* header one") + ("WikiWord#header--two" . "* header two") + ("(WikiWord#header--three)" . "* header three") + ("WikiWord#header---four" . "* header four")))) + ;; Setup target WikiWord + (with-current-buffer (find-file-noselect wiki-page) + (hywiki-tests--insert "\ +* first +* header one +* header two +* header three +* header four +") + (save-buffer)) + ;; Create temp buffers with WikiWord links to the target + ;; WikiWord page and verify they work. + (with-temp-buffer + (dolist (w words) + (let ((wiki-link (car w)) + (expected-str-at-pos (regexp-quote (cdr w)))) + (ert-info ((format "Link: %s Header: %s" wiki-link expected-str-at-pos)) + (erase-buffer) + (hywiki-tests--insert wiki-link) + (goto-char 4) + (save-excursion + (action-key) + (should (looking-at-p expected-str-at-pos)))))))))) + (defun hywiki-tests--search-section (section) "Find SECTION in current buffer and return the id string. Search for elements of type ... for the id string. Example: @@ -924,7 +959,7 @@ First line body A ** Bsection subsection body B -*** Csection-subsection +*** Csection subsection body C ") (save-buffer) @@ -950,7 +985,7 @@ WikiWord#Csection-subsection (with-current-buffer (find-file-noselect wikiword-html) (setq idA (should (hywiki-tests--search-section "Asection"))) (setq idB (should (hywiki-tests--search-section "Bsection subsection"))) - (setq idC (should (hywiki-tests--search-section "Csection-subsection")))) + (setq idC (should (hywiki-tests--search-section "Csection subsection")))) ;; Verify links are generated (find-file wikipage-html)