seam

Personal wiki toolkit for Emacs
Log | Files | Refs | LICENSE

commit f49a747adfea970f73dc96c07240794c60cec696
parent 0be370b732edd3119c0839275642f76a8a4e7b37
Author: Spencer Williams <spnw@plexwave.org>
Date:   Sat, 29 Mar 2025 19:09:35 -0400

Add option to export internal links with custom CSS class

Diffstat:
Mseam-export.el | 17++++++++++++++++-
Mseam-html.el | 3+++
Mseam-test.el | 15+++++++++++++++
3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/seam-export.el b/seam-export.el @@ -34,6 +34,7 @@ (defvar seam-export--template nil) (defvar seam-export--root-path nil) (defvar seam-export--no-extension nil) +(defvar seam-export--internal-link-class nil) (defvar seam-export--options nil) (defgroup seam-export nil @@ -74,6 +75,11 @@ properties: Whether to drop the \".html\" file extension in links. Defaults to nil. + `:internal-link-class' + + CSS class name for internal links. Defaults to the value of + `seam-export-internal-link-class'. + `:backend-options' A plist of extra options passed to the Org HTML backend. This can be @@ -165,6 +171,12 @@ the datetime attribute of <time>. Passed to `format-time-string'." :group 'seam-export :type 'sexp) +(defcustom seam-export-internal-link-class nil + "CSS class name to use for internal links (i.e., links to other Seam +notes)." + :group 'seam-export + :type 'string) + (defvar seam-export-backend-options (list :html-container "article" @@ -292,7 +304,10 @@ the datetime attribute of <time>. Passed to `format-time-string'." (seam-export--template template) (seam-export--options (org-combine-plists seam-export-backend-options - backend-options))) + backend-options)) + (seam-export--internal-link-class + (or (plist-get plist :internal-link-class) + seam-export-internal-link-class))) (seam-export--note-to-html file dir)))))))) (defun seam-export-all-notes () diff --git a/seam-html.el b/seam-html.el @@ -195,6 +195,9 @@ INFO is a plist holding contextual information. See link)))) (and (eq link (org-element-map parent 'link #'identity info t)) (org-export-read-attribute :attr_html parent))) + ;; Add Seam internal link class if appropriate. + (when (and seam-export--internal-link-class (string= "seam" link-type)) + (list :class seam-export--internal-link-class)) ;; Also add attributes from link itself. Currently, those ;; need to be added programmatically before `org-html-link' ;; is invoked, for example, by backends building upon HTML diff --git a/seam-test.el b/seam-test.el @@ -47,6 +47,7 @@ (seam-title-formatter (lambda (title _type) title)) (seam-export-template-file nil) (seam-export-template-string seam-export-default-template-string) + (seam-export-internal-link-class nil) (seam-export-alist `((,(file-name-concat seam-test-directory "html") :types ("public") @@ -254,6 +255,20 @@ extension." (buffer-string) (re-search-forward "<a href=\"/bar\">")))))) +(ert-deftest seam-test-link-internal-class () + "Test that setting `seam-export-internal-link-class' correctly renders +the class." + (should + (identity + (seam-test-with-notes ((seam-export-internal-link-class "internal")) + ((foo "foo" "public") + (bar "bar" "public")) + (seam-test-add-contents foo (seam-test-link-to-buffer bar)) + (with-temp-buffer + (insert-file-contents "html/foo.html") + (buffer-string) + (re-search-forward "<a href=\"/bar.html\" class=\"internal\">")))))) + (ert-deftest seam-test-link-getters () (should (equal