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
<Button label="insert field">
<cmd case="BaseExtensions:create-field-advanced"
Source="FromSelection"
Type="TC"
Flags="\f A \l "8"">
<Match value="(?<=\(|\[).+?(?=\)|\])"/>
<String value="	"/>
<Match value=".+?(?= \(|\[)"/>
</cmd>
</Button>
Above module configuration will result in below:
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.
Comments
0 comments
Please sign in to leave a comment.