-
Notifications
You must be signed in to change notification settings - Fork 378
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
Support and display YAML front-matter block contents #1597
Conversation
Must be switched on in Settings / Markdown / Show YAML-Block. These points apply: * keys must consist of alpha-numeric characters, no spaces, punctuation, etc. * attribute values are either strings or lists * the `tags attribute` is special: if it's a string of comma-separated values, it is split into a real list * single or double quotes surrounding a string are removed The following two `tags` values are equivalent: ``` --- tags: - tag1 - tag2 tags: tag1, tag2 --- ``` Assume this block: ``` --- foo: bar tags: tag1, tag2, tag3 alist: - an item - another item --- ``` The resulting HTML is: ``` <div class='yaml-front-matter-container'> <div class='yaml-front-matter yaml-foo-container'> <span class='yaml-foo-item'> bar </span> </div> <div class='yaml-front-matter yaml-tags-container'> <span class='yaml-tags-item'> tag1 </span> <span class='yaml-tags-item'> tag2 </span> <span class='yaml-tags-item'> tag3 </span> </div> <div class='yaml-front-matter yaml-alist-container'> <span class='yaml-alist-item'> an item </span> <span class='yaml-alist-item'> another item </span> </div> </div> ```
Specify which attributes to show in Settings / Markdown / YAML Block: * '': don't show any attributes * '*': show all attributes * 'attr1, attr2, ...': only show selected attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion is to get rid of the + v +
part that adds the content.
I suggest instead to place a token there like {{ post.<<key>> }}
, which is later replaced by the value.
I did quite a similar thing in another project .... generate the proper html escaped strings, and replace post.key, page.key & site.key with that value.
This means automatically, in case the user has somewhere {{ page.title }}
in the file, it gets the frontmatter title 😄
yamlFrontMatterMap = extractYamlFrontMatter(markup); | ||
|
||
if (!yamlFrontMatterMap.isEmpty()) { | ||
for (Map.Entry<String, List<String>> entry : yamlFrontMatterMap.entrySet()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
watch out for Zim Wiki (as it's transpiled to Markdown), do the files work fine?
maybe some additional unit-test(s) that compares input and output could be helpful generally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I wasn't aware of Zim Wiki. I will have a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a look at some Zim files but could not find any issues. Do you have anything in mind which could lead to problems?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. i dont use zim either.
app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java
Outdated
Show resolved
Hide resolved
Instead of switching YAML block display on and off, allow the user to define which attributes she wants to see by editing the setting in Settings / Markdown / Show YAML-Block. Allowed values are: * '' (empty string): turn off, i.e. nothing is displayed * '*' (star): display all attributes * 'attr1, attr2, ...': comma-separated list of attributes to show
I like the idea of using tokens instead, will see if I get it working. |
In fact, the whole range of Markdown works in the attributes: ```yaml --- title: Foo `bar` $a+b$ --- ```
a712da0
to
e124bb4
Compare
a818d5b
to
757efd4
Compare
This reverts commit e124bb4. Performance issue
da9cb60
to
44b8a14
Compare
should be something like that -->
for tags and date it can optionally be special handling, for the rest this is fine. My goal is that your new settings option is mainly about adding your newly added predefined Heading. This is then similar to how TOC table of contents is done. |
The tokens need to be of scope 'note': ``` --- title: Document title --- The not title is "{{ note.title }}". ```
HTML-encode only
let me know when it's reviewable again |
app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java
Outdated
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java
Outdated
Show resolved
Hide resolved
Instead of backslash-escaping the whole token, now the scope needs to be prefixed. Old: `\{{ page.title }}`, new: `{{ \page.title }}`.
Does it make sense to have three scopes 'page', 'post' and 'site'? If we drop two and only use 'post', the code will be even simpler. No need to iterate over the scope list for every attribute any longer, cutting down the mumber of |
I'm OK with it if it is just I took care of it, you don't need to make change for this. |
do you have something left, otherwise I merge it now |
Thanks! I have nothing left, have been using it for a while with no apparent issues. |
In app/src/main/res/values/strings.xml line 261 shouldn't this read 'post.title' instead of 'page.title'? |
now yes, before reducing to just post .. it would have worked : - ) |
cc7b681
to
80d6c9a
Compare
Most of my documents contain a leading YAML front-matter block with title, creation date and tags attributes. I'd really like that information to be displayed on top of the note in view mode. This PR adds support for it. It must be switched on in Settings / Markdown / Show YAML-Block.
These points apply:
tags
attribute is special: if it's a string of comma-separated values, it is split into a real list, so these twotags
are equivalent:Assume this block:
The resulting HTML is:
The following block:
Will be displayed like that: