peterh
peterh

Reputation: 1

How to make the Eclipse HTML editor to indent all tags properly?

This is how it currently looks:

<div ng-controller="AppCtrl" layout="column" style="height: 500px;" ng-cloak>
    <section layout="row" flex>
        <md-sidenav class="md-sidenav-left" md-component-id="left"
            md-is-locked-open="$mdMedia('gt-md')" md-whiteframe="4">
        <md-toolbar class="md-theme-indigo">
        <h1 class="md-toolbar-tools">Sidenav Left</h1>
        </md-toolbar> <md-content layout-padding ng-controller="LeftCtrl"> <md-button
            ng-click="close()" class="md-primary" hide-gt-md> Close
        Sidenav Left </md-button>

It is crap. I want properly indented XML. Around so:

<div ng-controller="AppCtrl" layout="column" style="height: 500px;" ng-cloak>
    <section layout="row" flex>
        <md-sidenav class="md-sidenav-left" md-component-id="left"
            md-is-locked-open="$mdMedia('gt-md')" md-whiteframe="4">
            <md-toolbar class="md-theme-indigo">
                <h1 class="md-toolbar-tools">Sidenav Left</h1>
            </md-toolbar>
            <md-content layout-padding ng-controller="LeftCtrl">      
                <md-button ng-click="close()" class="md-primary" hide-gt-md>
                    Close Sidenav Left
                </md-button>

This is how my relevant settings look:

enter image description here

What to do? (I've already checked that "Structured Text Editors" link, there seems nothing relevant to exist.)

Yes, I know, that the added whitespace can cause little troubles in the inline positioned block elements, but I can live with it.

I opened the HTML file with the XML editor, too, but it behaves exactly the same.

Upvotes: 0

Views: 1556

Answers (1)

peterh
peterh

Reputation: 1

The obvious solution is to use the XML Editor also for HTML formatting.

Unfortunately, Eclipse doesn't really want us to set this, but it can be forced to do that.

  1. The most simplest way would be: right click on the file, "open with" -> "others" -> "XML Editor". It doesn't work, if the file ends to *.html, Eclipse will still open the file as HTML. And the Eclipse development somehow thinks it is okay.
  2. In Window -> Preferences -> General -> Editors -> File Associations, select "*.html", and add "XML Editor" to the associated editors to it. Make it default by clicking "Default". Unfortunately, even this isn't enough, and the Eclipse development somehow thinks it is okay.
  3. You can't remove the "HTML Editor", because it is locked, and the Eclipse development somehow thinks it is okay.
  4. Now go to General -> Content Types -> Text -> XML. Here is an additional list of the files associated with the XML Editor. Add *.html to file associations of both "XML" and the "XML (Illformed)" fields. It seems, registering the same "path regexp" -> "editor plugin" dictionary on multiple places, is somehow okay for the Eclipse development. But it also enables us to override their locked default settings.

The solution works in current stable version of eclipse, v4.15. Around until Kepler simply setting the file associations was enough.

Upvotes: 1

Related Questions