New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion to rename a denote-file-type
value
#4
Comments
Yes, sure!
I think we can add this as well. Is that okay?
I admit to have never used toml before, so I need your help here. I
Will do it right away.
I am not sure I follow you on the "export" part. But yes, if we can |
This makes it specific that the front matter is YAML-compliant. It also gives us the option to support TOML. Thanks to Kaushal Modi for the feedback in issue 4 over at the GitHub mirror: <#4>.
This can be an incremental feature if people request it. I don't think it will be necessary to support a different flavor of front-matter in the first release. But renaming
The main benefit of TOML is that it's indentation-agnostic, and it has a tight and concise spec: https://toml.io/en/v1.0.0
💯
I was using "export" just as an umbrella term for the process of converting the user-entered data to a different format (TOML in this case). I think it will be another case statement here: Lines 345 to 351 in f9b8614
But as I was looking through it, I realized that a bit more work might be needed if we want to support spaces in tags/keywords. |
All clear about the "export" part. I am already working on it, though I must pause for ~30 minutes and be back to finalise it (diff below). denote.el | 34 ++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/denote.el b/denote.el
index 6bc4c23..5352405 100644
--- a/denote.el
+++ b/denote.el
@@ -118,8 +118,9 @@ (defcustom denote-file-type nil
By default (a nil value), the file type is that of Org mode.
When the value is the symbol `markdown-yaml', the file type is
-that of Markdown mode and the front matter uses a YAML-compliant
-way to represent tags.
+that of Markdown mode and the front matter uses YAML. Similarly,
+`markdown-toml' will use Markdown but apply TOML to the front
+matter.
When the value is `text', the file type is that of Text mode.
@@ -127,6 +128,7 @@ (defcustom denote-file-type nil
:type '(choice
(const :tag "Org mode (default)" nil)
(const :tag "Markdown (YAML front matter)" markdown-yaml)
+ (const :tag "Markdown (TOML front matter)" markdown-toml)
(const :tag "Plain text" text))
:group 'denote)
@@ -316,6 +318,7 @@ ;;;; New note
(defun denote--file-extension ()
"Return file type extension based on `denote-file-type'."
(pcase denote-file-type
+ ('markdown-toml ".md")
('markdown-yaml ".md")
('text ".txt")
(_ ".org")))
@@ -333,15 +336,22 @@ (defun denote--format-file (path id keywords slug extension)
(ext (or extension (denote--file-extension))))
(format "%s%s--%s--%s%s" path id slug kws ext)))
-(defun denote--file-meta-keywords (keywords)
+(defun denote--file-meta-keywords (keywords &optional type)
"Prepare KEYWORDS for inclusion in the file's front matter.
Parse the output of `denote--keywords-prompt', using `downcase'
on the keywords and separating them by two spaces. A single
-keyword is just downcased."
- (if (and (> (length keywords) 1)
- (not (stringp keywords)))
- (mapconcat #'downcase keywords " ")
- (downcase keywords)))
+keyword is just downcased.
+
+With optional TYPE, format the keywords
+appropriately (WORK-IN-PROGRESS)."
+ (cond
+ ((and (> (length keywords) 1)
+ (not (stringp keywords)))
+ (pcase type
+ ('toml (format "[%s]" (mapconcat #'downcase keywords ", ")))
+ (_ (mapconcat #'downcase keywords " "))))
+ (t
+ (downcase keywords))))
(defun denote--file-meta-header (title date keywords id)
"Front matter for new notes.
@@ -350,6 +360,14 @@ (defun denote--file-meta-header (title date keywords id)
provided by `denote-new-note'."
(let ((kw (denote--file-meta-keywords keywords)))
(pcase denote-file-type
+ ('markdown-toml (concat "+++" "\n"
+ "title: " title "\n"
+ "date: " date "\n"
+ "tags: " kw "\n"
+ "identifier: " id "\n"
+ "+++" "\n"
+ "\n"))
+
('markdown-yaml (concat "---" "\n"
"title: " title "\n"
"date: " date "\n" Can you please share TOML front matter with one and then with two tags? Just to be sure I use the correct syntax. |
Sure! TOML with 1 tag+++
title = "def"
date = 2022-06-10
tags = ["tag1"]
identifier = "20220610T110603"
+++ TOML with more tags+++
title = "def"
date = 2022-06-10
tags = ["tag1", "tag2", "tag3"]
identifier = "20220610T110603"
+++ Main differences compared to YAMLThis applies only to the simple scalar and list types that we are seeing here:
The list format above will work for YAML too. |
I find this website very useful: https://toolkit.site/format.html |
Thanks to Kaushal Modi for the feedback in issue 4 over at the GitHub mirror: <#4>.
Just pushed the changes to a new branch: What do you think? [ Will update the README.org afterwards. ] |
Sample output:
And with more tags:
|
For TOML,
+++
title = "This is a test"
date = 2022-06-10
tags = [ 'tag1', 'tag2', 'tag3' ]
identifier = "20220610T192450"
+++
Strings get auto-double-quoted if you format them using (format "%s" "abc") ;; => abc
(format "%S" "abc") ;; => "abc" |
Thanks to Kaushal Modi for the feedback in issue 4 over at the GitHub mirror: <#4>.
Good to know! Updated everything. We now get:
And:
|
Once we sort this out, we can move to the date format issue: #7 |
We are almost there.. This is seen as illegal by a TOML parser because it begins with numbers and then sees a "T" in middle. To make it a string, it would be need to wrapped in double-quotes as well. With that last change, the generated TOML will be valid. |
Thanks to Kaushal Modi for the feedback in issue 4 over at the GitHub mirror: <#4>.
Done! I will now merge this, update the docs, and then we can proceed to the next items. |
Perfect! Thank you! |
This concludes the work done on issue 4 over at the GitHub mirror with the help of Kaushal Modi: <#4>.
Hello,
From https://protesilaos.com/codelog/2022-06-07-denote-introduction/, I see:
May I suggest that that
denote-file-type
be changed to something likemarkdown-yaml
?If a user is using a static site generator like Hugo and few others, they can specify the front-matter in YAML, TOML, or even JSON.
For example, in TOML format, the same will look like this:
If this data is organized internally as a plist, it can be easily exported to TOML using tomelr [Disclaimer: I am maintaining that library and it's available on GNU ELPA too.]
Here's an example of using
tomelr-encode
from that library, which will generate the above TOML.Summary
markdown
value tomarkdown-yaml
for now.tomelr
can be done ifdenote-file-type
is set tomarkdown-toml
.The text was updated successfully, but these errors were encountered: