Extending Dreamweaver: Customizing the parsing of third-party tags.
Because I have been developing Dreamweaver plug-ins recently, there are very few Chinese materials, and my English is poor. When I check the English materials, I can't help but feel dizzy. After having to translate some of the important content into Chinese, I felt a lot more refreshed when I read it. This excerpt is excerpted from "Extending Dreamweaver 8" that comes with Dreamweaver 8. When translating, I referred to the "Dreamweaver 4 Chinese Help" translated by Xiakedao. But to be honest, I have some doubts that some parts of the help were translated using software such as Kingsoft Translation. Anyway, it is harder to read than English.
Server-side technologies such as ASP, Macromedia ColdFusion, JSP, and PHP use special non-HTML syntax in HTML files, and the server creates and serves HTML-formatted content based on these codes. When Dreamweaver detects non-HTML tags, Dreamweaver compares them by calling third-party tag definition files, which specify how Dreamweaver reads and displays these tags.
For example, in addition to the standard HTML language, ASP files also contain ASP code for the server to parse. ASP code looks similar to HTML tags. It is marked by a pair of tags, an opening <% and a closing %>. There is a file named Tags.xml in the Configuration/ThirdPartyTags folder of Dreamweaver. This file is used to describe various third-party tag specifications including ASP, and defines how Dreamweaver displays these codes. Using this approach, the ASP code has been standardized in Tags.xml, so Dreamweaver will no longer try to parse any code between <%...%>. However, in Design view, it will display an icon to indicate that this is ASP code. You can define your own tags and create a new tag library file for each set of tags to specify how Dreamweaver reads and displays your tags.
Note: This section describes how to define a method for Dreamweaver to display a custom label, but does not describe how to edit the custom label's content or properties. See Property Inspector for information on how to create a property inspector to inspect and modify the properties of a custom label.
Each tag library file defines the name, type, content mode, display specification, and icon of one or more custom tags. You can create any number of tag library files, but they must be located in the Configuration/ThirdPartyTags folder in order to be read and processed by Dreamweaver. Tag library files use the .xml file extension.
Tip: If you are working on several different websites at the same time (assuming you are a freelancer), you can define all the tag specifications in a file and store it on a special site for future use by other When someone maintains the site, you can hand over the complete tag library, including custom icons and property inspectors.
You need to define a tag specification using an XML tag called tagspec. For example, the following code represents a tag specification named happy.
<tagspec tag_name="happy" tag_type="nonempty" render_contents="false" content_model="marker_model" icon="happy.gif" icon_width="18" icon_height="18"></tagspec>
You can use tagspec to define Two kinds of labels:
·Common tags in HTML format
The happy tag example is an ordinary tag in HTML format. It starts with the <happy> tag, contains data between the opening and closing tags, and ends with the </happy> tag.
·String-delimited tags String-delimited tags start with one string and end with another string. They are similar to HTML empty tags (such as img) in that they contain neither content nor closing tags. . If happy is also a string-delimited tag, its definition specification must include two attributes: start_string and end_string. ASP tags are all string-delimited tags. They start with <% and end with %>, and there is no closing tag.
The following information lists the various attributes and valid values of the tagspec tag. Attributes with an asterisk ("*") indicate that they are not applicable to string-delimited tags, and optional attributes are marked with braces ({}); it is not difficult to infer that other properties that are not marked with braces are necessary properties.
<tagspec>
Describes
the default informationattributes
about third-party tags
tag_name, {tag_type}, {render_contents}, {content_model}, {start_string}, {end_string}, {detect_in_attribute}, {parse_attributes}, icon, icon_width, icon_height, { equivalent_tag}, {is_visual}, {server_model}
tag_name represents a custom name. For string-delimited tags, tag_name is used only to check whether a specific property inspector is applicable to the tag. If the first line of the attribute inspector contains the tag name in a conforming position (in fact, in the first line of declaration) and is marked with an asterisk ("*"), then the inspector will be allowed to inspect the type label. For example, the tag name of ASP code is ASP. Inspectors that allow checking ASP code must contain *ASP* in the first line. For information about the Property Inspector API, see Property Inspector.
tag_type determines whether the tag is empty (like the img mentioned earlier) or allows content to be placed between the opening and closing tags (like the code tag). This attribute is necessary for normal (non-string-delimited) tags, but has no effect on string-delimited tags because they are always empty. Valid values include "empty" and "nonempty".
render_contents determines whether the label displays the content in design view, or replaces it with a specific icon. This attribute is only necessary for non-empty tags and has no effect on empty tags (empty tags themselves have no content to display). This attribute only applies to tags inserted outside the attribute. If a tag is inserted into the attribute value of other tags, its content will not be displayed (this paragraph is a bit difficult to understand. I am thinking of Objects such as RealMedia and Flash. Inside those param tags? ). Valid values are "true" or "false".
content_model describes what kind of content this tag can contain, and where this tag can be inserted into the HTML file. Valid values include "block_model", "head_model", "marker_model", and "script_model":
·block_model means that the tag can contain block objects such as div and p, and the tag can only appear in the body area, or be inserted into other body-content tags, such as div, layer, and td.
·head_model means that the label can only contain text and can only appear in the HEAD range.
·marker_model means that the tag can contain any valid HTML code and can be placed anywhere within the HTML file. Dreamweaver's built-in HTML validator ignores tags defined as marker_model. However, the content contained in these tags is not ignored by the validator; so, although the tag itself can be placed anywhere, its content may cause errors in some parts of the HTML. For example, plain text cannot appear (except for legal head elements) in the head area of the document, so you cannot place a marker_model tag containing plain text in the head area (if you want to do this, you must change the tag's content model Replaced by marker_model with head_model). Tags using marker_model will be displayed on one line (within a block element such as a p or div - for example, within a paragraph). If you want the tag to display its own paragraph, leave blank lines before and after it. , then it is recommended not to use this mode.
·script_model allows this tag to be placed anywhere between HTML tags within the document. When Dreamweaver detects a tag using this mode, all content of the tag is ignored. Dreamweaver will not parse such tags (such as certain ColdFusion tags) when used.
start_string specifies a delimiter as the starting point for string-delimited labels. String-delimited labels can be placed anywhere a comment can be inserted. Dreamweaver will neither parse, encode, or link the code between start_string and end_string. This attribute is required when end_string has been defined.
end_string specifies a delimiter as the end point of a string-delimited label. Also, this attribute is required when start_string has been defined.
detect_in_attribute specifies whether to ignore all code between start_string and end_string (or between the start and end tags, if these two strings are not defined), regardless of whether attributes or values are inserted between these codes. Its default value is "false", but in general string-delimited tags should have this value set to "true". For example, the ASP tag specification specifies detect_in_attribute="true", so even if there are quotes containing attribute values inside the ASP tag, they will be ignored by Dreamweaver.
parse_attributes indicates whether to parse the attributes of the tag. If set to "true" (the default), Dreamweaver will parse these properties; if set to "false", Dreamweaver will ignore all code before the ">" outside the quotation marks. For example, tags such as cfif should have this attribute set to "false" (because Dreamweaver cannot parse a tag such as <cfif a is 1> as an attribute name/value pair).
icon specifies the path and file name of the icon that matches this label. This property is required for empty tags, as well as for non-empty tags whose content cannot be displayed in the document window's design view.
icon_width specifies the pixel width of the icon.
icon_height specifies the pixel height of the icon.
equivalent_tag specifies simple HTML equivalents for certain tags associated with forms in ColdFusion. This attribute cannot be used by other tags.
is_visual specifies whether the label is visible on the page. For example, the ColdFusion tag cfgraph does not specify a value for is_visual (so the default value "true" is used), and the ColdFusion tag cfset specifies a value for is_visual of "false". In the "Invisible elements" column of the default dialog box, you can control the visibility of server labels; the visibility of visual server labels and non-visual server labels can be set separately.
server_model, if set, indicates that the tagspec tag can only be applied to pages belonging to the specified server model. If not set, tagspec can be applied to all pages. For example, the delimiters for ASP and JSP are the same, but the tagspec tag applicable to JSP specifies the server mode as "JSP", so when Dreamweaver detects a specific delimiter on a JSP page, it displays a JSP icon; When the same code is detected in a non-JSP page, it displays the ASP icon.
Nocontent
(empty tag).
Container
None.
Example
<tagspec tag_name="happy" tag_type="nonempty" render_contents="false" content_model="marker_model" icon="happy.gif" icon_width="18" icon_height="18"></tagspec>
Custom tag in design How the view displays
custom tags in the design view of the document window depends on the values of the tag_type attribute and render_contents attribute of the tagspec tag (see the analysis of custom third-party tags). If the value of tag_type is "empty", the specified icon defined by the icon attribute is displayed. If the value of tag_type is "nonempty" but the value of render_contents is "false", the icon will also be displayed like an empty tag. The following example demonstrates how an instance of the happy tag we just defined can be inserted into HTML code:
<p>This is a paragraph that includes an instance of the <code>happy</code>tag (<happy>Joe</ happy>).</p>
Because render_contents has been set to "false" in the tag specification, the happy tag (word joe) will not be displayed, and the opening and closing tags including the content between them will be replaced with a Simple icon.
For a non-empty tag with a render_contents value of "true", the design view will not display it as an icon, but will display the content between the opening and closing tags (such as the text between the tags, like this: <mytag> This is the content between the opening and closing tags </mytag>). If View > Visual Assistants > Invisible Elements is selected in the menu option, then this content will be highlighted using the third-party tag color specified by the "Code Color" parameter ("Code Color" only applies to tag library files
How to change the highlight color of third-party tags:
1.
Select Edit > Preferences in the menu options, and then select the "Code Color" column.
2. Click the third-party label color box to display the color picker.
3. Select a color, then click "OK" and close the preset dialog box. For information on how to choose colors, see also Using Dreamweaver.
Avoid rewriting third-party tags
Dreamweaver will correct certain errors in HTML code. For more information, please refer to Using Dreamweaver. By default, Dreamweaver prevents changes to HTML code in files with certain file extensions, including .asp (ASP), .cfm (ColdFusion), .jsp (JSP), and .php (PHP). This default setting is to ensure that Dreamweaver does not accidentally modify any code contained in non-HTML tags. You can change Dreamweaver's default rewriting behavior so that HTML code is rewritten when such files are opened, and you can add other file types to the list of file types that Dreamweaver prohibits rewriting.
When you enter certain special characters into the Property inspector, Dreamweaver encodes them into numeric values. Generally speaking, it is best to let Dreamweaver perform this encoding because these special characters will likely be displayed better across different platforms and browsers. However, because this encoding affects third-party tags, you may want to change Dreamweaver's encoding behavior when you edit files that include third-party tags.
Allow Dreamweaver to rewrite HTML in more types of files:
1. Select Edit > Preferences in the menu options, and then select the "Code Rewriting" column
2. Choose any of the following:
·Correct illegal nested tags or unending tags ·Delete redundant closing tags
3. Do one of the following:
· Remove one or more file extensions from the "Never rewrite code: in files with extensions" list.
· Uncheck the "Never rewrite code: in files with extensions" option. Please note: This allows Dreamweaver to rewrite HTML code in any type of file.
Add file types that Dreamweaver prohibits rewriting:
1. Select Edit > Preferences in the menu options, and then select the "Code Rewriting" column
2. Choose any of the following:
·Correct illegal nested tags or unending tags ·Delete redundant closing tags
3. Confirm that the "Never rewrite code: in files with extensions" item is selected and add the new file extension to the list in the text box.
If the new file type does not appear in the pop-up menu of the File > Open dialog box, you may need to add it to the Configuration/Extensions.txt folder. For details, see Changing the Default File Type.
Turn off Dreamweaver's coding options:
1. Select Edit > Preferences in the menu options, and then select the "Code Rewrite" column
2. Cancel either of the two "Special Character Encoding" options.
For additional information on selecting Code Rewrite preferences, see Using Dreamweaver.