24.6.7 Selectively modifying table text with macros: an example
• Some columns in your tables have text that you want bold in HTML, even though in FrameMaker the text is not differentiated with a character format or an override.
• The columns in question all have column headings that include the word “Fields”.
• The paragraph format for table body cells is CellBody, and the format for column headings is CellHeading.
To achieve selective bolding, you can use macros to assign different class attributes to paragraph format CellBody, based on the content of each column heading.
Use macro variables to identify table columns
Create two macro variables to hold column numbers; for example, $$ColNum and $$FieldColNum. $$ColNum counts the columns in a table, and $$FieldColNum holds the column number of any column whose heading contains the word “Fields”.
If you are not using table macros for any other purpose, you can use a wildcard to specify the following macros for all tables:
; Reset $$FieldColNum for each table:
; Reset $$ColNum for each table row:
; Increment $$ColNum for each table column:
§24.2.3 Using wildcards to specify table sets
§24.6.1 Invoking macros around tables
Assign coding options to table-cell formats
Turn off the HTML paragraph tag that Mif2Go would otherwise automatically assign to CellBody, and specify macro code for both CellBody and CellHeading:
; CellBody formatting will be replaced by macro code:
CellBody=NoPara CodeStart CodeEnd
; CellHeading will hold column-heading content to be checked,
; and also provide the code for checking:
CellHeading=CodeStore CodeAfter
; Assign a macro to CellBody, so the code can exceed one line:
; Provide a closing tag for the class attribute:
; Use the CodeStore property assigned to CellHeading to
; capture the content of the current CellHeading paragraph,
; and also assign a macro, so the code can exceed one line:
CellHeading=<$$CellHeading><$CheckColHead>
§21.3.6 Stripping paragraph properties
§28.3.2 Assigning values to macro variables
§28.9.3 Surrounding or replacing text with code or macros
§28.3.7.2 Inserting code with the CodeStore property
Check for columns that need bolding
Use a conditional expression to check the content of each CellHeading paragraph:
; Use string operator "contains" to check the content;
; if the text sought is present, flag the column:
<$_if ($$CellHeading contains "Fields")>
Select a class attribute based on the column flag
To select a class attribute for CellBody, compare $$ColNum and $$FieldColNum in a conditional expression:
<p class="<$_if ($$FieldColNum == $$ColNum)>CellBodyBold
§28.6.4 Using control structures in expressions
§28.6.5 Specifying substrings in expressions
> 24 Converting tables to HTML > 24.6 Using macros to control table properties > 24.6.7 Selectively modifying table text with macros: an example