Skip to content

feature: codeblocks should have a true left margin #656

@printfdebugging

Description

@printfdebugging

Is your feature request related to a problem? Please describe.

margin for other elements like headings, bullets etc is true margin i.e. the cursor cannot enter that area in normal mode. codeblocks should also have a similar margin, this would improve their appearance a lot.

Image

something like this. i have added 2 spaces before ach line of code, but that doesn't work well as the indentation lines show up on the left side. the actual codeblock markers start from that indentation line..

Image

but if instead we can move the entire codeblock right by 2 spaces and highlight those two spaces with code block color, it would improve the appearance of the code block and also not mess up with the indentation lines.

Describe the solution you'd like

the solution would be to add an option "block_margin" or something similar which would work similar to heading indentations but the codeblock will still be rendered (the background) on those margin spaces...

Describe alternatives you've considered

alternative is to just be happy in what you have :)

Additional information

my plugin config

return {
  "MeanderingProgrammer/render-markdown.nvim",
  config = function()
    require("render-markdown").setup({
      render_modes = true,
      anti_conceal = {
        enabled = true,
        disabled_modes = false,
        above = 0,
        below = 0,
        ignore = {
          code_background = true,
          indent = true,
          sign = true,
          virtual_lines = true,
        },
      },
      link = {
        enabled = true,
        render_modes = false,
        footnote = {
          enabled = true,
          icon = "󰯔 ",
          body = function(ctx)
            return ctx.text
          end,
          superscript = true,
          prefix = "",
          suffix = "",
        },
        image = "󰥶 ",
        image_custom = true,
        email = "󰀓 ",
        hyperlink = "󰌹 ",
        highlight = "RenderMarkdownLink",
        highlight_title = "RenderMarkdownLinkTitle",
        wiki = {
          enabled = true,
          icon = "󱗖 ",
          conceal_destination = true,
          body = function()
            return nil
          end,
          highlight = "RenderMarkdownWikiLink",
          scope_highlight = nil,
        },
        custom = {
          web = { icon = "󰖟 ", pattern = "^http" },
          apple = { icon = "", pattern = "apple%.com", kind = "url" },
          discord = { icon = "󰙯 ", pattern = "discord%.com", kind = "url" },
          github = { icon = "󰊤 ", pattern = "github%.com", kind = "url" },
          gitlab = { icon = "󰮠 ", pattern = "gitlab%.com", kind = "url" },
          google = { icon = "󰊭 ", pattern = "google%.com", kind = "url" },
          hackernews = { icon = "", pattern = "ycombinator%.com", kind = "url" },
          linkedin = { icon = "󰌻 ", pattern = "linkedin%.com", kind = "url" },
          microsoft = { icon = "", pattern = "microsoft%.com", kind = "url" },
          neovim = { icon = "", pattern = "neovim%.io", kind = "url" },
          reddit = { icon = "󰑍 ", pattern = "reddit%.com", kind = "url" },
          slack = { icon = "󰒱 ", pattern = "slack%.com", kind = "url" },
          stackoverflow = { icon = "󰓌 ", pattern = "stackoverflow%.com", kind = "url" },
          steam = { icon = "", pattern = "steampowered%.com", kind = "url" },
          twitter = { icon = "", pattern = "twitter%.com", kind = "url" },
          wikipedia = { icon = "󰖬 ", pattern = "wikipedia%.org", kind = "url" },
          x = { icon = "", pattern = "x%.com", kind = "url" },
          youtube = { icon = "󰗃 ", pattern = "youtube[^.]*%.com", kind = "url" },
          youtube_short = { icon = "󰗃 ", pattern = "youtu%.be", kind = "url" },
        },
      },
      bullet = {
        enabled = true,
        render_modes = false,
        icons = { "", "", "", "" },
        ordered_icons = function(ctx)
          local value = vim.trim(ctx.value)
          local index = tonumber(value:sub(1, #value - 1))
          return ("%d."):format(index > 1 and index or ctx.index)
        end,
        left_pad = 0,
        right_pad = 0,
        highlight = "RenderMarkdownBullet",
        scope_highlight = {},
        scope_priority = nil,
      },
      quote = {
        enabled = true,
        render_modes = false,
        icon = "",
        repeat_linebreak = false,
        highlight = {
          "RenderMarkdownQuote1",
          "RenderMarkdownQuote2",
          "RenderMarkdownQuote3",
          "RenderMarkdownQuote4",
          "RenderMarkdownQuote5",
          "RenderMarkdownQuote6",
        },
      },
      callout = {
        note = {
          raw = "[!NOTE]",
          rendered = "󰋽  Note",
          highlight = "RenderMarkdownInfo",
          category = "github",
        },
        tip = {
          raw = "[!TIP]",
          rendered = "󰌶 Tip",
          highlight = "RenderMarkdownSuccess",
          category = "github",
        },
        important = {
          raw = "[!IMPORTANT]",
          rendered = "󰅾  Important",
          highlight = "RenderMarkdownHint",
          category = "github",
        },
        warning = {
          raw = "[!WARNING]",
          rendered = "󰀪  Warning",
          highlight = "RenderMarkdownWarn",
          category = "github",
        },
        caution = {
          raw = "[!CAUTION]",
          rendered = "󰳦  Caution",
          highlight = "RenderMarkdownError",
          category = "github",
        },
        abstract = {
          raw = "[!ABSTRACT]",
          rendered = "󰨸  Abstract",
          highlight = "RenderMarkdownInfo",
          category = "obsidian",
        },
        summary = {
          raw = "[!SUMMARY]",
          rendered = "󰨸  Summary",
          highlight = "RenderMarkdownInfo",
          category = "obsidian",
        },
        tldr = {
          raw = "[!TLDR]",
          rendered = "󰨸  TL;DR",
          highlight = "RenderMarkdownInfo",
          category = "obsidian",
        },
        info = {
          raw = "[!INFO]",
          rendered = "󰋽  Info",
          highlight = "RenderMarkdownInfo",
          category = "obsidian",
        },
        todo = {
          raw = "[!TODO]",
          rendered = "󰗡  Todo",
          highlight = "RenderMarkdownInfo",
          category = "obsidian",
        },
        hint = {
          raw = "[!HINT]",
          rendered = "󰌶 Hint",
          highlight = "RenderMarkdownSuccess",
          category = "obsidian",
        },
        success = {
          raw = "[!SUCCESS]",
          rendered = "󰄬  Success",
          highlight = "RenderMarkdownSuccess",
          category = "obsidian",
        },
        check = {
          raw = "[!CHECK]",
          rendered = "󰄬  Check",
          highlight = "RenderMarkdownSuccess",
          category = "obsidian",
        },
        done = {
          raw = "[!DONE]",
          rendered = "󰄬  Done",
          highlight = "RenderMarkdownSuccess",
          category = "obsidian",
        },
        question = {
          raw = "[!QUESTION]",
          rendered = "󰘥  Question",
          highlight = "RenderMarkdownWarn",
          category = "obsidian",
        },
        help = {
          raw = "[!HELP]",
          rendered = "󰘥  Help",
          highlight = "RenderMarkdownWarn",
          category = "obsidian",
        },
        faq = {
          raw = "[!FAQ]",
          rendered = "󰘥  Faq",
          highlight = "RenderMarkdownWarn",
          category = "obsidian",
        },
        attention = {
          raw = "[!ATTENTION]",
          rendered = "󰀪  Attention",
          highlight = "RenderMarkdownWarn",
          category = "obsidian",
        },
        failure = {
          raw = "[!FAILURE]",
          rendered = "󰅖 Failure",
          highlight = "RenderMarkdownError",
          category = "obsidian",
        },
        fail = {
          raw = "[!FAIL]",
          rendered = "󰅖 Fail",
          highlight = "RenderMarkdownError",
          category = "obsidian",
        },
        missing = {
          raw = "[!MISSING]",
          rendered = "󰅖 Missing",
          highlight = "RenderMarkdownError",
          category = "obsidian",
        },
        danger = {
          raw = "[!DANGER]",
          rendered = "󱐌 Danger",
          highlight = "RenderMarkdownError",
          category = "obsidian",
        },
        error = {
          raw = "[!ERROR]",
          rendered = "󱐌 Error",
          highlight = "RenderMarkdownError",
          category = "obsidian",
        },
        bug = {
          raw = "[!BUG]",
          rendered = "󰨰 Bug",
          highlight = "RenderMarkdownError",
          category = "obsidian",
        },
        example = {
          raw = "[!EXAMPLE]",
          rendered = "󰉹  Example",
          highlight = "RenderMarkdownHint",
          category = "obsidian",
        },
        quote = {
          raw = "[!QUOTE]",
          rendered = "󱆨  Quote",
          highlight = "RenderMarkdownQuote",
          category = "obsidian",
        },
        cite = {
          raw = "[!CITE]",
          rendered = "󱆨  Cite",
          highlight = "RenderMarkdownQuote",
          category = "obsidian",
        },
      },
      checkbox = {
        enabled = false,
        render_modes = false,
        bullet = false,
        left_pad = 0,
        right_pad = 1,
        unchecked = {
          icon = "󰄱 ",
          highlight = "RenderMarkdownUnchecked",
          scope_highlight = nil,
        },
        checked = {
          icon = "󰱒 ",
          highlight = "RenderMarkdownChecked",
          scope_highlight = nil,
        },
        custom = {
          todo = { raw = "[-]", rendered = "󰥔 ", highlight = "RenderMarkdownTodo", scope_highlight = nil },
        },
        scope_priority = nil,
      },
      code = {
        enabled = true,
        render_modes = true,
        sign = false,
        conceal_delimiters = false,
        language = true,
        position = "left",
        language_icon = false,
        language_name = false,
        language_info = false,
        language_pad = 0,
        disable = {},
        disable_background = { "diff" },
        background_inset = 1,
        width = "block",
        left_margin = 0,
        left_pad = 0,
        right_pad = 0,
        min_width = 90,
        border = "thin",
        language_border = "",
        language_left = "",
        language_right = "",
        above = "",
        below = "",
        inline = true,
        inline_left = "",
        inline_right = "",
        inline_pad = 0,
        priority = 140,
        highlight = "RenderMarkdownCode",
        highlight_info = "RenderMarkdownCodeInfo",
        highlight_language = nil,
        highlight_border = "RenderMarkdownCodeBorder",
        highlight_fallback = "RenderMarkdownCodeFallback",
        highlight_inline = "RenderMarkdownCodeInline",
        highlight_inline_left = nil,
        highlight_inline_right = nil,
        style = "full",
      },
      dash = {
        enabled = true,
        render_modes = false,
        icon = "",
        width = "full",
        left_margin = 0,
        priority = nil,
        highlight = "RenderMarkdownDash",
      },
      indent = {
        enabled = true,
        render_modes = true,
        per_level = 1,
        skip_level = 1,
        skip_heading = false,
        icon = " ",
        priority = 0,
        highlight = "RenderMarkdownIndent",
      },
      paragraph = {
        enabled = true,
        render_modes = false,
        left_margin = 0,
        indent = 0,
        min_width = 0,
      },
      heading = {
        enabled = true,
        render_modes = false,
        atx = true,
        setext = true,
        sign = false,
        -- icons = { "◉  ", "○  ", "✸  ", "✿  ", "✿  ", "✿  " },
        icons = { "# ", "## ", "### ", "#### ", "##### ", "###### " },
        position = "overlay",
        signs = { "󰫎 " },
        width = "full",
        left_margin = 0,
        left_pad = 0,
        right_pad = 0,
        min_width = 0,
        border = false,
        border_virtual = false,
        border_prefix = false,
        above = "",
        below = "",
        backgrounds = {
          "RenderMarkdownH1Bg",
          "RenderMarkdownH2Bg",
          "RenderMarkdownH3Bg",
          "RenderMarkdownH4Bg",
          "RenderMarkdownH5Bg",
          "RenderMarkdownH6Bg",
        },
        foregrounds = {
          "RenderMarkdownH1",
          "RenderMarkdownH2",
          "RenderMarkdownH3",
          "RenderMarkdownH4",
          "RenderMarkdownH5",
          "RenderMarkdownH6",
        },
        custom = {},
      },
      pipe_table = {
        enabled = true,
        render_modes = true,
        preset = "none",
        cell = "padded",
        cell_offset = function()
          return 0
        end,
        padding = 1,
        min_width = 0,
        border = {
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          "",
          "",
        },
        border_enabled = false,
        border_virtual = false,
        alignment_indicator = "",
        head = "RenderMarkdownTableHead",
        row = "RenderMarkdownTableRow",
        style = "full",
      },
      completions = {
        lsp = { enabled = true },
      },
    })
  end,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions