Add a [format.markdown] config section to customize tags syntax

pull/8/head
Mickaël Menu 3 years ago
parent f5b3102deb
commit 9fda155a99
No known key found for this signature in database
GPG Key ID: 53D73664CD359895

@ -11,7 +11,7 @@ All notable changes to this project will be documented in this file.
* To match notes associated with either tags, use a pipe `|` or `OR` (all caps), e.g. `--tag "inbox OR todo"`.
* If you want to exclude notes having a particular tag, prefix it with `-` or `NOT` (all caps), e.g. `--tag "NOT done"`.
* Use glob patterns to match multiple tags, e.g. `--tag "book-*"`.
* Many tag flavors are supported: `#hashtags`, `:colon:separated:tags:` and even Bear's [`#multi-word tags#`](https://blog.bear.app/2017/11/bear-tips-how-to-create-multi-word-tags/). If you prefer to use a YAML frontmatter, list your tags with the key `tags` or `keywords`.
* Many tag flavors are supported: `#hashtags`, `:colon:separated:tags:` ([opt-in](docs/note-format.md)) and even Bear's [`#multi-word tags#`](https://blog.bear.app/2017/11/bear-tips-how-to-create-multi-word-tags/) ([opt-in](docs/note-format.md)). If you prefer to use a YAML frontmatter, list your tags with the key `tags` or `keywords`.
* Print metadata from the YAML frontmatter in `list` output using `{{metadata.<key>}}`, e.g. `{{metadata.description}}`. Keys are normalized to lower case.
### Changed

