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

Inconsistent formatting with markdown codeblocks vs native file #1256

Open
4 tasks done
cavanaug opened this issue Oct 31, 2024 · 4 comments
Open
4 tasks done

Inconsistent formatting with markdown codeblocks vs native file #1256

cavanaug opened this issue Oct 31, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@cavanaug
Copy link

Checklist

  • I have searched through the AstroNvim documentation
  • I have searched through the existing issues of this project
  • I have searched the existing issues of plugins related to this issue
  • I can replicate the bug with the minimal repro.lua provided 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 cavanaug added the bug Something isn't working label Oct 31, 2024
@Uzaaft
Copy link
Member

Uzaaft commented Nov 1, 2024

@cavanaug Use the issue template properly and fill in the minimal config.

@Uzaaft
Copy link
Member

Uzaaft commented Nov 1, 2024

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.

@azdanov
Copy link

azdanov commented Nov 14, 2024

Does Prettier format markdown code blocks?

@ALameLlama
Copy link
Member

I think this is prettierd doing the code formatting and I don't think it supports doing code blocks differently like azdanov said

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants