Bug 442025 - Invalid code in Markdown code fences breaks formatting outside of code fences
Summary: Invalid code in Markdown code fences breaks formatting outside of code fences
Status: CONFIRMED
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: syntax (other bugs)
Version First Reported In: unspecified
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-05 08:40 UTC by Dotan Cohen
Modified: 2025-09-17 07:40 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
Kate 19.12.3 in Linuxmint showing correct highlighting (46.91 KB, image/png)
2021-09-05 10:21 UTC, Jan Paul Batrina
Details
Good PHP code on the left, invalid PHP code on the right. (82.32 KB, image/png)
2021-09-06 10:59 UTC, Dotan Cohen
Details
SQL in a PHP block (66.66 KB, image/png)
2021-09-06 11:07 UTC, Dotan Cohen
Details
PHP with `?>` breaking Markdown fenced code block (199.72 KB, image/png)
2025-09-17 07:40 UTC, Christian Lampe
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dotan Cohen 2021-09-05 08:40:33 UTC
When opening a Markdown document in Kate, invalid code inside code fences causes improper formatting of text after the end of the code fence.


STEPS TO REPRODUCE
1. Create a file with the following text, not including the `----` markers:
----
# Invalid code sample

```php
$foobar = "Foo bar";
```

# This is another heading

This is another nice line of text.
----

2. Save as demo.md
3. Note formatting, specifically consistent colours on heading lines.
4. Remove one of the double quote characters from the string assignment line.

OBSERVED RESULT
Formatting of text after closing code fence is changed.

EXPECTED RESULT
Formatting of text after closing code fence should not change.

No matter how bad the code inside the fences is, it should not affect the formatting of text outside the fences. This is especially important when opening a file specifically used to document invalid code.

KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.68.0
Qt Version: 5.12.8
Comment 1 Jan Paul Batrina 2021-09-05 10:21:17 UTC
Created attachment 141309 [details]
Kate 19.12.3 in Linuxmint showing correct highlighting

Thanks for the bug report!

I cannot reproduce the issue, neither with Kate from master nor with Kate 19.12.3 from a linuxmint 20.2 live usb.

I have attached a screenshot of how it looks on both versions (minus differences on the colors), and similar highlighting happens in VS Code and Notepad++.

Please attach a screenshot of the issue you described, even better if you point out the exact problem, so that we can check if it has already been fixed in newer versions.
Comment 2 Jan Paul Batrina 2021-09-05 10:21:38 UTC
setting to needsinfo
Comment 3 Dotan Cohen 2021-09-06 10:52:53 UTC
Thank you Jan. Notice this additional step needed to make the PHP code invalid, and thus break the Kate formatting:

> 4. Remove one of the double quote characters from the string assignment line.

Screenshot in a few minutes.
Comment 4 Dotan Cohen 2021-09-06 10:59:15 UTC
Created attachment 141326 [details]
Good PHP code on the left, invalid PHP code on the right.
Comment 5 Dotan Cohen 2021-09-06 11:00:56 UTC
Note in the screenshot, the PHP code on the right is missing a double-quote character, making the code not valid PHP code.
Comment 6 Jan Paul Batrina 2021-09-06 11:07:05 UTC
Ahh, my bad. I don't know how I didn't notice the 4th step before, but now I can confirm that the bug exists in kate master.

Takes for the quick response, complete with comparison screenshots!
Comment 7 Dotan Cohen 2021-09-06 11:07:44 UTC
Created attachment 141327 [details]
SQL in a PHP block

This is another example, in which valid SQL is mentioned in a PHP block. It breaks the formatting outside the code fences as well.
Comment 8 Jan Paul Batrina 2021-09-06 11:28:12 UTC
(In reply to Dotan Cohen from comment #7)
> Created attachment 141327 [details]
> SQL in a PHP block
> 
> This is another example, in which valid SQL is mentioned in a PHP block. It
> breaks the formatting outside the code fences as well.

This one I can reproduce in Kate 19.12.3, but not anymore in the latest version from master.

As for the original bug (the one with the unfinished string), that would be a bit tricky to fix as the php syntax-highlighting is "imported" wholesale, and current syntax rules dictate that a string in php will not end unless a closing " is supplied. It might take while for the bug to be fixed
Comment 9 Dotan Cohen 2021-09-19 12:07:00 UTC
I see, thank you.
Comment 10 Christian Lampe 2025-09-17 07:40:15 UTC
Created attachment 185000 [details]
PHP with `?>` breaking Markdown fenced code block

I don't know if it's related or not, but when I write Markdown in Kate and put a fenced PHP code block, the closing fence is treated as a new opening fence if the fenced PHP code contains a `<?php […] ?>`.   
I've attached a screenshot of how I discovered it.