(fix): remove nonspacing marks from slugs (#230)

Linux and macOS use different Unicode normalization conventions in filenames
master
Jethro Kuan 6 years ago committed by GitHub
parent d1a47e090e
commit 09a23c377b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      org-roam.el

@ -562,13 +562,18 @@ specified via the #+ROAM_ALIAS property."
(defun org-roam--title-to-slug (title)
"Convert TITLE to a filename-suitable slug."
(cl-flet ((replace (title pair)
(replace-regexp-in-string (car pair) (cdr pair) title)))
(cl-flet* ((nonspacing-mark-p (char)
(eq 'Mn (get-char-code-property char 'general-category)))
(strip-nonspacing-marks (s)
(apply #'string (seq-remove #'nonspacing-mark-p
(ucs-normalize-NFD-string s))))
(replace (title pair)
(replace-regexp-in-string (car pair) (cdr pair) title)))
(let* ((pairs `(("[^[:alnum:][:digit:]]" . "_") ;; convert anything not alphanumeric
("__*" . "_") ;; remove sequential underscores
("^_" . "") ;; remove starting underscore
("_$" . ""))) ;; remove ending underscore
(slug (-reduce-from #'replace title pairs)))
(slug (-reduce-from #'replace (strip-nonspacing-marks title) pairs)))
(s-downcase slug))))
;;;; Org-roam capture

Loading…
Cancel
Save