Create field (W)

Modified on Mon, 5 Oct at 1:55 PM

With BaseExtensions we are able to insert fields into Word, customizing the field code as we insert. This feature was built generically, but is currently quite limited in functionality.

Basically, this is a feature that can search and replace field codes in Word.

CMD

<Cmd case="BaseExtensions:create-field-advanced"/>

Parameter

Source

Can only be defined to FromSelection for now. This will set the source for the command to the current selection.

Type

This parameter can be defined to either TC or DOCPROPERTY.

A TC field is a native Word field that is used to reference specific words or sentences in a table of contents, e.g. a glossary list or a list of abbreviations and acronyms.

Flags

Define the flags (or switches) to be added to the field, example in bold: { TOC \o "1-3" \h \z \u }. This parameter is required if the type of field is TC, and should be empty if it is defined to be a document property.

The values defined in the parameter must be escaped xml in order for the module to parse.

Here is a list of available switches for TC fields in MS Word.

HasQuotes

Define whether or not string value is inserted as a quoted string, using true or false. The default value is true which will enclose the string value in quotes.

This parameter is required if the type of field is defined to be a document property, and should be omitted if the type is a TC.

Children (<Match> and <String>)

The command can have any number of children defined. Currently, the only allowed children are <Match> and <String>.

Using Regex we are able to match selection to a string defined in <Match> and replace it with value in <String>.

Example

XML
<Button label="insert field">
  <cmd case="BaseExtensions:create-field-advanced"
      Source="FromSelection"
      Type="TC"
      Flags="\f A \l &quot;8&quot;">
        <Match value="(?&lt;=\(|\[).+?(?=\)|\])"/>
        <String value="&#09;"/>
        <Match value=".+?(?= \(|\[)"/>
  </cmd>
</Button>

Above module configuration will result in below:

mceclip1.png

The context here is that the user is adding acronyms to a list in the beginning of the document. Selecting the term and it's corresponding acronym, the user clicks the button and runs the command.

The command will then produce the TC field matching selected content before parenthesis and inside parenthesis using Regex syntax, before adding flags.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article