OXY2DEV / markview.nvim

An experimental markdown previewer for Neovim
Apache License 2.0
1.26k stars 35 forks source link

Working config for "label" heading? #22

Closed pkazmier closed 3 months ago

pkazmier commented 3 months ago

Can you share a working configuration that would produce this style of headings? I've been trying different permutations from the wiki page, but I'm getting various errors and cannot figure out the secret incantation I'm supposed to be doing. Ideally, if I could add an icon to the front of those headings as well (without the shift_width), it would be perfect.

image

On the wiki, there is this example:

    style = "label",

    hl = "rainbow1",

    corner_left = "", corner_left_hl = nil,
    corner_right = "", corner_right_hl = nil,

    padding_left = "", padding_left_hl = nil,
    padding_right = "", padding_right_hl = nil,

    icon = "", icon_hl = nil,
    text = "", text_hl = nil,

    sign = nil, sign_hl = nil

But it fails with "attempt call field 'position' (nil value)". Any help would be appreciated as I really like the design choices you have made here. It looks lovely and as one that spends most of my time taking notes in markdown, I appreciate all your efforts!

OXY2DEV commented 3 months ago

This is the actual table for headings.

require("markview").setup({
    heading = {
        enable = true,
        shift_width = 4,

        heading_1 = {},
        heading_2 = {},
        heading_3 = {},
        heading_4 = {},
        heading_5 = {},
        heading_6 = {}
    }
});

What you are showing should be inside the heading_1(and all the other headings if you are configuring them too).

I will update the wiki to be more clear.

OXY2DEV commented 3 months ago

Check this table it has everything configured(it is used in the screenshot).

You can see how I did it.

pkazmier commented 3 months ago

Sorry if I was not clear, I do understand the top-level configuration and had the block of code in the right location. In addition, I had also discovered that table you shared, but even that configuration does not work for me as I get this error:

E5108: Error executing lua vim/_editor.lua:0: nvim_exec2()..BufWinEnter Autocommands for "<buffer=3>": Vim(append):Error executing lua callback: .
..te/pack/deps/opt/markview.nvim/lua/markview/renderer.lua:586: attempt to call field 'position' (a nil value)
stack traceback:
        ...te/pack/deps/opt/markview.nvim/lua/markview/renderer.lua:586: in function 'render_headers'
        ...te/pack/deps/opt/markview.nvim/lua/markview/renderer.lua:1153: in function 'render'
        ...m/site/pack/deps/opt/markview.nvim/ftplugin/markdown.lua:43: in function <...m/site/pack/deps/opt/markview.nvim/ftplugin/markdown.lua:2
9>
        [C]: in function 'nvim_exec2'
        vim/_editor.lua: in function 'cmd'
        ...ivim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:1528: in function 'eval_fun_or_string'
        ...ivim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:908: in function 'eval_current_item'
        [string ":lua"]:1: in main chunk
stack traceback:
        [C]: in function 'nvim_exec2'
        vim/_editor.lua: in function 'cmd'
        ...ivim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:1528: in function 'eval_fun_or_string'
        ...ivim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:908: in function 'eval_current_item'
        [string ":lua"]:1: in main chunk

And here is the config I tried:

