Replace Rules

This section defines HTML elements that can be replaced with a MAML equivalent.

Rule Processing

The rules in this section make an attempt at replacing HTML elements with the closest MAML equivalent. The entries consist of Tag elements with various attribute combinations that define the HTML element and its replacement. Nested Match elements can be used to further refine how the replacement occurs.

The Tag element can contain the following attributes:

Attribute

Purpose

name

The HTML element to replace. This attribute is required.

startTag

The value to use as the replacement opening tag. If omitted and no nested match rules are met, the element will be removed. If the replacement value contains "<" or ">", the value is used as a verbatim replacement. If not present, the replacement is wrapped in "<" and ">". Any attributes and the self-closing "/" are included if necessary.

endTag

The value to use as the replacement closing tag. Normally, this is omitted and the startTag value is used for the closing tag as well. However, if it differs, this can be used to specify the value for it. As with startTag, if the replacement value contains "<" or ">", the value is used as a verbatim replacement. If not present, the replacement is wrapped in "</" and ">".

attributes

This can be used to define a replacement set of attributes that will appear on the MAML element. If omitted, all attributes from the HTML element are removed and the MAML element will not have any attributes. If set to the value "@Preserve", the HTML attributes will be preserved and will be added as attributes on the replacement MAML element as-is. For any other value, the specified text replaces the HTML attributes. If startTag contains "<" or ">", this attribute is ignored.

  Note

All name and regular expression values are matched case-insensitively.

Defining Additional Match Rules

In certain cases, it may be necessary to define additional match conditions to define the replacement MAML element. To do this, add one or more Match elements as children of the related Tag element.

The Match element can contain the same attributes as the Tag element in any needed combination. In addition, it has a required expression attribute that defines the regular expression used to match the specific instance of an HTML element. If a match is made, the other attributes on the Match element are used instead of the attributes on the parent Tag element. If none of the expressions result in a match, the attributes on the parent Tag element are evaluated as usual.

Example Replacement Rules

  Note

Since they resides in an XML file, any special characters in the expressions such as <, >, &, ", and ' must be encode as shown in the example below.

Example Replace Entries
<Replace>
  <Tag name="abbr" startTag="phrase" />
  <Tag name="b" startTag="legacyBold" />
  <Tag name="br" startTag="&lt;para/&gt;" />
  <Tag name="comment" startTag="&lt;--" endTag="--&gt;" />

  <Tag name="div">
    <!-- If a match for 'class="deprecated"' is found, replace it with
         an alert.  If not matched, the element is removed. -->
    <Match expression="class=&quot;deprecated&quot;" startTag="alert"
      attributes="class=&quot;warning&quot;" />
  </Tag>

  <!-- Replace pre tags with a code element with no language or title. -->
  <Tag name="pre" startTag="code" attributes="language=&quot;none&quot; title=&quot; &quot;">
    <!-- However, if a lang/language attribute is defined, preserve
         the HTML attributes. -->
    <Match expression="lang(uage)?=" startTag="code" attributes="@Preserve" />
  </Tag>

  <!-- Like div, replace span if possible based on class or remove it -->
  <Tag name="span">
    <Match expression="class=&quot;code&quot;" startTag="codeInline" />
    <Match expression="class=&quot;command&quot;" startTag="command" />
    <Match expression="class=&quot;foreignPhrase&quot;" startTag="foreignPhrase" />
  </Tag>
</Replace>

See Also