Click here to Skip to main content
15,884,099 members
Articles / Desktop Programming / WPF

Using AvalonEdit (WPF Text Editor)

Rate me:
Please Sign up or sign in to vote.
4.97/5 (271 votes)
1 Apr 2013LGPL313 min read 1.8M   72.3K   534  
AvalonEdit is an extensible Open-Source text editor with support for syntax highlighting and folding.
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
	<xsd:annotation>
		<xsd:documentation>
		This schema defines the syntax for mode definitions in SharpDevelop.
		The schema can be simplified quite a bit but it does the job as is.
		
		
		If you are using this file as a reference it is probably easiest to scroll to
		the botton to find the definition of the root element called SyntaxDefinition and
		then unwind the different type definitions and refernces.
		
		Note on coloring:
		Many tags define how some symbol should be colored. If a specific symbol
		can not be matched onto either a Span definition, Keyword, or a Digit/Number it
		will be rendered in the current default color. Which is the default color of the
		current span or the default color of the mode as a whole if no span has been entered.
		</xsd:documentation>
	</xsd:annotation>
	
	<!-- Defines the default rendering of the mode -->
	<xsd:complexType name="EnvironmentEntry">
		<xsd:attribute name="bold" type="xsd:boolean" />
		<xsd:attribute name="italic" type="xsd:boolean" />
		<xsd:attribute name="color" type="xsd:string" />
		<xsd:attribute name="bgcolor" type="xsd:string" />
	</xsd:complexType>
	
	<xsd:complexType name="CustomEnvironmentEntry">
		<xsd:attribute name="name" type="xsd:string" use="required" />
		<xsd:attribute name="bold" type="xsd:boolean" />
		<xsd:attribute name="italic" type="xsd:boolean" />
		<xsd:attribute name="color" type="xsd:string" />
		<xsd:attribute name="bgcolor" type="xsd:string" />
	</xsd:complexType>
	
	<!-- The environment tag defines the coloring of various attributes in SharpDevelop -->
	<xsd:complexType name="Environment">
		
		<xsd:choice minOccurs="0" maxOccurs="unbounded">
			<xsd:element name="Default" type="EnvironmentEntry" minOccurs="0" maxOccurs="1" />
			<xsd:element name="Selection" type="EnvironmentEntry" minOccurs="0" maxOccurs="1"/>
			<xsd:element name="VRuler" type="EnvironmentEntry" minOccurs="0" maxOccurs="1"/>
			<xsd:element name="InvalidLines" type="EnvironmentEntry" minOccurs="0" maxOccurs="1"/>
			<xsd:element name="CaretMarker" type="EnvironmentEntry" minOccurs="0" maxOccurs="1"/>
			<xsd:element name="CaretLine" type="EnvironmentEntry" minOccurs="0" maxOccurs="1"/>
			
			<xsd:element name="LineNumbers" type="EnvironmentEntry" minOccurs="0" maxOccurs="1"/>
			
			<xsd:element name="FoldLine" type="EnvironmentEntry" minOccurs="0" maxOccurs="1"/>
			<xsd:element name="FoldMarker" type="EnvironmentEntry" minOccurs="0" maxOccurs="1"/>
			<xsd:element name="SelectedFoldLine" type="EnvironmentEntry" minOccurs="0" maxOccurs="1"/>
			
			<xsd:element name="EOLMarkers" type="EnvironmentEntry" minOccurs="0" maxOccurs="1"/>
			<xsd:element name="SpaceMarkers" type="EnvironmentEntry" minOccurs="0" maxOccurs="1"/>
			<xsd:element name="TabMarkers" type="EnvironmentEntry" minOccurs="0" maxOccurs="1"/>
			
			<xsd:element name="Custom" type="CustomEnvironmentEntry" minOccurs="0" maxOccurs="unbounded"/>
		</xsd:choice>
	</xsd:complexType>
	
	<xsd:complexType name="Properties">
		<xsd:sequence>
			<xsd:element name="Property" type="Property" minOccurs="0" maxOccurs="unbounded"/>
		</xsd:sequence>
	</xsd:complexType>
	
	<xsd:complexType name="Property">
		<!-- The actual KeyWord, typically reserved words or symbols in a programming language -->
		<xsd:attribute name="name" type="xsd:string" />
		<xsd:attribute name="value" type="xsd:string" />
	</xsd:complexType>
	
	<!-- The Digits tag defines the color for rendering Digits-->
	<xsd:complexType name="Digits">
		<xsd:attribute name="name" type="xsd:string" />
		<xsd:attribute name="bold" type="xsd:boolean" />
		<xsd:attribute name="italic" type="xsd:boolean" />
		<xsd:attribute name="color" type="xsd:string" />
		<xsd:attribute name="bgcolor" type="xsd:string" />
	</xsd:complexType>
	
	<!-- Defines the delimiting characters of the syntax, e.g., the characters that, "break up" a line
    into separate symbols, typically key words. It is not necessary, or desirable to include the
    characters that denot the start or end of a span. Space and Tab are implicitly defined as delimeters
    and they don't need to be includeded explicitly (this will probably be changed at some future time).-->
	<xsd:complexType name="Delimiters">
		<xsd:simpleContent>
			<xsd:extension base="xsd:string">
			</xsd:extension>
		</xsd:simpleContent>
	</xsd:complexType>
	
	<!-- The beginning symbol of a Span -->
	<xsd:complexType name="Begin">
		<xsd:simpleContent>
			<xsd:extension base="xsd:string">
				<xsd:attribute name="singleword" type="xsd:boolean" />
				<xsd:attribute name="startofline" type="xsd:boolean" />
				<!-- The default rendering style for the Begin symbol. If not specified
					 the defaul rendering style for the span will be used. -->
				<xsd:attribute name="bold" type="xsd:boolean" />
				<xsd:attribute name="italic" type="xsd:boolean" />
				<xsd:attribute name="color" type="xsd:string" />
				<xsd:attribute name="bgcolor" type="xsd:string" />
			</xsd:extension>
		</xsd:simpleContent>
	</xsd:complexType>
	
	<!-- The end symbol of a Span -->
	<xsd:complexType name="End">
		<xsd:simpleContent>
			<xsd:extension base="xsd:string">
				<xsd:attribute name="singleword" type="xsd:boolean" />
				<!-- The default rendering style for the End symbol. If not specified
					 the defaul rendering style for the span will be used. -->
				<xsd:attribute name="bold" type="xsd:boolean" />
				<xsd:attribute name="italic" type="xsd:boolean" />
				<xsd:attribute name="color" type="xsd:string" />
				<xsd:attribute name="bgcolor" type="xsd:string" />
			</xsd:extension>
		</xsd:simpleContent>
	</xsd:complexType>
	
	<xsd:complexType name="Span">
		<xsd:sequence>
			<!-- Defines the symbol that indicates the beginning of the span. -->
			<xsd:element name="Begin" type="Begin" />
			<!-- Defines the symbol that indicates the end of the span. May be omitted for
				 one-line spans. -->
			<xsd:element name="End" minOccurs="0" type="End" />
		</xsd:sequence>
		<!-- The name of the span definition -->
		<xsd:attribute name="name" type="xsd:string" use="required" />
		<!-- Defines the rule set that is applicable in the Span. May be omitted. -->
		<xsd:attribute name="rule" type="xsd:string" />
		<!-- Defines wether the Span should terminate automatically at the end of line. Typical examples
       		 include one-line comments such as // in C++ or REM in Windows .Bat files. -->
		<xsd:attribute name="stopateol" type="xsd:boolean" />
		
		<!-- OBSOLUTE: Defines whether C-style escape sequences using \ are applicable or not in the span. -->
		<xsd:attribute name="noescapesequences" type="xsd:boolean" />
		
		<!-- defines the escape character -->
		<xsd:attribute name="escapecharacter" type="xsd:string" />
		
		<!-- The default rendering style for the span -->
		<xsd:attribute name="bold" type="xsd:boolean" />
		<xsd:attribute name="italic" type="xsd:boolean" />
		<xsd:attribute name="color" type="xsd:string" />
		<xsd:attribute name="bgcolor" type="xsd:string" />
	</xsd:complexType>
	
	<xsd:complexType name="MarkPrevious">
		<xsd:simpleContent>
			<xsd:extension base="xsd:string">
				<!-- Svante Lidman, looking in the code it is a bit unclear what the intent is here... -->
				<xsd:attribute name="markmarker" type="xsd:boolean" />
				<!-- The rendering style to be used -->
				<xsd:attribute name="bold" type="xsd:boolean" />
				<xsd:attribute name="italic" type="xsd:boolean" />
				<xsd:attribute name="color" type="xsd:string" />
				<xsd:attribute name="bgcolor" type="xsd:string" />
			</xsd:extension>
		</xsd:simpleContent>
	</xsd:complexType>
	
	<!-- Allows you to define the coloring of the symbol that follows a specified symbol -->
	<xsd:complexType name="MarkFollowing">
		<xsd:simpleContent>
			<xsd:extension base="xsd:string">
				<!-- Svante Lidman, looking in the code it is a bit unclear what the intent is here... -->
				<xsd:attribute name="markmarker" type="xsd:boolean" />
				<!-- The rendering style to be used -->
				<xsd:attribute name="bold" type="xsd:boolean" />
				<xsd:attribute name="italic" type="xsd:boolean" />
				<xsd:attribute name="color" type="xsd:string" />
				<xsd:attribute name="bgcolor" type="xsd:string" />
			</xsd:extension>
		</xsd:simpleContent>
	</xsd:complexType>
	
	<xsd:complexType name="Key">
		<!-- The actual KeyWord, typically reserved words or symbols in a programming language -->
		<xsd:attribute name="word" type="xsd:string" />
	</xsd:complexType>
	
	
	<!-- A grouping of keywords that sholuld be colored the same way -->
	<xsd:complexType name="KeyWords">
		<xsd:sequence>
			<!-- allow groups with 0 keywords: this simplifies the syntax highlighting editor -->
			<!-- A KeyWord -->
			<xsd:element name="Key" type="Key" minOccurs="0" maxOccurs="unbounded">
			</xsd:element>
		</xsd:sequence>
		<!-- The name of the KeyWord group -->
		<xsd:attribute name="name" type="xsd:string" />
		<!-- The rendering style of the  KeyWord group -->
		<xsd:attribute name="bold" type="xsd:boolean" />
		<xsd:attribute name="italic" type="xsd:boolean" />
		<xsd:attribute name="color" type="xsd:string" />
		<xsd:attribute name="bgcolor" type="xsd:string" />
	</xsd:complexType>
	
	<xsd:complexType name="RuleSet">
		<xsd:sequence>
			<!-- Defines the delimiting characters of the syntax, e.g., the characters that, "break up" a line
        		 into separate symbols, typically key words. It is not necessary, or desirable to include the
        		 characters that denot the start or end of a span. Space and Tab are implicitly defined as delimeters
        		 and they don't need to be includeded explicitly (this will probably be changed at some future time).-->
			<xsd:element name="Delimiters" type="Delimiters" minOccurs="0" maxOccurs="1">
			</xsd:element>
			<!-- A Span tag defines a scope, or what can be seen as a separate parsing context where a different set of
            	 highlighting rules are applicable compared to the text where the span is found. 
            	 Examples of spans include:
            	 - A string in a language as C
            	 - A <script> tag in Html
            	 - The internals of a tag in XML (between < and >).
            	 A span can have a rule set associated with it that defines the highlighting rules that are applicable
            	 in the span. -->
			<xsd:element name="Span" type="Span" minOccurs="0" maxOccurs="unbounded">
			</xsd:element>
			<!-- The MarkPrevious tag allows you to define the coloring of the item that preceeds a specific
            	 symbol. An example of where this comes in handy is when coloring the contents of an XML-tag,
            	 in particular the attributes and attribute names. The following definition:
            	 <MarkPrevious bold="false" italic="false" color="Red">=</MarkPrevious>
				 will make teh highlighter color words that are followed by an = to be colored in Red.
				 You can see this in this file if you view it with the default XML-mode in SharpDevelop. -->
			<xsd:element name="MarkPrevious" type="MarkPrevious" minOccurs="0" maxOccurs="unbounded">
			</xsd:element>
			<!-- The MarkFollowing tag works similarly as the MarkPrevious tag but relates to the coloring
            of the symbol that follows the specified symbol. -->
			<xsd:element name="MarkFollowing" type="MarkFollowing" minOccurs="0" maxOccurs="unbounded">
			</xsd:element>
			<!-- Defines a group of keywords that should be colored the same way -->
			<xsd:element name="KeyWords" type="KeyWords" minOccurs="0" maxOccurs="unbounded">
			</xsd:element>
		</xsd:sequence>
		<!-- The name of the RuleSet. Used when you refer to the RuleSet in the rule attribute of a Span tag.
        	 Each mode file should have a rule definition without a defined name. This denotes the default rule
        	 set for the mode. -->
		<xsd:attribute name="name" type="xsd:string" />
		<!-- Allows you to use another mode, defined in another file as a RuleSet. For an example see the
        	 use of the JavaScript mode from the HTML-mode. -->
		<xsd:attribute name="reference" type="xsd:string" />
		<!-- Defines whether case is significant for matching keywords in the mode. -->
		<xsd:attribute name="ignorecase" type="xsd:boolean" />
		<!-- OBSOLETE: noescapesequences -->
		<xsd:attribute name="noescapesequences" type="xsd:boolean" />
		<!-- defines the escape character -->
		<xsd:attribute name="escapecharacter" type="xsd:string" />
	</xsd:complexType>
	
	<!-- The RuleSets tag is just a grouping of the set of RuleSets for a mode. -->
	<xsd:complexType name="RuleSets">
		<xsd:sequence minOccurs="0" maxOccurs="unbounded">
			<!-- Any number of RuleSet tag can be defined in a mode -->
			<xsd:element name="RuleSet" type="RuleSet" minOccurs="1" maxOccurs="unbounded">
			</xsd:element>
		</xsd:sequence>
	</xsd:complexType>
	
	<!-- SyntaxDefinition is the root-element in a mode definition file -->
	<xsd:element name="SyntaxDefinition">
		<xsd:complexType>
			<xsd:sequence>
				<!-- The Environment tag defines colors, for various standard elements in the SharpDevelop GUI, if
				     not given the default values are used. -->
				<xsd:element name="Environment" type="Environment" minOccurs="0" maxOccurs="1"/>
				
				<!-- The Properties section defines properties which are bound to the highlighting -->
				<xsd:element name="Properties" type="Properties" minOccurs="0" maxOccurs="1" />
				
				<!-- The Digits tag defines the color for rendering Digits-->
				<xsd:element name="Digits" type="Digits" minOccurs="0" maxOccurs="1"/>
				
				<!-- The RuleSets tag defines the rule sets that are used in the mode. Note that all modes are defined in
					 a flat structture even if they are used recursively. For an example of a mode that uses
					 multiple rule sets see the XML-mode. There is a top level rule-set and and another rule-set
					 that handles highligting within a tag, i.e., between < and >. -->
				<xsd:element name="RuleSets" type="RuleSets" />
			</xsd:sequence>
			<!-- The name of the mode. This is used when you, in the defintion of a RuleSet refers to another
				 mode. I.e., one that is defined in an external file. For an example of this see the HTML-Mode that
				 uses the JavaScript-mode this way. -->
			<xsd:attribute name="name" type="xsd:string" />
			<!-- The file extensions that the mode is applicable for. Extensions must be written with lower case and
				 should include the ., as in .txt. If several extensions are applicable they should be separeated with | -->
			<xsd:attribute name="extensions" type="xsd:string" />
			<!-- Name of a syntax mode where rulesets, spans, keywords and other settings are imported from -->
			<xsd:attribute name="extends" type="xsd:string" />
		</xsd:complexType>
	</xsd:element>

</xsd:schema>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Germany Germany
I am the lead developer on the SharpDevelop open source project.

Comments and Discussions