Adobe Dreamweaver - adding new extensions and syntax highlighting

From NoskeWiki
Jump to navigation Jump to search


NOTE: This page is a daughter page of: Adobe Dreamweaver

I'm a big fan of Dreamweaver, and it comes with a big built in list of mappings from file types to code syntax highlighting, but every so often you might come across a file type which isn't highlighted the way you want. One big example of a file type that isn't recognized is Python (.py) files. Fortunately there is a way to add extra extensions and syntax highlighting "schemes" to Dreamweaver by editing a few of Dreamweaver's XML/configuration text files. Below I have outlined instructions on exactly how to perform these tasks using python as my example.

These instructions have been tested with Window 7 and Adobe Dreamweaver CS5, but work on MAC too. Be warned that for different versions of Windows and/or Dreamweaver you will probably find the files located in different slightly locations (see here). On a MAC computer you'll find all the files under: /Users/anoske/Library/Application Support/Adobe/Dreamweaver CS5/en_US/Configuration/etc....

WARNING: Before changing each file I strongly recommend you make a (backup) copy of each to your desktop. By doing this it should be easy to revert to the old version if you make any mistakes. Avoid making these backup copies to the same directory, as this might cause unexpected errors, despite you giving the file a different name (see here).

Step 1) Adding a New File Extension to Dreamweaver's Recognized Extensions (Extensions.txt)

Go to: "C:\Users\you\AppData\Roaming\Adobe\Dreamweaver CS5\en_US\Configuration"

Open the file "Extensions.txt" and add the following line of text to the end:

PY:Python Files

If you restart Dreamweaver it will now "recognize" .py files. In practical terms, this means that when you click the menubar: File > Open or File > Save As the option "Python Files (*.py)" will appear on the drop down list of file types. When you open such a file, however, it will still be in black-and-white: in other words this step alone is pretty useless!

TIP: To make this change for all users, edit the same file under "C:\Program Files\Adobe\Adobe Dreamweaver CS5\configuration instead. This goes for the files in step #3 and #4 too."

Step 2) Mapping a File Extension to (MMDocumentTypes.xml)

Go to: "C:\Program Files\Adobe\Adobe Dreamweaver CS5\configuration\DocumentTypes"

Open the file "MMDocumentTypes.xml" and add the following line of text after the 2nd last line, just before the "</documenttypes>" tag:

	<documenttype id="Python" internaltype="Text" winfileextension="py" macfileextension="py" file="" writebyteordermark="false" mimetype="text/py">
			<MMString:loadString id="mmdocumenttypes_70" />
			<MMString:loadString id="mmdocumenttypes_71" />

Here we specify that .py files should map to a new color scheme with the id "Python". This color scheme is created in a separate file. Also note that the number in 'mmdocumenttypes_70' and 'mmdocumenttypes_71' should follow on from the numbers above it. If you were happy mapping a new file extension to an existing color scheme you could list it here instead - for example you could replace the word "Python" with "Java". Alternatively, you could find the line "<documenttype id="Java" internaltype="Text" winfileextension="java" macfileextension="java" file="" ..." and modify it to "<documenttype id="Java" internaltype="Text" winfileextension="java,py" macfileextension="java,py" file="" ...". Unfortunately python is very different from all the default listed languages, meaning you'll probably want to read on and see how to make your own color scheme.

NOTE: If you can't edit this file, try copying the file to your (Windows) desktop, editing there and then dragging back in. This step will only works if you have admin privileges.

Step 3) Creating a new Syntax Color Scheme (CodeColoring.xml)

Go to: "C:\Users\anoske\AppData\Roaming\Adobe\Dreamweaver CS5\en_US\Configuration\CodeColoring"

Open the file "CodeColoring.xml" and add the following line of text after the first line:

