Sublime Forum

Convert this dynamic .tmTheme to a proper .sublime-color-theme

#1

I am running into a problem with this file https://github.com/mhenrixon/SublimeSimpleCov/blob/master/common/theme_generator.py#L15

I’d like to convert it to a .sublime-color-theme because of the following errors:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 1088, in run_
    return self.run(edit)
  File "/Users/mhenrixon/Library/Application Support/Sublime Text 3/Packages/SimpleCov/toggle_ruby_coverage.py", line 25, in run
    self.show_coverage(filename, coverage)
  File "/Users/mhenrixon/Library/Application Support/Sublime Text 3/Packages/SimpleCov/toggle_ruby_coverage.py", line 43, in show_coverage
    self.augment_color_scheme()
  File "/Users/mhenrixon/Library/Application Support/Sublime Text 3/Packages/SimpleCov/toggle_ruby_coverage.py", line 146, in augment_color_scheme
    themeGenerator = ThemeGenerator(original_color_scheme)
  File "/Users/mhenrixon/Library/Application Support/Sublime Text 3/Packages/SimpleCov/common/theme_generator.py", line 48, in __init__
    self.plist = ElementTree.XML(color_scheme_xml)
  File "./python3.3/xml/etree/ElementTree.py", line 1356, in XML
xml.etree.ElementTree.ParseError: XML or text declaration not at start of entity: line 2, column 0

Any suggestions on either how to fix the problem or convert that dynamic template to a proper (new) one would be greatly appreciated. I’m a ruby developer with very little python exposure :slight_smile:

0 Likes

#2

I think the error is just saying there’s white space at the top of the XML. Remove or trim the line break in the source code.

0 Likes

#3

Hi @michaelblyons,

I tried various XML validators and noone spots any errors: Also plutil validates the file as ok:

plutil testing.tmTheme                                                              0 [14:38:12]
testing.tmTheme: OK 

Yet when I use python3’s ElementTree.XML it complains that it is broken. Seems like a problem in python3 to me?

0 Likes

#4

The code you linked says this:

STYLES_HEADER = """
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
"""

The line break between the opening """ and the <?xml is likely why you are getting:

XML or text declaration not at start of entity: line 2, column 0

because the “XML declaration” (<?xml) has been bumped to “line 2, col 0” by the line break. There are two paths you can take:

  • Trim the line break. (Add .lstrip() to the end of the string.) or
  • Remove the line break in the string declaration. (Start with """<?xml without the break.)
2 Likes

#5

That worked when I edit the generated file manually to remove the linebreak, nothing else works unfortunately.

0 Likes