-
Notifications
You must be signed in to change notification settings - Fork 2
/
velocity-backend-markdown.el
54 lines (41 loc) · 1.62 KB
/
velocity-backend-markdown.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;;; DEPENDENCIES
(require 'velocity-api)
;;; REGISTRATION
(velocity-register-backend
'markdown-file
(list :filter-result-fn 'velocity--markdown-filter-result
:get-content-unit-fn 'velocity--markdown-get-content-unit/file
:create-fn 'velocity--markdown-create))
(velocity-register-backend
'markdown-heading-1
(list :filter-result-fn 'velocity--markdown-filter-result
:get-content-unit-fn 'velocity--markdown-get-content-unit/heading-1
:create-fn 'velocity--markdown-create))
(velocity-register-backend
'markdown-heading-2
(list :filter-result-fn 'velocity--markdown-filter-result
:get-content-unit-fn 'velocity--markdown-get-content-unit/heading-2
:create-fn 'velocity--markdown-create))
;;; CALLBACKS
(defun velocity--markdown-create (title)
(goto-char (point-min))
(insert "# " title "\n\n")
(list :start-pos (point-min)
:end-pos (point)))
(defun velocity--markdown-filter-result (result)
(let* ((snippet-lines (split-string (plist-get result :snippet) "\n"))
(snippet-title (car snippet-lines))
(snippet-body (string-join (cdr snippet-lines) " ")))
(thread-first result
(plist-put :title snippet-title)
(plist-put :body snippet-body))))
(defun velocity--markdown-get-content-unit/file (from-pos)
(if (= from-pos (point-max))
nil
(cons 1 (point-max))))
(defun velocity--markdown-get-content-unit/heading-1 (from-pos)
(velocity--move-to-next-separator "^\\# " from-pos))
(defun velocity--markdown-get-content-unit/heading-2 (from-pos)
(velocity--move-to-next-separator "^\\## " from-pos))
;;; META
(provide 'velocity-backend-markdown)