Skip to content
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

Please help style headlines in markdown #37

Open
prankousky opened this issue Jul 16, 2022 · 3 comments
Open

Please help style headlines in markdown #37

prankousky opened this issue Jul 16, 2022 · 3 comments

Comments

@prankousky
Copy link

Hi everybody,

I just stumbled upon this plugin; since I use markdown a bunch, I wanted to integrate it in my workflow.

This is the ~/.config/nvim/plugin/headlines.vim file I started with:

lua << EOF

vim.cmd [[highlight Headline1 guibg=#F0F]]
vim.cmd [[highlight Headline2 guibg=#F0F]]
vim.cmd [[highlight CodeBlock guibg=#F0F]]
vim.cmd [[highlight Dash guibg=#F0F gui=bold]]

require("headlines").setup {
    markdown = {
        headline_highlights = { "Headline1", "Headline2" },
    },
}
EOF

I used #F0F so that any changes would be clearly visible. But it seems like these lines don't make any difference, whether they are there, or not, or commented out.

I changed that file to the bare minimum as well

lua << EOF
require('headlines').setup()
EOF

What do I need to change in order to make it look like in the example image? Screenshot
grafik

Example Image
grafik

I also tried the default config, but it did not work. When I use this, I got some errors; I realized they could be solved by :TSInstall org, :TSInstall norg. I tried added the color modifying block again (see below image). However, after doing this, it looked like this

grafik

This is the file I used for the screenshot above

lua << EOF

vim.cmd [[highlight Headline1 guibg=#F0F]]
vim.cmd [[highlight Headline2 guibg=#F0F]]
vim.cmd [[highlight CodeBlock guibg=#F0F]]
vim.cmd [[highlight Dash guibg=#F0F gui=bold]]

require("headlines").setup {
    markdown = {
        query = vim.treesitter.parse_query(
            "markdown",
            [[
                (atx_heading [
                    (atx_h1_marker)
                    (atx_h2_marker)
                    (atx_h3_marker)
                    (atx_h4_marker)
                    (atx_h5_marker)
                    (atx_h6_marker)
                ] @headline)

                (thematic_break) @dash

                (fenced_code_block) @codeblock

                (block_quote_marker) @quote
                (block_quote (paragraph (inline (block_continuation) @quote)))
            ]]
        ),
        headline_highlights = { "Headline" },
        codeblock_highlight = "CodeBlock",
        dash_highlight = "Dash",
        dash_string = "-",
        quote_highlight = "Quote",
        quote_string = "",
        fat_headlines = true,
    },
    rmd = {
        query = vim.treesitter.parse_query(
            "markdown",
            [[
                (atx_heading [
                    (atx_h1_marker)
                    (atx_h2_marker)
                    (atx_h3_marker)
                    (atx_h4_marker)
                    (atx_h5_marker)
                    (atx_h6_marker)
                ] @headline)

                (thematic_break) @dash

                (fenced_code_block) @codeblock

                (block_quote_marker) @quote
                (block_quote (paragraph (inline (block_continuation) @quote)))
            ]]
        ),
        treesitter_language = "markdown",
        headline_highlights = { "Headline" },
        codeblock_highlight = "CodeBlock",
        dash_highlight = "Dash",
        dash_string = "-",
        quote_highlight = "Quote",
        quote_string = "",
        fat_headlines = true,
    },
    norg = {
        query = vim.treesitter.parse_query(
            "norg",
            [[
                [
                    (heading1_prefix)
                    (heading2_prefix)
                    (heading3_prefix)
                    (heading4_prefix)
                    (heading5_prefix)
                    (heading6_prefix)
                ] @headline

                (weak_paragraph_delimiter) @dash
                (strong_paragraph_delimiter) @doubledash

                ((ranged_tag
                    name: (tag_name) @_name
                    (#eq? @_name "code")
                ) @codeblock (#offset! @codeblock 0 0 1 0))

                (quote1_prefix) @quote
            ]]
        ),
        headline_highlights = { "Headline" },
        codeblock_highlight = "CodeBlock",
        dash_highlight = "Dash",
        dash_string = "-",
        doubledash_highlight = "DoubleDash",
        doubledash_string = "=",
        quote_highlight = "Quote",
        quote_string = "",
        fat_headlines = true,
    },
    org = {
        query = vim.treesitter.parse_query(
            "org",
            [[
                (headline (stars) @headline)

                (
                    (expr) @dash
                    (#match? @dash "^-----+$")
                )

                (block
                    name: (expr) @_name
                    (#eq? @_name "SRC")
                ) @codeblock

                (paragraph . (expr) @quote
                    (#eq? @quote ">")
                )
            ]]
        ),
        headline_highlights = { "Headline" },
        codeblock_highlight = "CodeBlock",
        dash_highlight = "Dash",
        dash_string = "-",
        quote_highlight = "Quote",
        quote_string = "",
        fat_headlines = true,
    },
}
EOF

I like the way the colors are in the example image. Also, I am planning to use this exclusively for markdown (no org, no norg, nothing else); could you please tell me how a minimal configuration would have to look in order to make markdown files look like in the example? This way, I could build on top of it in case I want to change the look.

Thank you in advance for your help :)

@lukas-reineke
Copy link
Owner

#F0F is not a valid hex color in Neovim. You have to type it out, #FF00FF should work.

When I use this, I got some errors; [...] Also, I am planning to use this exclusively for markdown (no org, no norg, nothing else);

Just don't include the default values in your config, then you won't get any errors.

@prankousky
Copy link
Author

Thank you. Using valid hex color works, and I got familiar with the syntax. I stripped the code down to what's below. I also tried to read the different :h headlines* files and believe the answer is "no", but I'll ask anyway: is it possible to get an icon similar to what you have in a headline / another headline etc. on the example image I posted in my initial questin?

It still displays # / ## etc. for me, but I use markdown, not org, so perhaps that's why.

~/.config/nvim/plugin/headlines.vim

lua << EOF

vim.cmd [[highlight Headline1 guibg=#2C6E00 guifg=#58DB01 gui=italic]]
vim.cmd [[highlight Headline2 guibg=#C8DB01 guifg=#2C6E00 gui=italic]]
--
vim.cmd [[highlight CodeBlock guibg=#07230E guifg=lightyellow]]
--
vim.cmd [[highlight Quote guifg=#0099EC]]
--
-- vim.cmd [[highlight Dash guibg=#58DB01]]
-- vim.cmd [[highlight Dash guifg=#58DB01 gui=bold]]

require("headlines").setup {
    markdown = {
        headline_highlights = {
            "Headline1",
            "Headline2"
            },
        fat_headlines = false,
        fat_headline_upper_string = "",
        --
        codeblock_highlight = "CodeBlock",
        --
        quote_highlight = "Quote",
        -- quote_string = "",
        quote_string = ">> ",
        --
        dash_highlight = "Dash",
        dash_string = "_",
    },
}
EOF

@lukas-reineke
Copy link
Owner

The icons are not from this plugin. They are from https://github.com/akinsho/org-bullets.nvim
But yes, it's orgmode only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants