Inconsistent formatting with markdown codeblocks vs native file
Checklist
- [X] I have searched through the AstroNvim documentation
- [X] I have searched through the existing issues of this project
- [X] I have searched the existing issues of plugins related to this issue
- [X] I can replicate the bug with the minimal
repro.luaprovided below
Neovim version (nvim -v)
NVIM v0.10.2 Build type: Release LuaJIT 2.1.1727870382
Operating system/version
debian linux
Terminal/GUI
windows terminal
Describe the bug
Im seeing inconsistent formatting for json files vs json codeblocks in markdown. When editing a standard json file, I get things appropriately mapped with my editorconfig settings of
[*.json]
indent_style = space
indent_size = 4
[*.yaml]
indent_style = space
indent_size = 2
So everything when I run an lsp format is properly formatting with 4 spaces.
But if I bring the same exact json content into a markdown codeblock wrapped with a json type and I do an lsp format I get the same data but it is expanded with tabs, not spaces. This makes it awkward when I check in a file and it is viewed in Github preview, the tabs are then expanded out to 8 spaces and it looks awful.
yaml ironically works identically for formatting a native file or within a code block. That is the behavior I would expect for json as well.
Steps to Reproduce
Load a vanilla astrovim with the included community.lua file
utilize any small json file, and compare its formatting between a native file and the same content in a markdown json codeblock
Expected behavior
I would expect the same formatting (ie. spaces) that I see when editing a json file natively
Screenshots
No response
Additional Context
-- AstroCommunity: import any community modules here
-- We import this file in lazy_setup.lua before the plugins/ folder.
-- This guarantees that the specs are processed before any user plugins.
---@type LazySpec return { "AstroNvim/astrocommunity", { import = "astrocommunity.pack.lua" }, { import = "astrocommunity.pack.markdown" }, { import = "astrocommunity.pack.json" }, { import = "astrocommunity.pack.yaml" }, -- import/override with your plugins folder }
Minimal configuration
-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
-- stylua: ignore
vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)
-- install plugins
local plugins = {
{ "AstroNvim/AstroNvim", import = "astronvim.plugins" },
{ "AstroNvim/astrocommunity" },
-- add any other plugins/customizations here
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
-- ONLY THING IS THE community.lua file I listed in additional context
@cavanaug Use the issue template properly and fill in the minimal config.
I dont think this can be attributed as a bug in the pack, or just a limitation to the upstream plugins that the pack is using. The Json lsp isnt running when editing a markdown file, so its seems like its either markdown-oxide, or perhaps treesitter(Dont see how but just leaving this here) thats formatting the buffer and the code blocks.
Does Prettier format markdown code blocks?
I think this is prettierd doing the code formatting and I don't think it supports doing code blocks differently like azdanov said
Is this still an issue?