-
Notifications
You must be signed in to change notification settings - Fork 650
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
PHP code blocks require closing tag (?>) to format correctly #221
Comments
god i wish this would be fixed |
To help reiterate if you have a ```php
<?php
function test()
{
return 'something';
}
``` \\closing the php fence, delete this comment
# and then add a header down here will won't get styled properly If you can point me at the right area to fix this i'd be glad to help, but I think it might be something more to the core of subl. |
@drKnoxy If you really like to solve this problem on your own, search |
IIRC, the complication comes mostly from the fact that the MarkdownEditing tmlanguage syntax inherits from HTML, which includes |
I'll tell my dirty explanation and possible fix for the bug. This bug happens because;
Possible fix:
This is what I have in mind at the moment without deep research. :) |
My solution:
|
@g105b That still requires putting Also this bug has some other faces. For example if you put I don't know how we can remove the requirement of being "syntax complete". Maybe we should create simplified syntaxes that only highlights keywords and punctuations for that language. |
So, should this be marked as "won't fix"? |
It is up to you. P.S. I was using "impossible" label for such stuff, instead of "wontfix" |
I'm seeing this as a much larger problem that isn't language specific and suggest creating a new issue to track this bug. For instance, I'm looking at a markdown file right now that has the following fenced block:
Leading up to that section markdown hi lighting works correctly. Following the last three backticks, however, markdown hi lighting is broken. It breaks on the The suggestion by @g105b to simply disable syntax parsing within code blocks makes a lot of sense. @maliayas Not sure why you state that "putting Is it possible to disable syntax hilighting within code blocks? |
@markeissler , I am going to answer your question by answering the following three instead:
What is the nature of this issue?You noticed that //Syntax: Javascript
var a;
var text = "some text";
var b; What if we remove the trailing quotation mark: //Syntax: Javascript
var a;
var text = "some text;
var b; See, <!--Syntax: HTML-->
<label>label 1</label>
<script>
var a;
var text = "some text;
var b;
</script>
<label>label 2</label> Essentially, what you just saw is same as the problem you described. In bash, What causes this issue?Sublime Text uses "scope" to decide how text should be highlighted. And the scopes are decide by syntax definition files. When ST sees an "scope opener" like a left quotation mark, it will search for the "scope closer" like a right quotation mark. Anything between them will be swallowed as a whole and assigned to that scope. We cannot simply add three consecutive backticks as a "scope closer" for all scopes. Consider this:
How do you decide
What can we do about it?Sadly, not much. Like you said, adding the support for turning on/off syntax highlight so you can turn off the highlight if you really need to write broken code in a code block sounds like an acceptable workaround. Unfortuanately, neither syntax highlight files (.thTheme) nor syntax definition files (.thLanguage) can be modified dynamically. We have to add three more syntaxes files as "Markdown (without code block highlight)", "Markdown GFM (without code block highlight)" and "MultiMarkdown (without code block highlight)" in addition to the three we already have. Personally, I think this will make the project too messy. Settings cannot change the behaviour of highlight. Despite all that I have said, this is still a bug because the way the text gets highlighted is different from how most markdown parsers work. But before a major change happens to ST parsing engine, we have to bear with it. I hope this ends all questions about this issue. |
Oh the sadness. :'( What I'm doing right now is writing my markdown with the |
Upcoming fix described in #484. Closing it for now. Feel free to reopen it if that solution is not sufficient. |
Here is a snippet of PHP that will be formatted by Github:
and this paragraph is no longer formated as PHP.
However, in MarkdownEditing syntax, the subsequent paragraphs after the above snippet will continue to be formatted as code, unless a closing tag (
?>
) ends the code snippet.The text was updated successfully, but these errors were encountered: