Reply to: CTM file for tables from table menu?May 24, 2011 at 8:42 pm
Two table types are recognized: HTML and CALS. You cannot alter the behavior of the menu item, which recognizes that a table can be inserted and which table model your DTD or XSD is supporting. A different dialog is launched for each table type and that dialog ultimately calls one of these APIs when the table insertion is done: Selection.InsertTable() or Selection.InsertCALSTable().
Those APIs do not have any options along the lines of: “pad all my table cells with element X”.
You could replace the menu item (and toolbar item) however, so that it ends up calling your own custom dialog (designed using XFT). That would not be too difficult to do (see the CommandBars API object for this). The trickier portion of this would be recreating the dialog so that it would provide all the existing options you need to expose to your author but also include
elements inside your table cells.
If this is for DITA then keep in mind that we do not support making changes to the scripting portions of the DITA customization.
An alternative might be to write a script that walks the document to insert
elements for any content inside a table cell that is not already wrapped in a
(that would probably be a fairly simple check, something like checking to see if
was the first child of
elements as they wish. Then during an event such as On_Before_Document_Validate your script would run (which means that it would also run just before saving as validation is normally done then as well). Again, if this is for DITA then we wouldn't support making such changes, though in my opinion this approach would be safer if it is something you must do. I think there are a few possible cases that need to be decided:
1. Do you add a
when a cell is empty?
2. Do you wrap the content of a cell when it contains just PCDATA? (ie: the cell's has only one child and it is a text node)
3. If the cell already contains a
do you wrap any other PCDATA that is not wrapped in a
or leave it alone? The order of the child nodes might matter here (first child is
followed by other children, or first child is
4. If the cell already contains a non-
element (if that is possible for your schema) is that OK? Do you still need to add a
in this case?
There could easily be other things you need to check, depending on your schema and what you really wish to force on the authors.
Third approach would be to add similar logic into any post-save document processing that you may have as part of your overall solution. For example, some CMS systems allow documents to be processed and altered during check-in or check-out. Or you might integrate such logic into any XSLT or similar type of transform.
You could also alter the schema so that
is a required element inside your table cells. In this case XMetaL is still not going to automatically insert the
(that would be nice, but just not the case). However, when the document is validated the user would at least be told that there are missing
elements and they could then jump to each cell in the table using the Validation Log to insert them.