NOTE: You can add it further down, but it's a long document, so I suggest the start.

	<scheme MMString:name="Python/scheme/name" id="Python" doctypes="Python" priority="20">
		<defaultText MMString:name="CodeColor_JavaDefaultText/defaultText/name" id="CodeColor_JavaDefaultText" />
		<blockStart MMString:name="CodeColor_JavaBlock/blockStart/name" id="CodeColor_JavaBlock" doctypes="JSP" scheme="customText"><![CDATA[<%]]></blockStart>
		<commentStart MMString:name="CodeColor_JavaComment/commentStart/name" id="CodeColor_JavaComment"><![CDATA[""""]]></commentStart>
		<stringStart MMString:name="CodeColor_JavaString/stringStart/name" id="CodeColor_JavaString"><![CDATA["]]></stringStart>
		<brackets MMString:name="CodeColor_JavaBracket/brackets/name" id="CodeColor_JavaBracket"><![CDATA[{[()]}]]></brackets>
		<operators MMString:name="CodeColor_JavaOperator/operators/name" id="CodeColor_JavaOperator"><![CDATA[+-*/%<>!?:=&|^~]]></operators>
		<numbers MMString:name="CodeColor_JavaNumber/numbers/name" id="CodeColor_JavaNumber" />
		<idCharRest MMString:name="CodeColoring/CodeColoring/CodeColor_Identifier" id="CodeColor_JavaIdentifier">_$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</idCharRest>
		<keywords MMString:name="CodeColoring/CodeColoring/CodeColor_PythonReservedWords/keywords/name" id="CodeColor_PythonReservedWords">
		<keywords MMString:name="CodeColoring/CodeColoring/CodeColor_PythonCommonWords/keywords/name" id="CodeColor_PythonCommonWords">
		<keywords MMString:name="CodeColoring/CodeColoring/CodeColor_PythonCommonFunctions/keywords/name" id="CodeColor_PythonCommonFunctions">
		<keywords MMString:name="CodeColoring/CodeColoring/CodeColor_PythonOther/keywords/name" id="CodeColor_PythonOther">
		<sampleText doctypes="Python"><![CDATA[from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, webapp World!')

application = webapp.WSGIApplication(
                                     [('/', MainPage)],

def main():

if __name__ == "__main__":

The syntax within these <scheme> tags is similar to the one listed for Java, but a lot of keywords and comments are different. Feel free to add your own words too. Notice that it keeps a reference to many colors used by Java (since these colors are a good choice), but in the last four "keywords" tags I've referenced four new color ids: "CodeColor_PythonReservedWords", "CodeColor_PythonCommonWords", "CodeColor_PythonCommonFunctions" and "CodeColor_PythonOther". If desired you can set these to match existing Java colors by changing all the matching values to "CodeColor_JavaReserved"... but in the final step below you'll see how to set your own colors.

Step 4) Creating a new Syntax Color Scheme (Colors.xml)

While still in: "C:\Users\anoske\AppData\Roaming\Adobe\Dreamweaver CS5\en_US\Configuration\CodeColoring"

Open the file "Colors.xml" and add the following line of text to the 3rd last line, just before the </colorGroup> tag:

		<syntaxColor id="CodeColor_PythonReservedWords" text="#0000FF" />
		<syntaxColor id="CodeColor_PythonCommonWords" text="#773300" />
		<syntaxColor id="CodeColor_PythonCommonFunctions" text="#009988" />
		<syntaxColor id="CodeColor_PythonOther" text="#990099" />

These colors are blue, brown, aqua and purple (respectively) but it's fairly easy to change them if you prefer other colors.

Step 5) Reload Dreamweaver and Check it Works!

Having edited four different files, make sure you've saved them all and now quit and restart Dreamweaver. If you've made all these changes correctly you should now be able to open a .py file and see your new Python color scheme / syntax highlighting appear! Finally!

Don't hesitate to e-mail me if you have further comments. As mentioned, different operating systems and/or versions of Dreamweaver may have these files located in slightly different locations.

See Also