require("markview").setup({
  modes = { "n", "i" },
  headings = {

    enable = true,
    shift_width = 0,

    heading_1 = {
      style = "label",

      padding_left = " ",
      padding_right = " ",

      corner_right = "",
      corner_right_hl = "decorated_h1_inv",

      hl = "decorated_h1",
    },
    heading_2 = {
      style = "label",

      padding_left = " ",
      padding_right = " ",

      corner_right = "",
      corner_right_hl = "decorated_h2_inv",

      hl = "decorated_h2",
    },
    heading_3 = {
      style = "label",

      padding_left = " ",
      padding_right = " ",

      corner_right = "",
      corner_right_hl = "decorated_h3_inv",

      hl = "decorated_h3",
    },
    heading_4 = {
      style = "label",

      padding_left = " ",
      padding_right = " ",

      corner_right = "",
      corner_right_hl = "decorated_h4_inv",

      hl = "decorated_h4",
    },
    heading_5 = {
      style = "label",

      padding_left = " ",
      padding_right = " ",

      corner_right = "",
      corner_right_hl = "decorated_h5_inv",

      hl = "decorated_h5",
    },
    heading_6 = {
      style = "label",

      padding_left = " ",
      padding_right = " ",

      corner_right = "",
      corner_right_hl = "decorated_h6_inv",

      hl = "decorated_h6",
    },
})
pkazmier commented 3 months ago

Also, I'm using main branch as I saw you merged the dev branch to it.

OXY2DEV commented 3 months ago

Ah, that one's a bug. My bad

OXY2DEV commented 3 months ago

Can you check now?

pkazmier commented 3 months ago

No more errors. Looks like I just need to define those decorated highlight groups now. Thanks!

image
OXY2DEV commented 3 months ago

They are also in that file.

Check this line

pkazmier commented 3 months ago

Yeah, just saw that as well. It's looking great now:

image

Just need to find out what happened to my code block background, but that's easy enough. Thanks again!

pkazmier commented 3 months ago

Hmm ... I see when I defined those highlight groups, it overrides all of them, so I no longer get the defaults you had picked for things like the code block, the block quote, etc ... Any chance you can do a vim.tbl_deep_extend to merge user choices with the standard ones?

pkazmier commented 3 months ago

Specifically, I lose these groups when I added the decorated ones. I'll just re-add these manually, but it would be nice to merge versus replace.

image
pkazmier commented 3 months ago

Looking good now! Next step for me is to link all of those highlight groups so I don't have hardcoded values as I switch themes often and would like colors that align with the theme I'm using. But coincidentally your choices look good with my primary theme (minihues).

image

They even look good with my secondary theme (gruvbox-material)—save for the code block:

image
OXY2DEV commented 3 months ago

Specifically, I lose these groups when I added the decorated ones. I'll just re-add these manually, but it would be nice to merge versus replace.

image

You can just do something like vim.list_extend( require("markview").configuration.highlight groups, require("markview.presets").decorated_hls) for that.

pkazmier commented 3 months ago

I submitted #24 which allows a user to use the established idiom of overriding default values via the setup function. One can override only a specific item, while still inheriting the rest of the defaults.

OXY2DEV commented 3 months ago

I submitted #24 which allows a user to use the established idiom of overriding default values via the setup function. One can override only a specific item, while still inheriting the rest of the defaults.

This is not intended behavior. This works great when you are doing small tweaks to the plugin.

But when you try to use the setup function to actually set things up to your need you will have no way(without redefining them) to remove these default highlight groups.

Highlight groups should be maintained by the user as per their needs. And as such they should preferably be maintained by their colorscheme(or similar plugin) not individually by plugins(especially not this one since it doesn't rely on any of the defaults highlight groups). The option is there only for the sake of completeness.

Besides, you can just use vim.list_extend(markview.configuration.highlight groups, { your_list_of_highlights }) to do that.

pkazmier commented 3 months ago

What are your thoughts on this line from the PR?

https://github.com/OXY2DEV/markview.nvim/pull/24/files#diff-f95388a6e004a0ee8f59c156ec09bc8b0545c9f780a52430b21d15a9246c0376R501

Before I got the label headers working, when I wanted to use the default icon headers, I had to define all of them explicitly—even though I had no changes to heading_N—because I could not just set shift_width. Doing so with a shallow extend wiped out your defaults. Thanks.

OXY2DEV commented 3 months ago

What are your thoughts on this line from the PR?

https://github.com/OXY2DEV/markview.nvim/pull/24/files#diff-f95388a6e004a0ee8f59c156ec09bc8b0545c9f780a52430b21d15a9246c0376R501

Before I got the label headers working, when I wanted to use the default icon headers, I had to define all of them explicitly—even though I had no changes to heading_N—because I could not just set shift_width. Doing so with a shallow extend wiped out your defaults. Thanks.

The plugin originally used tbl_deep_extend but there's a problem. You lose the ability to disable parts of the plugin.

Some of the options use nested tables for their configuration and deep extend will result in inconsistent behavior (due to properties set by the plugin getting into places you don't want them).

Plus, some of the options use the hl property which will cause an issue because now you have to explicitly define all the color related properties(as they will otherwise use hl instead).

pkazmier commented 3 months ago

On a tangential note, I really like how my headings stack when using nvim-treesitter-context. In the prior markdown plug-in I used, the formatting of the header reverted back to plain text. But, with your plug-in, the formatting stays, so it looks very nice. Here is a small movie to demonstrate.

https://github.com/OXY2DEV/markview.nvim/assets/747855/64d0d6c9-e654-4311-a595-e7f3af3c3ff9