You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
-
# Contributing to markdown-shortcuts.nvim
1
+
# Contributing to markdown-tools.nvim
2
2
3
-
Thank you for considering contributing to `markdown-shortcuts.nvim`! We appreciate your time and effort.
3
+
Thank you for considering contributing to `markdown-tools.nvim`! We appreciate your time and effort.
4
4
5
5
## How Can I Contribute?
6
6
7
7
### Reporting Bugs
8
8
9
-
- Ensure the bug was not already reported by searching on GitHub under [Issues](https://github.com/magnusriga/markdown-shortcuts.nvim/issues).
10
-
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/magnusriga/markdown-shortcuts.nvim/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
9
+
- Ensure the bug was not already reported by searching on GitHub under [Issues](https://github.com/magnusriga/markdown-tools.nvim/issues).
10
+
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/magnusriga/markdown-tools.nvim/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
> Enhancing your Markdown editing experience in Neovim with intuitive shortcuts and commands.
9
7
10
8
`markdown-tools.nvim` provides a set of commands and configurable keymaps to streamline common Markdown editing tasks, from inserting elements like headers and code blocks to managing checkbox lists and creating files from templates.
11
9
10
+
For users migrating from plugins like [obsidian.nvim](https://github.com/epwalsh/obsidian.nvim), `markdown-tools.nvim` aims to fill some gaps by offering features such as creating new notes based on templates with predefined frontmatter, helping maintain a familiar workflow.
11
+
12
+
The markdown created, including the frontmatter, is compatible with [obsidian](https://obsidian.md/) and other Markdown editors.
13
+
12
14
## ✨ Features
13
15
14
-
-**Insert Markdown Elements:** Quickly add headers, code blocks (with language prompt), bold/italic text, links, tables, and checkbox list items.
15
-
-**Visual Mode Integration:** Wrap selected text with bold, italic, links, or code blocks.
16
+
-**Template Creation:** Create new Markdown files from predefined templates using your choice of picker (`fzf`, `telescope`, `snacks`). Automatically adds frontmatter with configurable placeholders (e.g., `alias`, `tags`).
17
+
-**Insert Markdown Elements:** Quickly add links, checkboxes, tables, headers, bold/italic/highlight text, code blocks (with language prompt), and more.
18
+
-**Visual Mode Integration:** Wrap selected text with bold, italic, links, or highlights.
16
19
-**Checkbox Management:** Insert new checkboxes (`- [ ]`) and toggle their state (`- [x]`).
17
-
-**Template Creation:** Create new Markdown files from predefined templates using your choice of picker (`fzf`, `telescope`, `mini.pick`).
---@fieldtemplate_dirstring Directory for templates
216
+
---@fieldpicker'fzf' | 'snacks' | 'telescope' Picker to use for file selection
217
+
---@fieldaliasstring[] Default aliases for new markdown files
218
+
---@fieldtagsstring[] Default tags for new markdown files
219
+
---@fieldinsert_frontmatterboolean Automatically add frontmatter when creating new markdown files with e.g. `MarkdownNewTemplate`.
220
+
---@fieldfrontmatter_idfun(opts: {timestamp: string, filename: string, sanitized_name: string, filepath: string}):string | nil Function to generate the 'id' field in the frontmatter. Return nil to omit the id field.
221
+
---@fieldfrontmatter_titlefun(opts: {timestamp: string, filename: string, sanitized_name: string, filepath: string}):string | nil Function to generate the 'title' field in the frontmatter. Return nil to omit the title field.
222
+
---@fieldfrontmatter_aliasfun(opts: {timestamp: string, filename: string, sanitized_name: string, filepath: string}):string[] | nil Function to generate the 'alias' field in the frontmatter. Return nil to omit the alias field.
223
+
---@fieldfrontmatter_tagsfun(opts: {timestamp: string, filename: string, sanitized_name: string, filepath: string}):string[] | nil Function to generate the 'tags' field in the frontmatter. Return nil to omit the tags field.
224
+
---@fieldfrontmatter_datefun(opts: {timestamp: string, filename: string, sanitized_name: string, filepath: string}):string | nil Function to generate the 'date' field in the frontmatter. Return nil to omit the date field.
225
+
---@fieldfrontmatter_customtable<string, fun(opts: {timestamp: string, filename: string, sanitized_name: string, filepath: string}):string|string[]|nil> Table defining custom frontmatter fields and their generator functions.
226
+
---@fieldkeymapsKeymapConfig Keymappings for markdown shortcuts
227
+
---@fieldcommandsCommandEnableConfig Configuration for enabling/disabling commands
228
+
---@fieldpreview_commandstring|function|nil Command or function to use for previewing markdown
229
+
---@fieldenable_local_optionsboolean Whether to enable local options for markdown files
230
+
---@fieldwrapboolean Whether to enable line wrapping for markdown files
231
+
---@fieldconceallevelnumber Conceallevel for markdown files
232
+
---@fieldconcealcursorstring Concealcursor for markdown files
233
+
---@fieldspellboolean Whether to enable spell checking for markdown files
234
+
---@fieldspelllangstring Language for spell checking
235
+
---@fieldfile_typesstring[] File types where keymaps should be active
236
+
---@fieldcontinue_lists_on_enterboolean Automatically continue lists on Enter
237
+
```
238
+
130
239
## 🚀 Usage
131
240
132
241
### Commands
@@ -137,20 +246,22 @@ The following commands are available, most work in both visual and normal mode:
137
246
-`:MarkdownHeader`: Insert a header. Prompts for level (1-6) or uses `[count]` (e.g., `:3MarkdownHeader`). In Visual mode, wraps selection.
138
247
-`:MarkdownCodeBlock`: Insert a code block. Prompts for language. In Visual mode, wraps selection.
139
248
-`:MarkdownBold`: Insert `**bold text**`. In Visual mode, wraps selection.
249
+
-`:MarkdownHighlight`: Insert `==highlight text==`. In Visual mode, wraps selection.
140
250
-`:MarkdownItalic`: Insert `*italic text*`. In Visual mode, wraps selection.
141
251
-`:MarkdownLink`: Insert `[link text](url)`. Prompts for text and URL. In Visual mode, uses selection as text and prompts for URL.
142
252
-`:MarkdownInsertTable`: Insert a table. Prompts for rows and columns.
143
253
-`:MarkdownCheckbox`: Insert a checkbox list item (`- [ ]`). In Visual mode, uses selection as text.
144
254
-`:MarkdownToggleCheckbox`: Toggles the checkbox state (`[ ]` <=> `[x]`) on the current line.
145
-
-`:MarkdownPreview`: Preview markdown.
255
+
-`:MarkdownPreview`: Preview markdown. Saves the current file, then attempts to preview using: 1) the configured `preview_command`, 2) an auto-detected plugin (`markdown-preview.nvim`, `peek.nvim`, `glow.nvim`, `nvim-markdown-preview`), or 3) the system's default application as a fallback.
146
256
147
257
### Keymaps
148
258
149
259
Default keymaps are provided (see Configuration). Use them in Normal or Visual mode within Markdown files.
150
260
151
-
-`<leader>mh`: Insert header (prompts or use count).
261
+
-`<leader>mH`: Insert header.
152
262
-`<leader>mc`: Insert code block.
153
263
-`<leader>mb`: Insert bold.
264
+
-`<leader>mh`: Insert highlight.
154
265
-`<leader>mi`: Insert italic.
155
266
-`<leader>ml`: Insert link.
156
267
-`<leader>mt`: Insert table.
@@ -159,6 +270,38 @@ Default keymaps are provided (see Configuration). Use them in Normal or Visual m
159
270
-`<leader>mp`: Preview (if configured).
160
271
-`<leader>mnt`: Create new file from template.
161
272
273
+
### Creating Markdown Files from Templates
274
+
275
+
The `:MarkdownNewTemplate` command (default keymap `<leader>mnt`) allows you to create new Markdown files based on templates stored in your configured `template_dir`.
276
+
277
+
1. Run the command.
278
+
2. Select a template file using the configured picker (fzf, telescope, or snacks).
279
+
3. Enter a name for the new file (the `.md` extension will be added automatically if omitted).
280
+
4. The new file will be created in the same directory as the currently open file.
281
+
282
+
#### Frontmatter Handling
283
+
284
+
When creating a file from a template, the configured frontmatter generator functions (`frontmatter_id`, `frontmatter_title`, `frontmatter_custom`, etc.) are always executed first to produce values for the standard and custom fields.
285
+
286
+
These generated values are then used in two ways:
287
+
288
+
1.**Placeholder Replacement:** The content of the selected template file is processed. The following placeholders are supported and replaced with their corresponding generated values:
289
+
290
+
-`{{id}}`: Value from `frontmatter_id` function.
291
+
-`{{title}}`: Value from `frontmatter_title` function.
292
+
-`{{date}}`: Value from `frontmatter_date` function.
293
+
-`{{alias}}`: YAML list format of values from `frontmatter_alias` function (e.g., `["alias1", "alias2"]`).
294
+
-`{{tags}}`: YAML list format of values from `frontmatter_tags` function (e.g., `["tag1", "tag2"]`).
295
+
-`{{datetime}}`: Current date and time (YYYY-MM-DD HH:MM:SS). Generated internally.
296
+
-`{{timestamp}}`: Timestamp used during generation (YYYYMMDDHHMM). Generated internally.
297
+
-`{{key}}`: For each key in `frontmatter_custom`, the corresponding placeholder `{{key}}` is replaced by the value returned by its function. If the function returns a list, it's inserted in YAML list format (e.g., `["item1", "item2"]`).
298
+
299
+
If a generator function returns `nil`, the corresponding placeholder is replaced with an empty string. **Any other text within double curly braces (e.g., `{{unsupported}}`) that does not match a supported placeholder will be left unchanged in the template content.**
300
+
301
+
2.**Automatic Frontmatter Insertion:** After placeholder replacement, the plugin checks if the template content starts with `---`.
302
+
- If it **does not** start with `---` AND the `insert_frontmatter` configuration option is `true` (the default), a new frontmatter block is automatically added to the beginning of the file. This block includes all fields (standard and custom) for which the generator function returned a non-nil value, formatted correctly in YAML. List values will be formatted like `tags: [tag1, tag2]`.
303
+
- If it **does** start with `---`, or if `insert_frontmatter` is `false`, no new frontmatter block is inserted. The template's existing frontmatter (with placeholders already replaced) is kept as is.
304
+
162
305
### List Continuation
163
306
164
307
When `continue_lists_on_enter` is `true`, pressing `Enter` in a Markdown list item (bullet `*`, `-`, `+`; numbered `1.`; checkbox `- [ ]`, `- [x]`) will automatically insert the next list marker on the new line.
@@ -174,3 +317,7 @@ Please see CONTRIBUTING.md or open an issue/pull request.
174
317
## License
175
318
176
319
Distributed under the MIT License. See `LICENSE` file for more information.
320
+
321
+
## 🙏 Credits
322
+
323
+
- The excellent [obsidian.nvim](https://github.com/epwalsh/obsidian.nvim), for inspiration on various features, including creating Markdown notes from templates.
0 commit comments