diff options
| -rw-r--r-- | CHANGELOG.org | 5 | ||||
| -rw-r--r-- | README.org | 2 | ||||
| -rw-r--r-- | lisp/seam-export.el | 67 | ||||
| -rw-r--r-- | lisp/seam-test.el | 10 | 
4 files changed, 42 insertions, 42 deletions
diff --git a/CHANGELOG.org b/CHANGELOG.org index db0b53f..6526921 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -6,6 +6,11 @@    should have been all along.  Make sure to update your =init.el=    accordingly. +- Seam now uses [[https://github.com/Wilfred/mustache.el][mustache.el]] for templating.  In Mustache +  double-bracketed variables are escaped, so you must use +  triple-brackets for variables that include raw HTML.  Please see the +  updated =seam-export-default-template-string= for reference. +  - Your =seam-title-formatter= function should now take three arguments    instead of two: the third arg (=draft-p=) will be non-nil if the    note is a draft. @@ -20,7 +20,7 @@ Be aware that Seam is a fully self-contained package, and is not  likely to be compatible with things like [[https://www.orgroam.com/][Org-roam]] due to its vastly  different approach. -*Note:* Requires Emacs 29 or greater, with Org 9.6 or greater. +*Note:* Requires Emacs 29+, Org 9.6+, and [[https://github.com/Wilfred/mustache.el][mustache.el]].  *** Getting started diff --git a/lisp/seam-export.el b/lisp/seam-export.el index 743672a..698d1f4 100644 --- a/lisp/seam-export.el +++ b/lisp/seam-export.el @@ -28,6 +28,7 @@  ;;; Code:  (require 'cl-lib) +(require 'mustache)  (require 'seam-html)  (defvar seam-export--types nil) @@ -115,18 +116,20 @@ See `seam-export-alist' for more information about specifying templates."  <h1>{{title}}</h1>  <p class=\"modified\">Last modified: <time datetime=\"{{modified-dt}}\">{{modified}}</time></p>  </header> -{{contents}} +{{{contents}}}  <section class=\"backlinks\">  <h1>Backlinks</h1> -{{backlinks}} +{{{backlinks}}}  </section>  </main>  </body>  </html>"    "The default HTML template string if no other template is specified. -It should be plain HTML5. Several variables are defined which can be -interpolated using the {{variable}} syntax: +It should be plain HTML5.  Several variables are defined which +can be interpolated using Mustache bracket syntax.  {{variable}} +will HTML-escape the interpolated text, while {{{variable}}} will +interpolate it as-is.    `contents' @@ -224,11 +227,6 @@ notes)."      (seam-export--to-string        (insert s))))) -(defun seam-export--replace-variable (var replacement) -  (goto-char 1) -  (while (re-search-forward (format "{{%s}}" var) nil t) -    (replace-match replacement t t))) -  (defun seam-export--generate-backlinks (file)    (seam-export--to-string      (let ((files (cl-sort @@ -248,33 +246,30 @@ notes)."          (modified (file-attribute-modification-time                     (file-attributes note-file))))      (with-temp-buffer -      (insert seam-export--template) -      (seam-export--replace-variable -       "title" -       (seam-export--escape-string -        (seam-get-title-from-file note-file))) -      (seam-export--replace-variable -       "modified" -       (format-time-string -        seam-export-time-format -        modified -        seam-export-time-zone)) -      (seam-export--replace-variable -       "modified-dt" -       (format-time-string -        seam-export-time-format-datetime -        modified -        seam-export-time-zone)) -      (seam-export--replace-variable -       "contents" -       (seam-export--to-string -         (insert-file-contents note-file) -         (re-search-forward "^\\* ") -         (org-mode)                    ;Needed for `org-set-property'. -         (org-set-property "seam-title-p" "t"))) -      (seam-export--replace-variable -       "backlinks" -       (seam-export--generate-backlinks note-file)) +      (insert +       (mustache-render +        seam-export--template +        `(("title" . +           ,(seam-export--escape-string +             (seam-get-title-from-file note-file))) +          ("modified" . +           ,(format-time-string +             seam-export-time-format +             modified +             seam-export-time-zone)) +          ("modified-dt" . +           ,(format-time-string +             seam-export-time-format-datetime +             modified +             seam-export-time-zone)) +          ("contents" . +           ,(seam-export--to-string +              (insert-file-contents note-file) +              (re-search-forward "^\\* ") +              (org-mode)               ;Needed for `org-set-property'. +              (org-set-property "seam-title-p" "t"))) +          ("backlinks" . +           ,(seam-export--generate-backlinks note-file)))))        (write-file html-file))))  (defun seam-export--file-string (file) diff --git a/lisp/seam-test.el b/lisp/seam-test.el index fc4e2d4..6177907 100644 --- a/lisp/seam-test.el +++ b/lisp/seam-test.el @@ -326,7 +326,7 @@ notes such that they no longer link to it."    "Test that linking to a note from a public note creates a backlink."    (should     (identity -    (seam-test-with-notes ((seam-export-template-string "{{backlinks}}")) +    (seam-test-with-notes ((seam-export-template-string "{{{backlinks}}}"))          ((foo "foo" "public")           (bar "bar" "public"))        (with-current-buffer foo @@ -341,7 +341,7 @@ backlink."    (should     (equal      "" -    (seam-test-with-notes ((seam-export-template-string "{{backlinks}}")) +    (seam-test-with-notes ((seam-export-template-string "{{{backlinks}}}"))          ((foo "foo")           (bar "bar" "public"))        (with-current-buffer foo @@ -355,7 +355,7 @@ backlink."    (should     (equal      "" -    (seam-test-with-notes ((seam-export-template-string "{{backlinks}}")) +    (seam-test-with-notes ((seam-export-template-string "{{{backlinks}}}"))          ((foo "foo" "public")           (bar "bar" "public"))        (with-current-buffer foo @@ -372,7 +372,7 @@ backlink."    (should     (equal      "" -    (seam-test-with-notes ((seam-export-template-string "{{backlinks}}")) +    (seam-test-with-notes ((seam-export-template-string "{{{backlinks}}}"))          ((foo "foo" "public" nil t)           (bar "bar" "public"))        (with-current-buffer foo @@ -510,7 +510,7 @@ it."    (should     (equal      "“quotes” & <symbols>\n" -    (seam-test-with-notes ((seam-export-template-string "{{title}}")) +    (seam-test-with-notes ((seam-export-template-string "{{{title}}}"))          ((note "\"quotes\" & <symbols>" "public"))        (seam-export--file-string "html/quotes-symbols.html")))))  | 
