-
Notifications
You must be signed in to change notification settings - Fork 214
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
Issue 632 support for obsidian callouts #665
base: main
Are you sure you want to change the base?
Issue 632 support for obsidian callouts #665
Conversation
would hhave the same highlights
Looking at it makes me wonder if it's cleaner to not have the blue bit before the highlight group |
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.
Hey @aquilesg this is a great start and I'm really excited about this feature. I ran into some bugs when I tried it out though:
When I have this:
>[!info] foo
it appears to work, although I think the space between ">" and "[" should be required.
When I do add the space:
> [!info] foo
I don't see the info icon anymore.
And when I add another line the first non-space character gets swallowed regardless of whether or not I have a space after ">":
> [!info] foo
> bar
lua/obsidian/ui.lua
Outdated
@@ -515,14 +691,30 @@ local function update_extmarks(bufnr, ns_id, ui_opts) | |||
|
|||
-- Check if inside a code block or at code block boundary. If not, update marks. | |||
if string.match(line, "^%s*```[^`]*$") then | |||
inside_code_block = not inside_code_block | |||
inside_code_block = true |
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.
Why this change?
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.
Oh whoops, I didn't mean to add this. Let me revert.
lua/obsidian/util.lua
Outdated
------------------------- | ||
--- Stack implementation | ||
------------------------- | ||
|
||
-- Create new stack | ||
function util.new_stack() | ||
return {} | ||
end | ||
|
||
-- Push an item onto the stack | ||
function util.push(stack, item) | ||
table.insert(stack, item) | ||
end | ||
|
||
-- Pop an item from the stack | ||
function util.pop(stack) | ||
if #stack == 0 then | ||
return nil | ||
end | ||
return table.remove(stack) | ||
end | ||
|
||
-- Check the top item on the stack | ||
function util.peek(stack) | ||
if #stack == 0 then | ||
return nil | ||
end | ||
return stack[#stack] | ||
end | ||
|
||
-- Check if the stack is empty | ||
function util.is_empty(stack) | ||
return #stack == 0 | ||
end |
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.
Could you move this to lua/obsidian/collections.lua
lua/obsidian/ui.lua
Outdated
local count = 0 | ||
for c = 1, #line do | ||
local char = line:sub(c, c) | ||
if char == ">" then | ||
count = count + 1 | ||
elseif char == "[" then | ||
if line:sub(c, c + 2) == "[!]" then | ||
break | ||
end | ||
end | ||
end |
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.
If this is just counting the number of ">"s then you could do that with regular expressions
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'm a n00b with Lua and regex so I'm struggling to find the correct way to do this.
Do you have any tips?
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 think you could just do local count = util.string_count(line, "> ")
lua/obsidian/search.lua
Outdated
@@ -36,6 +36,7 @@ M.Patterns = { | |||
|
|||
-- Miscellaneous | |||
Highlight = "==[^=]+==", -- ==text== | |||
Callout = "%[!.*%]", |
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.
Shouldn't callouts always start with ">"?
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.
Ah that's right
1f32e4e
to
8befa8d
Compare
lua/obsidian/collections.lua
Outdated
-- Create new stack | ||
function M.new_stack() | ||
return {} | ||
end | ||
|
||
-- Push an item onto the stack | ||
function M.push(stack, item) | ||
table.insert(stack, item) | ||
end | ||
|
||
-- Pop an item from the stack | ||
function M.pop(stack) | ||
if #stack == 0 then | ||
return nil | ||
end | ||
return table.remove(stack) | ||
end | ||
|
||
-- Check the top item on the stack | ||
function M.peek(stack) | ||
if #stack == 0 then | ||
return nil | ||
end | ||
return stack[#stack] | ||
end | ||
|
||
-- Check if the stack is empty | ||
function M.is_empty(stack) | ||
return #stack == 0 | ||
end |
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.
This isn't really how Lua classes are implemented, and it doesn't seem necessary to have a separate class here anyway since it's just a very thin wrapper around a raw table/list.
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'm fine with removing this all together then.
lua/obsidian/ui.lua
Outdated
callout_mark_start, | ||
callout_mark_end |
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 don't think these args are actually used
lua/obsidian/ui.lua
Outdated
local count = 0 | ||
for c = 1, #line do | ||
local char = line:sub(c, c) | ||
if char == ">" then | ||
count = count + 1 | ||
elseif char == "[" then | ||
if line:sub(c, c + 2) == "[!]" then | ||
break | ||
end | ||
end | ||
end |
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 think you could just do local count = util.string_count(line, "> ")
This adds the ability to preview images on Mac OS using `qlmanage`. See the example in the README. (epwalsh#411) See also epwalsh#660.
* fix: corrects typo on ObsidianPasteImg's description * docs: updates changelog
c516b2a
to
f8538c4
Compare
This adds UI support for the callout groups that are defined
in the Obsidian documentation.
It also supports custom alias definitions.
The result is below: