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

Linux and macOS use different Unicode normalization conventions in filenames
This commit is contained in:
Jethro Kuan
2020-03-06 01:47:22 +08:00
committed by GitHub
parent d1a47e090e
commit 09a23c377b

View File

@ -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