@@ -75,43 +75,54 @@ for more information.")
75
75
(defcustom org-chef-prefer-json-ld nil
76
76
" Prefer JSON-LD extractor over custom extractor. This is for testing the JSON-LD functionality."
77
77
:type 'boolean )
78
-
78
+
79
+ (defun org-chef-to-unordered-list (list )
80
+ " Convert a LIST of strings into an org-element plain list"
81
+ (if (null list )
82
+ nil
83
+ `(plain-list nil ,(mapcar #' (lambda (x ) `(item (:bullet " -" :pre-blank 0 ) , x )) list ))))
84
+
85
+ (defun org-chef-to-ordered-list (list )
86
+ " Convert a LIST of strings into an ordered org-element plain list"
87
+ (if (null list )
88
+ nil
89
+ `(plain-list nil ,(mapcar #' (lambda (x ) `(item (:bullet " 1. " :pre-blank 0 ) , x )) list ))))
90
+
91
+ (org-element-interpret-data (org-chef-to-unordered-list '(" " )))
92
+
93
+ (defun org-chef-recipe-to-org-element (recipe )
94
+ " Convert a RECIPE into an `org-element` AST."
95
+ `(headline (:title ,(cdr (assoc 'name recipe)) :level 1 )
96
+ (property-drawer nil
97
+ ((node-property (:key " source-url" :value ,(cdr (assoc 'source-url recipe))))
98
+ (node-property (:key " servings" :value ,(cdr (assoc 'servings recipe))))
99
+ (node-property (:key " prep-time" :value ,(format " %s " (cdr (assoc 'prep-time recipe)))))
100
+ (node-property (:key " cook-time" :value ,(format " %s " (cdr (assoc 'cook-time recipe)))))
101
+ (node-property (:key " ready-in" :value ,(format " %s " (cdr (assoc 'ready-in recipe)))))))
102
+ (headline (:title " Ingredients" :level 2 :pre-blank 1 )
103
+ ,(org-chef-to-unordered-list (cdr (assoc 'ingredients recipe))))
104
+ (headline (:title " Directions" :level 2 :pre-blank 1 )
105
+ ,(org-chef-to-ordered-list (cdr (assoc 'directions recipe))))))
106
+
107
+ (defun org-chef-recipe-to-org (recipe )
108
+ " Convert a RECIPE into `org-mode` test."
109
+ (org-element-interpret-data (org-chef-recipe-to-org-element recipe)))
110
+
79
111
(defun org-chef-recipe-insert-org (recipe )
80
112
" Insert a RECIPE as an ‘org-mode’ heading."
81
- (org-insert-heading )
82
- (insert (cdr (assoc 'name recipe)))
83
- (org-return )
84
- (org-set-property " source-url" (cdr (assoc 'source-url recipe)))
85
- (org-set-property " servings" (cdr (assoc 'servings recipe)))
86
- (org-set-property " prep-time" (format " %s " (cdr (assoc 'prep-time recipe))))
87
- (org-set-property " cook-time" (format " %s " (cdr (assoc 'cook-time recipe))))
88
- (org-set-property " ready-in" (format " %s " (cdr (assoc 'ready-in recipe))))
89
- (org-insert-subheading t )
90
- (insert " Ingredients" )
91
- (org-return )
92
- (org-return )
93
- (org-chef-insert-org-list (cdr (assoc 'ingredients recipe)))
94
- (org-return )
95
- (org-return )
96
- (org-insert-heading )
97
- (insert " Directions" )
98
- (org-return )
99
- (org-return )
100
- (org-chef-insert-org-list (cdr (assoc 'directions recipe)) " 1." ))
101
-
113
+ (insert
114
+ (org-chef-recipe-to-org (recipe))))
102
115
103
116
(defun org-chef-recipe-org-string (recipe )
104
117
" Get an ‘org-mode’ heading string for a RECIPE."
105
118
(with-temp-buffer (org-mode )
106
119
(org-chef-recipe-insert-org recipe)
107
120
(buffer-string )))
108
121
109
-
110
122
(defun org-chef-match-url (BASE URL )
111
123
" Match URL against a BASE url."
112
124
(not (null (string-match-p (regexp-quote BASE) URL))))
113
125
114
-
115
126
(defun org-chef-fetch-recipe-specific-url (URL )
116
127
" Look up a recipe based on a specific URL."
117
128
(cond
0 commit comments