Search code examples
htmlattributescomparediffbeyondcompare

Sorting HTML attributes for comparison


Is there a way to sort HTML attributes when comparing things in BeyondCompare?

So for example the following should be considered equivalent:

<div class="btn" id="someId">

vs

<div id="someId" class="btn">

Solution

  • Beyond Compare doesn't provide a method to sort HTML attributes.

    If you can find a command line application to sort HTML attributes, you can use a Beyond Compare file format to run it as a preprocessor before comparison.

    To define a file format that runs an external app before comparison:

    1. Open Tools > File Formats.
    2. Click +.
    3. Select Text Format.
    4. In the General tab, enter *.html as the file mask.
    5. Go to the Conversion tab.
    6. Change the top dropdown from None to External program (Unicode filenames).
    7. In Loading, enter the path to the external app, followed by variables %s and %t for the source and target filenames.
    8. Save.

    The highest format in the list with matching file mask is used when comparing pairs of files in Beyond Compare or running rules-based comparison in the Folder Compare.