Skip to content

bug: left_pad does not work with tabs #230

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

Closed
2 tasks done
FaisalAl-Rayes opened this issue Nov 8, 2024 · 2 comments
Closed
2 tasks done

bug: left_pad does not work with tabs #230

FaisalAl-Rayes opened this issue Nov 8, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@FaisalAl-Rayes
Copy link

Neovim version (nvim -v)

0.10.1

Neovim distribution

LazyVim

Operating system

MacOS

Terminal emulator / GUI

iTerm2

Describe the bug

When i set the "code" configuration as shown blow, with a left_pad and a right_pad defined it actually makes the right_pad be (left_pad + declared value of right_pad) 6 in this case.

this is from the wiki

return {
  "MeanderingProgrammer/markdown.nvim",
  main = "render-markdown",
  name = "render-markdown",
  dependencies = {
    "nvim-treesitter/nvim-treesitter",
    "nvim-tree/nvim-web-devicons"
  },
  config = function ()
    require("render-markdown").setup(
      {
        code = {
          width = "block",
          left_pad = 2,
          right_pad = 4,
        },
      }
    )
  end
}

Screenshot 2024-11-08 at 14 31 36

if __name__ == "__main__":
	# Usage
	merge_pdfs(sys.argv[1], sys.argv[2], "merged_output.pdf")
\`\`\`
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

My suspicion is that these are happening in these areas of the code:
area1
area2

Expected behavior

The right padding should only be the value of the right_pad value in the config and not the sum of the left_pad and right_pad (value from the config)

Healthcheck output

render-markdown: require("render-markdown.health").check()

render-markdown.nvim [version] ~
- OK plugin 7.5.1
- OK neovim >= 0.10

render-markdown.nvim [configuration] ~
- OK valid

render-markdown.nvim [nvim-treesitter] ~
- OK installed
- OK markdown: parser installed
- OK markdown: highlight enabled
- OK markdown_inline: parser installed
- OK markdown_inline: highlight enabled
- WARNING latex: parser not installed
  - ADVICE:
    - Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }

render-markdown.nvim [executables] ~
- OK latex2text: installed

render-markdown.nvim [conflicts] ~
- OK headlines: not installed
- OK obsidian: installed but should not conflict

Plugin configuration

return {
  "MeanderingProgrammer/markdown.nvim",
  main = "render-markdown",
  name = "render-markdown",
  dependencies = {
    "nvim-treesitter/nvim-treesitter",
    "nvim-tree/nvim-web-devicons"
  },
  config = function ()
    require("render-markdown").setup(
      {
        code = {
          width = "block",
          left_pad = 2,
          right_pad = 4,
        },
      }
    )
  end
}

Plugin error log

N/A

Confirmations

  • I have updated this plugin to the latest version using my plugin manager
  • I have provided the text contained in all screenshots as raw text in this issue. This means if there is a screenshot below it is the copy pasted contents of the file in the screenshot. I understand that my issue will be closed if I have not.

Additional information

No response

@FaisalAl-Rayes FaisalAl-Rayes added the bug Something isn't working label Nov 8, 2024
@MeanderingProgrammer
Copy link
Owner

The issue is that the lines in the code block have tabs and the left padding (made up of spaces) is not applied as a result.

Changing the tabs to spaces fixes this. For instance the following code block works correctly with your configuration:

```python
if __name__ == "__main__":
    # Usage
    merge_pdfs(sys.argv[1], sys.argv[2], "merged_output.pdf")
```

I'll see if I can handle tabs.

@MeanderingProgrammer MeanderingProgrammer changed the title bug: right_pad is actually the sum of the left_pad and right_pad parameter in the "code" configuration bug: left_pad does not work with tabs Nov 8, 2024
MeanderingProgrammer added a commit that referenced this issue Nov 8, 2024
## Details

Issue: #230

When adding inline spaces for padding or margin in code blocks tabs
would cause the spacing to not work. For example if a user wants left
padding of 2 but has tabstop set to 4 the 2 spaces added would be ignored
since they did not occupy enough space to shift the text.

To fix this when adding spaces to the left first check if the code block
contains any tabs. If it does instead of applying the spacing directly
find the next value that is a multiple of the users tabstop and use that.
From the previous example we would add 4 spaces now instead of 2. A
tabstop of 8 and a padding of 10 would result in 16 spaces.
@MeanderingProgrammer
Copy link
Owner

Fixed here: d80acb3

There's no way to shift text to the left by 2 spaces when it's before a tab and your tab size is 4. So now the next multiple of your tab size will be used as the left padding. So your example will be left padded by 4 spaces and the right padding will be whatever value you set, in this case also 4.

This is just how tabs work:

  • Text a\tb displayed as a b
  • But a\tb displayed as a b

The extra space in the second example doesn't shift the b anywhere and the text remains the same width overall. This is the same behavior you were seeing.

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

2 participants