-
-
Notifications
You must be signed in to change notification settings - Fork 258
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
Compatibility issues with Highlighting Lines in Code blocks #2544
Comments
I'll start off by saying that while this was filed as a bug, it is not a bug and the docs clearly state the parsing expectations for this extension. I would consider this a feature request or an enhancement at the very least. Additionally, I will state that this extension is not meant to support every variation of code blocks created in the past, and certainly is not designed with the requirement to adopt all new syntaxes that various parsers may decide upon in the future. SuperFences was based on the syntax of CodeHilite which has been around probably longer than all the listed examples' implementations. A lot of the examples are probably based on CommonMark which came out much later. Python Markdown is an old-school parser and is not expected to conform to any of the expectations of CommonMark. SuperFences specifically based the syntax on CodeHilite to provide compatibility when people came over from the Python Markdown default provided extension. It should also be noted that SuperFences provides a generic way to create custom fences to parse unaltered blocks of text. This was mainly done because Python Markdown's implementation of code handling is quite a bit cumbersome due to its need to be implemented as a preprocessor. Providing a generic interface that people could tap into meant others could leverage the work and that I'd never have to rewrite that logic again if I needed to pull off similar logic. While primarily used for code blocks, it should be noted that the logic is reused for non-code block custom fences. Adding a line highlight specific syntax like Now, regarding the aforementioned example: ```javascript [4]
function hello(name) {
let phrase = `Hello, ${name}!`;
debugger;
say(phrase);
}
``` I think SuperFences logic here is expected and logical. In order to have a fenced code block, the header must be well-formed and conform to expectations. If expectations are not met, the block will be treated as a paragraph, and then the inline code highlighter will be allowed to parse sections within the paragraph, which is exactly what happens. I don't find the output surprising at all. The difference is that GitHub (and possibly some other parsers) will look at the header and, as long as the header doesn't include another Is there merit in the new numerical syntax? I will generally say yes. There is certainly nothing wrong with the syntax As far as accepting anything in a code fence header, I do not like the idea of code blocks swallowing any and all junk on the fenced code block header line. Having a clear indication when you are providing nonsense to the parser is something that I like, and the parser failing to parse the content as a fence code block is that indicator. I admit that this is an opinionated viewpoint, but these are, to some extent, opinionated extensions. |
Okay, I got it. Thank you for your response, very detailed. My intention is not to ask you to change a new parsing method for this project, just to ask if it's possible to ignore the parsing of this part of the middle bracket [] so that it doesn't affect the later rendering. I think it should be easy to handle, for example, ```java [3], [3] is preceded by some space, you can split the line with a space, and then just take the first part as a syntax markup, and ignore anything after that line. Github, Typora, and other parsers seem to work this way. |
I wasn't sure. It seemed to mention it as a possible approach with a fallback to ignoring the content if implementing was not desired. Obviously, this was my misinterpretation 🙂.
No, I understand this part, but as I detailed earlier, I'm not sure I agree with this approach. These implementations make a number of assumptions. If the line starts with Additionally, as stated earlier, I'm not sure I'm okay with hiding bad syntax on the header line and confusing people by making them think their header is valid, but then the functionality they expected isn't shown in the output. Part of my reasoning is preventing people from filing issues here. If they see the code block not rendered properly, they may take a closer look at their syntax. If this prevents even a handful of filed issues here that I have to respond to, it is worth it. |
Okay, thank you very much. |
Yes, specifically a number of CommonMark parsers mainly, but many that are not do not.
Sure. I'll say this, if it is something I can make "opt-in", without too much complexity, then I might consider it. I'll leave this as a "maybe" with low priority for now. |
Description
I have a paragraph in my markdown text like this, and when I run it, it parses incorrectly, causing the rendered page to be completely misaligned, here's the source file: TestOne.md.
It would be rendered like this:
This is the correct parsing in Typora:
The reason is that the [4] after the token is not recognized, and it treats the [4] as the beginning of the code, which should normally be the next line.
I know this is not the canonical writeup for this project, but it could be designed so that ignore unrecognized markup when it is encountered, thus not affecting the parsing and rendering of later text.This writeup renders fine in other editors, such as Typora, Github and so on.
This writeup is from other project revealjs, I compared, this design is much simpler, just need to set the number, don't need to remember the property name, and it also supports step-by-step highlights.
Here are some write-ups for comparison and reference:
Minimal Reproduction
unnecessary
Version(s) & System Info
unnecessary
The text was updated successfully, but these errors were encountered: