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

Add Support for Tab Customization in Code Blocks #1450

Closed
ArfaNada opened this issue Mar 11, 2024 · 3 comments
Closed

Add Support for Tab Customization in Code Blocks #1450

ArfaNada opened this issue Mar 11, 2024 · 3 comments
Labels
3rd-party Should be implemented as a third party extension. extension Related to one or more of the included extensions. feature Feature request.

Comments

@ArfaNada
Copy link

ArfaNada commented Mar 11, 2024

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

  • Modify Parser: Extend the Markdown parser to recognize additional parameters in code block declarations, such as ts=, where denotes the desired tab width.
  • Implement Tab Handling: Introduce logic to handle tab width settings within code blocks according to the specified parameter.
  • Provide Default Behavior: Define a default tab width behavior to maintain backward compatibility while allowing users to override it as needed.

Alternative Solutions

  • Third-Party Extensions: Users can currently explore third-party extensions that might offer similar functionality. However, native support within Python-Markdown would streamline the process and ensure compatibility with future updates.
  • Manual Formatting: Users can manually adjust tab widths within code blocks, but this approach is cumbersome and prone to errors.

@daniel-santos
@timabbott
@zulip (zulip/zulip#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
Copy link
Collaborator

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
Copy link
Member

waylan commented Mar 11, 2024

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 waylan added feature Feature request. extension Related to one or more of the included extensions. 3rd-party Should be implemented as a third party extension. labels Mar 11, 2024
@waylan
Copy link
Member

waylan commented Mar 11, 2024

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.

@waylan waylan closed this as not planned Won't fix, can't repro, duplicate, stale Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd-party Should be implemented as a third party extension. extension Related to one or more of the included extensions. feature Feature request.
Projects
None yet
Development

No branches or pull requests

3 participants