epwalsh / obsidian.nvim

Obsidian 🀝 Neovim
Apache License 2.0
4.31k stars 196 forks source link

markdown syntax highlight seems not working correctly #116

Closed devstefancho closed 1 year ago

devstefancho commented 1 year ago

πŸ› Describe the bug

image

Hello, I have a problem with syntax highlighting In my case, Syntax highlight is not good. (poor readabillity πŸ₯²) For example, I want to header to be another color (like orange) Is there any way to setup for this? I use treesitter and rose-pine colorscheme

obisidian.lua

return {
  "epwalsh/obsidian.nvim",
  config = function()
    require("obsidian").setup({
      dir = "~/iCloud/Documents/my-vault",
      daily_notes = {
        folder = "daily",
      },
    })
  end,
}

treesitter.lua

return {
  -- Syntax Highlighings
  {
    "nvim-treesitter/nvim-treesitter",
    build = function()
      local ts_update = require("nvim-treesitter.install").update({ with_sync = true })
      ts_update()
    end,
  },
  "nvim-treesitter/playground",
}

treesitter config

local status, ts = pcall(require, "nvim-treesitter.configs")
if not status then
  return
end

-- How to Setup (https://github.com/nvim-treesitter/nvim-treesitter#modules)
ts.setup({
  ensure_installed = {
    "lua",
    "tsx",
    "json",
    "css",
    "javascript",
    "typescript",
    "help",
    "vim",
    "markdown",
    "markdown_inline",
    "html",
    "graphql",
  },
  highlight = {
    enable = true,
    disable = {},
    additional_vim_regex_highlighting = { "markdown" },
  },
  indent = {
    enable = true,
    disable = {},
  },
  context_commentstring = {
    enable = true,
  },
  incremental_selection = {
    enable = true,
    keymaps = {
      init_selection = "<c-space>",
      node_incremental = "<c-space>",
      scope_incremental = "<c-s>",
      node_decremental = "grm",
    },
  },
})

rose-pine.lua (I think this maybe not the reason)

return {
    {
    "rose-pine/neovim",
    name = "rose-pine",
    config = function()
      vim.cmd("colorscheme rose-pine")
    end,
    -- cond = false,
  },
}

Versions

NVIM v0.8.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@HMBRW-A-001-M1-005.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.8.2/share/nvim"

Run :checkhealth for more info
1.8.0
[NvimTree] "open_on_setup behaviour has been deprecated, please see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup"%
epwalsh commented 1 year ago

@devstefancho I updated neovim and treesitter yesterday and I ran into a similar issue. If you haven't already, first try :TSUpdate markdown markdown_inline. If that still doesn't work, make sure treesitter highlighting is actually enabled with :TSEnable highlight. This was the main issue for me even though my treesitter config has highlight.enable = true. So this must be a bug with treesitter. I ended up having to use an autocmd to force enabling highlight:

https://github.com/epwalsh/dotfiles/blob/9f3bf0c96c4925bae807d703ac32e7e98e590670/neovim/lua/plugins/treesitter.lua#L54

devstefancho commented 1 year ago

@epwalsh thanks for your suggestion I copied your tresitter.lua and update the commit hash like your lazy-lock But It still does not work.

image

Sadly πŸ₯² all highlight is gone (only available white color) Do you have syntax highlight for header1~4 ?

image
epwalsh commented 1 year ago

I should mention I'm also using nightly Neovim (upgraded yesterday). That might make a difference. treesitter recommends using nightly. I do get header syntax highlighting for 1-4.

devstefancho commented 1 year ago

I reinstall to nvim nightly (now I use NVIM v0.9.0-dev-1307+g75e1b1d5c-dirt) and after reinstall then try this step , but it didn't work

  1. :Lazy clean nvim-treesitter
  2. :Lazy install nvim-treesitter
  3. :TSInstall markdown markdown_inline
  4. :TSEnable highlight

(also try clean and install obsidian.nvim)

devstefancho commented 1 year ago

Hmm.. Maybe it is not related with obisidian nvim, because another markdown files which is not located in vault have no syntax highlight.

epwalsh commented 1 year ago

Yea I agree it’s probably a bug with treesitter or the markdown parsers. Alternatively you could try a non-treesitter markdown plugin for highlighting like vim-markdown.

On Sat, Apr 1, 2023 at 6:46 AM Steven (stefan cho) @.***> wrote:

Hmm.. Maybe it is not related with obisidian nvim, because another markdown files which is not located in vault have no syntax highlight.

β€” Reply to this email directly, view it on GitHub https://github.com/epwalsh/obsidian.nvim/issues/116#issuecomment-1492974351, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDHPKZSLVFYOFIQ3R4HTFTW7AWRVANCNFSM6AAAAAAWO4HCEM . You are receiving this because you were mentioned.Message ID: @.***>

--

[image: Logo for the Allen Institute for AI] https://allenai.org/

Pete Walsh (he/him)

Engineering @ Allen Institute for AI

devstefancho commented 1 year ago

@epwalsh Thanks to your continuous support, I'm finally done

This issue is not from obsidian, but it's my fault

  1. Treesitter docs As you said, treesitter recommend to install nightly version of nvim

  2. Colorscheme rose-pine theme probably does not support markdown fully, so I change to tokyonight theme after that, header1~4 is now highlighted

  3. Treesitter installation info I should have checked the installation of javascript, typescript, tsx for markdown multiline code and single-line code when I checked :TSInstallInfo those languages are not installed, I don't know why those languages are not installed (which were included in ensured_installed), but after installing them manually, now all looks good :TSInstall markdown markdown_inline javascript typescript tsx css yaml

image
epwalsh commented 1 year ago

Awesome, I'm glad you figured it out!