Skip to content

Commit c6d2670

Browse files
committed
added option to not add title as header automatically
1 parent 14e0427 commit c6d2670

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Added `opts.follow_img_func` option for customizing how to handle image paths.
1313
- Added better handling for undefined template fields, which will now be prompted for.
14+
- Added a `title_as_header` config option to decide whether or not note.title is added as the first header (`# note.title`).
15+
1416

1517
### Changed
1618

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ This is a complete list of all of the options that can be passed to `require("ob
350350
-- Either 'wiki' or 'markdown'.
351351
preferred_link_style = "wiki",
352352

353+
-- Optional, boolean.
354+
-- `false` indicates that you don't want obsidian.nvim to manage add `note.title` as the first
355+
-- header.
356+
title_as_header = true,
357+
353358
-- Optional, boolean or a function that takes a filename and returns a boolean.
354359
-- `true` indicates that you don't want obsidian.nvim to manage frontmatter.
355360
disable_frontmatter = false,

lua/obsidian/client.lua

+6
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,8 @@ Client.write_note = function(self, note, opts)
18311831
local path = assert(opts.path or note.path, "A path must be provided")
18321832
path = Path.new(path)
18331833

1834+
local title_as_header = require("obsidian").get_client().opts.title_as_header
1835+
18341836
---@type string
18351837
local verb
18361838
if path:is_file() then
@@ -1847,6 +1849,10 @@ Client.write_note = function(self, note, opts)
18471849
frontmatter = self.opts.note_frontmatter_func(note)
18481850
end
18491851

1852+
if not title_as_header then
1853+
note.title = nil
1854+
end
1855+
18501856
note:save {
18511857
path = path,
18521858
insert_frontmatter = self:should_save_frontmatter(note),

lua/obsidian/config.lua

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ local config = {}
1818
---@field follow_url_func fun(url: string)|?
1919
---@field follow_img_func fun(img: string)|?
2020
---@field note_frontmatter_func (fun(note: obsidian.Note): table)|?
21+
---@field title_as_header boolean|?
2122
---@field disable_frontmatter (fun(fname: string?): boolean)|boolean|?
2223
---@field completion obsidian.config.CompletionOpts
2324
---@field mappings obsidian.config.MappingOpts
@@ -51,6 +52,7 @@ config.ClientOpts.default = function()
5152
preferred_link_style = config.LinkStyle.wiki,
5253
follow_url_func = nil,
5354
note_frontmatter_func = nil,
55+
title_as_header = true,
5456
disable_frontmatter = false,
5557
completion = config.CompletionOpts.default(),
5658
mappings = config.MappingOpts.default(),

lua/obsidian/note.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ Note.save_to_buffer = function(self, opts)
754754

755755
local cur_buf_note = Note.from_buffer(bufnr)
756756

757+
local title_as_header = require("obsidian").get_client().opts.title_as_header
758+
757759
---@type string[]
758760
local new_lines
759761
if opts.insert_frontmatter ~= false then
@@ -762,7 +764,7 @@ Note.save_to_buffer = function(self, opts)
762764
new_lines = {}
763765
end
764766

765-
if util.buffer_is_empty(bufnr) and self.title ~= nil then
767+
if util.buffer_is_empty(bufnr) and self.title ~= nil and title_as_header then
766768
table.insert(new_lines, "# " .. self.title)
767769
end
768770

0 commit comments

Comments
 (0)