Python-Markdown / markdown

A Python implementation of John Gruber’s Markdown with Extension support.
https://python-markdown.github.io/
BSD 3-Clause "New" or "Revised" License
3.71k stars 856 forks source link

Add Support for Tab Customization in Code Blocks #1450

Closed ArfaNada closed 5 months ago

ArfaNada commented 5 months ago

Description

Python-Markdown currently lacks built-in support for tab customization in code blocks. This feature would allow users to specify the tab width within code blocks, enhancing flexibility and compatibility with various coding standards.

Why is this feature necessary

Different coding standards and preferences exist regarding tab width. By allowing users to customize tab width within code blocks, Python-Markdown can better accommodate these diverse requirements. This feature would improve the accuracy of code representation in Markdown documents, especially when copying code from IDEs or text editors.

Proposed Solution

Alternative Solutions

@daniel-santos @timabbott @zulip (https://github.com/zulip/zulip/issues/29044)

Considering Python-Markdown's focus on adhering to Markdown syntax rules, the proposed feature aligns with enhancing the flexibility and usability of the library without deviating from Markdown standards.

facelessuser commented 5 months ago

If you'd like, you can use SuperFences to preserve tabs. This accounts for code blocks earlier, before Python Markdown normalizes tabs to spaces. Then you can style them however you want.

waylan commented 5 months ago

I'm not sure how we would accomplish this as the first thing the parser does is strip all tabs from a document and replace those tabs with spaces. This is done before any parsing happens so code blocks have not been identified yet and there would be no way to differentiate and avoid code blocks at that stage. While we could change/remove that behavior, it would require the entire parser to now account for tabs in additional to spaces for indentation, etc. which would be a massive amount of work. It would also be a backward incompatible change in that it would require many third-party extensions to make changes as well. Therefore, it seems to me like the alternative solutions you already listed (third-party extension or manual formatting) would be a better solution. After all, as far as I can tell, this is a need of only a very small minority of our users.

Something that could potentially cause me to reconsider is if you could point to other implementations which already support this. Also, if a third-party extension was created and it became wildly popular, then we might be more inclined to adopt that behavior. However, as it stands now, it appears that this would be a new behavior only implemented by one implementation, which makes it ideal for a third-party extension.

waylan commented 5 months ago

If you'd like, you can use SuperFences to preserve tabs. This accounts for code blocks earlier, before Python Markdown normalizes tabs to spaces. Then you can style them however you want.

Apparently, a third-party extension already exists which implements this. I am closing this.