Skip to content

fix(code blocks): prevent list indent and list utils from firing inside code blocks#193

Merged
YousefHadder merged 1 commit intoYousefHadder:mainfrom
ten3roberts:fix/list-indent-codeblock
Jan 2, 2026
Merged

fix(code blocks): prevent list indent and list utils from firing inside code blocks#193
YousefHadder merged 1 commit intoYousefHadder:mainfrom
ten3roberts:fix/list-indent-codeblock

Conversation

@ten3roberts
Copy link
Copy Markdown
Contributor

Description

Fixes a bug where e.g; list indent handlers were invoked inside codeblocks, which could mess up Rust codeblocks using function chaining (one method wrapper per line), as well as other languages

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Code refactoring
  • Performance improvement

Related Issues

Fixes #192

Testing

  • Tested manually
  • Added new tests for codeblock checking
Screencast.From.2026-01-02.16-51-20.mp4

Checklist

  • Code follows project style
  • Self-reviewed my code
  • Commented complex logic
  • Updated documentation (amended "context aware keymaps" section)
  • No new warnings generated

Copilot AI review requested due to automatic review settings January 2, 2026 15:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #192 where list manipulation handlers (indent, outdent, enter, etc.) were incorrectly triggering inside fenced code blocks, causing unwanted modifications to code that resembles markdown list syntax (e.g., Rust method chaining with leading dots/dashes).

Key Changes:

  • Added is_in_code_block() detection utility with treesitter support and regex fallback
  • Wrapped all interactive list handlers with skip_in_codeblock() to prevent execution inside code blocks
  • Added comprehensive test coverage for both the detection logic and handler wrapping

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lua/markdown-plus/utils.lua Added is_in_code_block() utility function with treesitter-first approach and regex fallback for detecting fenced code blocks
lua/markdown-plus/format/treesitter.lua Added is_in_fenced_code_block() function using treesitter node traversal to detect fenced_code_block nodes
lua/markdown-plus/list/handlers.lua Added skip_in_codeblock() wrapper function that checks for code blocks and falls back to default key behavior when inside them
lua/markdown-plus/list/init.lua Wrapped all interactive list handlers (Enter, Tab, Backspace, o/O) with skip_in_codeblock() protection
spec/markdown-plus/utils_spec.lua Added 9 comprehensive tests covering various code block scenarios (backtick/tilde, indented, multiple, unclosed, etc.)
spec/markdown-plus/list_spec.lua Added 4 tests verifying that the wrapper correctly skips handlers inside code blocks and executes them outside
doc/markdown-plus.txt Updated "Context-aware keymaps" section to document that list operations are now code-block aware

@ten3roberts
Copy link
Copy Markdown
Contributor Author

Hi 😁

Let me know if you'd like to see any changes, or for this PR to be less invasive


P.S: I also noticed that there is some mixed logic, where some uses treesitter, and some good-old string.match (such as footnote parser which checks for codeblocks). Would you appreciate a followup that makes those use treesitter (when available) as well?

@YousefHadder YousefHadder changed the title fix #192: prevent list indent and list utils from firing inside code blocks fix(code blocks): prevent list indent and list utils from firing inside code blocks Jan 2, 2026
@YousefHadder
Copy link
Copy Markdown
Owner

Hi 😁

Let me know if you'd like to see any changes, or for this PR to be less invasive

P.S: I also noticed that there is some mixed logic, where some uses treesitter, and some good-old string.match (such as footnote parser which checks for codeblocks). Would you appreciate a followup that makes those use treesitter (when available) as well?

The PR looks good and fixes the bug really nice, thank you for working on this 😄

The treesitter approach was recently introduced in the format module with a fallback if the builtin treesitter wasn't available, I had in mind expanding it to other features in the next major release v2.0.

But since you mentioned it, I would really love it if you can open an issue for tracking first, and if you want you can give it a shot sometime with a PR.

@YousefHadder YousefHadder self-assigned this Jan 2, 2026
Copy link
Copy Markdown
Owner

@YousefHadder YousefHadder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪨 solid.

@ten3roberts Please have the honor of merging this PR.

@YousefHadder
Copy link
Copy Markdown
Owner

@all-contributors please add @ten3roberts for code

@allcontributors
Copy link
Copy Markdown
Contributor

@YousefHadder

I've updated the pull request to add @ten3roberts! 🎉

@YousefHadder
Copy link
Copy Markdown
Owner

@all-contributors please add @ten3roberts for code and bug

@allcontributors
Copy link
Copy Markdown
Contributor

@YousefHadder

I've put up a pull request to add @ten3roberts! 🎉

@ten3roberts
Copy link
Copy Markdown
Contributor Author

Thanks

Had to fix merge conflicts from the smart-paste PR

The . My invalid list is due to the handle_tab function trying to replicate the behavior of expandtab, instead of letting nvim handle Tab as normal

It is another issue, but fixable in the same way by using feedkeys to let nvim handle tab as normal

@YousefHadder
Copy link
Copy Markdown
Owner

Sorry for the merge conflicts, I had to fix the git commit history but thanks for taking care of it.

@YousefHadder
Copy link
Copy Markdown
Owner

@ten3roberts Because of the change I made to the commit history, the squash and merge for this PR shows an extended description with co-authors, if you don't mind removing those when you merge the PR.

Thanks for your contribution. ❤️

@ten3roberts ten3roberts force-pushed the fix/list-indent-codeblock branch from b17a44e to 2068a81 Compare January 2, 2026 22:27
@ten3roberts
Copy link
Copy Markdown
Contributor Author

@YousefHadder the commit history should now be clean.

Don't have the merge button on my side, so feel free to merge yourself once PR succeeds

@YousefHadder YousefHadder merged commit b2b1910 into YousefHadder:main Jan 2, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] List indent and list utils functions get invoked inside fenced codeblocks

3 participants