Bug 472870 - xml indentation works incorrectly
Summary: xml indentation works incorrectly
Status: REPORTED
Alias: None
Product: kate
Classification: Applications
Component: indentation (other bugs)
Version First Reported In: 22.12.3
Platform: Debian unstable Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-01 09:12 UTC by Martin Steigerwald
Modified: 2025-08-30 03:13 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Steigerwald 2023-08-01 09:12:31 UTC
SUMMARY

Since a while XML indenting does not work correctly anymore. One example, when typing:

<slide toc="yes">
    <title

and then closing the "<title>"-Tag with ">" Kate moves it onto the same level as the "<slide>"-Tag

On the other hand in case I do not indent the "<title>"-tag myself it does not indent it automatically but keeps it sitting on the same level as the "<slide>"-Tag.

This happens with tabs as spaces and tabs as tabs. However when playing around with indentation settings, sometimes I can get it to work correctly. I did not yet figure out how and it usually does not last long. So it may be necessary to replicate the exact indentation settings. I shared the mode line I use at the end of the report.

There other issues with XML indentation which basically renders the feature not only useless but it hinders working on an XML documentation. Thus I can work more productively when disabling indenting completely.

My suspicion is that this is related to some recent KDE Frameworks update, cause Kate was not updated in Debian since Debian Bookworm release and indentation worked correctly about 1 or 2 months ago AFAIR. KDE Frameworks got at least one update. I hope to get my hands on a newer Kate version soon enough, but Debian/Ubuntu Qt/KDE packaging team is also working on Qt 6 as a prerequisite for introducing Plasma 6 to Debian later in the year. So not sure when they will package Kate 23.04 or even better 23.08.

STEPS TO REPRODUCE

1. Try above example with XML indenting on

You could also use the mode line I pasted below for exact indentation settings.

OBSERVED RESULT

As above.

EXPECTED RESULT

Kate keeps the indentation or… in case I do not indent myself indents the "<title>"-Tag automatically.

SOFTWARE/OS VERSIONS

Linux/KDE Plasma: Devuan GNU/Linux 6 on Kernel 6.4.0-1-amd64 (that is Devuan Ceres tracking Debian Sid)
KDE Plasma Version: 5.27.5
KDE Frameworks Version:  5.107.0
Qt Version: 5.15.10

ADDITIONAL INFORMATION

I use the following mode line:

<!--
	kate: indent-mode xml; indent-width 4; line-numbers true; remove-trailing-spaces all; syntax XML; tab-indents true; tab-width 4;
-->

This makes it more difficult to disable XML indenting temporarily as Kate seems to enable it again when I save the document.
Comment 1 Martin Steigerwald 2023-08-01 09:34:46 UTC
For a few tags combinations like

<ul>
     <li>

indentation still seems to work correctly. However when adding another "<li>"-tag I get this:

<ul>
    <li>Some text</li>
<li>

Second "<li>"-tag is on same level than "<ul>"-tag.
Comment 2 Martin Steigerwald 2023-08-01 09:58:19 UTC
I have also seen this:

	<title>Some title</title>
<ul>
	<li>

I.e. Kate moves "<ul>"-tag out one level under a "<title>"-tag. As written with "<ul>"-"<li>" combo indentation is okay. It seems that Kate does not treat all tags equal anymore.

I do not see a pattern there so far. Seems kind of erratic to me.
Comment 3 Christoph Cullmann 2023-08-02 19:26:45 UTC
Help to improve that script is for sure welcome, it is done internally via some javascript, are you interested to help out with that?
Comment 4 Martin Steigerwald 2023-08-07 07:40:15 UTC
Hi Christoph. I actually see no need to improve it. In case I have not been clear: This is a regression. It worked before. No idea why it does not work correctly anymore. However… if I know where to look for that JavaScript I could have a look. I am not sure whether I'd find anything though. But at least I could have a look whether that JavaScript was changed recently, cause if not, it must have been some other change that caused the regression.
Comment 5 Christoph Cullmann 2023-08-07 07:56:08 UTC
Hi,

that is the script that handles it

https://invent.kde.org/frameworks/ktexteditor/-/blob/master/src/script/data/indentation/xml.js
Comment 6 spikethehobbitmage 2025-08-30 03:13:49 UTC
This bug is a whitespace issue. The XML indenter doesn't like tab characters.