@ -62,11 +62,11 @@ func (c *Container) TemplateLoader(lang string) *handlebars.Loader {
return c.templateLoader
}
func (c *Container) Parser() *markdown.Parser {
func (c *Container) Parser(zk *zk.Zk) *markdown.Parser {
return markdown.NewParser(markdown.ParserOpts{
HashtagEnabled: true,
MultiWordTagEnabled: false,
ColontagEnabled: true,
HashtagEnabled: zk.Config.Format.Markdown.Hashtags,
MultiWordTagEnabled: zk.Config.Format.Markdown.MultiwordTags,
ColontagEnabled: zk.Config.Format.Markdown.ColonTags,
})
}
@ -116,7 +116,7 @@ func (c *Container) index(zk *zk.Zk, db *sqlite.DB, force bool) (note.IndexingSt
stats, err = note.Index(
zk,
force,
c.Parser(),
c.Parser(zk),
c.NoteIndexer(tx),
c.Logger,
func(change paths.DiffChange) {

@ -12,6 +12,7 @@ import (
type Config struct {
Note NoteConfig
Groups map[string]GroupConfig
Format FormatConfig
Tool ToolConfig
Aliases map[string]string
Extra map[string]string
@ -26,6 +27,21 @@ func (c Config) RootGroupConfig() GroupConfig {
}
}
// FormatConfig holds the configuration for document formats, such as Markdown.
type FormatConfig struct {
Markdown MarkdownConfig
}
// MarkdownConfig holds the configuration for Markdown documents.
type MarkdownConfig struct {
// Hashtags indicates whether #hashtags are supported.
Hashtags bool `toml:"hashtags" default:"true"`
// ColonTags indicates whether :colon:tags: are supported.
ColonTags bool `toml:"colon-tags" default:"false"`
// MultiwordTags indicates whether #multi-word tags# are supported.
MultiwordTags bool `toml:"multiword-tags" default:"false"`
}
// ToolConfig holds the external tooling configuration.
type ToolConfig struct {
Editor opt.String
@ -163,6 +179,7 @@ func ParseConfig(content []byte, templatesDir string) (*Config, error) {
return &Config{
Note: root.Note,
Groups: groups,
Format: tomlConf.Format,
Tool: ToolConfig{
Editor: opt.NewNotEmptyString(tomlConf.Tool.Editor),
Pager: opt.NewStringWithPtr(tomlConf.Tool.Pager),
@ -224,6 +241,7 @@ func (c GroupConfig) merge(tomlConf tomlGroupConfig, name string, templatesDir s
type tomlConfig struct {
Note tomlNoteConfig
Groups map[string]tomlGroupConfig `toml:"group"`
Format FormatConfig
Tool tomlToolConfig
Extra map[string]string
Aliases map[string]string `toml:"alias"`

@ -27,6 +27,13 @@ func TestParseDefaultConfig(t *testing.T) {
Lang: "en",
},
Groups: make(map[string]GroupConfig),
Format: FormatConfig{
Markdown: MarkdownConfig{
Hashtags: true,
ColonTags: false,
MultiwordTags: false,
},
},
Tool: ToolConfig{
Editor: opt.NullString,
Pager: opt.NullString,
@ -58,6 +65,11 @@ func TestParseComplete(t *testing.T) {
id-length = 4
id-case = "lower"
[format.markdown]
hashtags = false
colon-tags = true
multiword-tags = true
[tool]
editor = "vim"
pager = "less"
@ -168,6 +180,13 @@ func TestParseComplete(t *testing.T) {
},
},
},
Format: FormatConfig{
Markdown: MarkdownConfig{
Hashtags: false,
ColonTags: true,
MultiwordTags: true,
},
},
Tool: ToolConfig{
Editor: opt.NewString("vim"),
Pager: opt.NewString("less"),
@ -269,6 +288,13 @@ func TestParseMergesGroupConfig(t *testing.T) {
},
},
},
Format: FormatConfig{
Markdown: MarkdownConfig{
Hashtags: true,
ColonTags: false,
MultiwordTags: false,
},
},
Aliases: make(map[string]string),
Extra: map[string]string{
"hello": "world",

@ -82,6 +82,17 @@ template = "default.md"
#key = "value"
# MARKDOWN SETTINGS
[format.markdown]
# Enable support for #hashtags
hashtags = true
# Enable support for :colon:separated:tags:
#colon-tags = true
# Enable support for Bear's #multi-word tags#
# Hashtags must be enabled for multi-word tags to work.
#multiword-tags = true
# EXTERNAL TOOLS
[tool]

@ -5,6 +5,7 @@ Each [notebook](notebook.md) contains a configuration file used to customize you
* `[note]` sets the [note creation rules](config-note.md)
* `[extra]` contains free [user variables](config-extra.md) which can be expanded in templates
* `[group]` defines [note groups](config-group.md) with custom rules
* `[format]` configures the [note format settings](note-format.md), such as Markdown options.
* `[tool]` customizes interaction with external programs such as:
* [your default editor](tool-editor.md)
* [your default pager](tool-pager.md)
@ -61,6 +62,14 @@ paths = ["journal/weekly", "journal/daily"]
filename = "{{date now}}"
# MARKDOWN SETTINGS
[format.markdown]
# Enable support for #hashtags
hashtags = true
# Enable support for :colon:separated:tags:
colon-tags = true
# EXTERNAL TOOLS
[tool]

@ -1,5 +1,5 @@
# A future-proof notebook
`zk` is designed to be future-proof and rely on simple plain text formats such as Markdown.
`zk` is designed to be future-proof and rely on simple [plain text formats](note-format.md) such as Markdown.
The shape of your [notebook](notebook.md) is entirely up to you, making `zk` flexible enough to be used in a variety of contexts. However, `zk` shines in a Zettelkasten-style notebook with many small interlinked notes.

@ -0,0 +1,13 @@
# Note formats
To keep your notebooks [future-proof](future-proof.md), `zk` uses a simple plain text format for your notes. Only Markdown is supported at the moment, but more formats may be added in the future.
You can set up some features of `zk`'s Markdown parser from your [configuration file](config.md), under the `[format.markdown]` section.
| Setting | Default | Description |
|------------------|---------|------------------------------------------------------------------------|
| `hashtags ` | `true` | Enable `#hashtags` support |
| `colon-tags` | `false` | Enable `:colon:separated:tags:` support |
| `multiword-tags` | `false` | Enable Bear's [`#multi-word tags#`][1]. Hashtags must also be enabled. |
[1]: https://blog.bear.app/2017/11/bear-tips-how-to-create-multi-word-tags/
Loading…
Cancel
Save