ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Exalt

by eerohele ST3

A Sublime Text 3 plugin for validating and formatting XML and (X)HTML

Details

Installs

  • Total 4K
  • Win 2K
  • OS X 1K
  • Linux 425
Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5 Sep 4
Windows 10 7 8 6 4 1 6 11 7 9 5 2 2 6 11 9 9 9 0 4 7 9 11 6 10 5 2 9 16 15 15 8 1 2 4 14 6 4 6 0 0 4 10 6 4 4
OS X 7 3 2 1 1 0 2 3 2 2 5 0 2 6 6 7 0 0 2 2 5 4 2 1 4 4 3 4 3 2 0 2 0 1 4 2 3 3 2 1 0 2 1 3 2 2
Linux 1 0 2 2 1 0 3 0 2 1 1 0 1 2 1 0 3 0 0 0 1 3 3 3 2 0 0 2 0 1 2 2 1 0 0 1 3 1 1 1 0 0 1 2 1 1

Readme

Source
raw.​githubusercontent.​com

Exalt

If you have the misfortune of having to work with XML, this is the Sublime Text 3 plugin for you.

The theme in the screenshot is Boxy.

Features

Validate files on the fly

Validate XML, XHTML, HTML, and XSLT files on the fly with lxml against a Document Type Definition (DTD), an XML schema (XSD), a RelaxNG schema (RNG), or a Schematron schema.

Exalt supports XML catalogs via lxml so that you don't need to put unnecessary load on W3C's servers.

XSLT validation

If the syntax of your current file is set to XSLT, Exalt automatically validates the file against Norman Walsh's Relax NG grammars for XSLT stylesheets.

XSD validation

Exalt uses the xsi:schemaLocation or the xsi:noNamespaceSchemaLocation attribute of the root element to validate against the schema defined in that attribute.

This means Exalt can validate Maven POM files that look like this:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>foobar</groupId>

    . . .
</project>

You'll probably want to set up an XML catalog to avoid having to fetch schemas from the internet. See Installing for more information.

xml-model validation

Exalt also supports the xml-model processing instruction. That means that you can have a processing instruction like this before the root element of your DITA XML 1.2 document (but after the XML declaration, of course):

<?xml-model href="urn:dita-ng:dita:rng:topic.rng"
            schematypens="http://relaxng.org/ns/structure/1.0"?>

Exalt will then validate against the schema in the href pseudo-attribute. It uses the XML catalog you've set up to resolve the path in the href pseudo-attribute and the schematypens pseudo-attribute to determine the the type of the schema.

You can naturally use absolute or relative paths, too:

<?xml-model href="file:///etc/xml/common/schemas/docbook/docbook-5.0/docbook.rng"
            schematypens="http://relaxng.org/ns/structure/1.0"?>


<?xml-model href="../docbook-5.0/xsd/docbook.xsd"
            schematypens="http://www.w3.org/2001/XMLSchema"?>


<?xml-model href="file:///etc/xml/common/schemas/dita/schematron/dita-1.2-for-xslt1.sch"
            schematypens="http://purl.oclc.org/dsdl/schematron"?>

If your file doesn't validate, you can press ⌘ + Ctrl + E to jump to the validation error if it's not already in view.

Format XML & HTML files

Press ⌘ + Ctrl + X to reformat (pretty-print) an XML or HTML file. If you have nothing selected, Exalt will format the entire document. If you have one or more selections, Exalt will format those.

NOTE: When formatting a selection, Exalt assumes the selection is a well-formed XML fragment. It will try to recover, but if your selection isn't well-formed, chances are the result is not what you want.

Exalt tries to format non-well-formed XML files via the libxml2 recover flag.

Installing

  1. Install Exalt via Package Control.
  2. Restart Sublime Text.
  3. (Optional, but recommended.) In User/Exalt.sublime-settings, set the path to your XML catalog files.

    For example:

    {
      "xml_catalog_files": ["/etc/xml/catalog", "~/.schemas/catalog.xml"]
    }
    

    By default, the plugin uses the catalog files defined in Exalt/Exalt.sublime-settings. Those catalog files might or might not exist on your system.

    If you want, you can use my catalogs repository to install a set of commonly used XML catalogs and schemas. Just set the xml_catalog_files setting of this plugin to point to the catalog.xml file in where you cloned the repo.

    Alternatively, you can clonecatalogs into /etc/xml and create /etc/xml/catalog.xml with this content:

    <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
      <nextCatalog catalog="catalogs/catalog.xml"/>
    </catalog>
    

    If you do that, you shouldn't need to set the xml_catalog_files setting.

    NOTE: If you change XML catalogs in any way, you need to restart Sublime Text 3 for the changes to take effect.

Known issues

  • Due to libxml2 issues #573483, #753970, and 753997, none of the available validation methods work for DITA 1.3 files. That's a bit of a bummer.
  • ISO Schematron validation doesn't always report the error position correctly.

Other caveats

  • There's probably many encoding things I didn't take into account. UTF-8 content should work OK.
  • I don't really know Python.

TODO

  • DTD validation support is incomplete.
  • More unit tests are needed.

Acknowledgements