Pages: 1
Print
Author Topic: CTM file for tables from table menu?  (Read 2118 times)
scorho
Member

Posts: 17


« on: May 23, 2011, 02:49:08 PM »

Is there a ctm file or macro (or a file that gives me similar functionality) for tables created from the Table menu? The writers in my group prefer to have a <p></p> inserted automatically in table cells. It was easy enough to add them for tables created from the Element List by editing the ctm files, but I'm having trouble finding where to add that tag to tables created from the menu.
« Last Edit: May 24, 2011, 10:15:54 AM by scorho » Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2568



WWW
« Reply #1 on: May 24, 2011, 02:42:33 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 <p> 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 <p> elements for any content inside a table cell that is not already wrapped in a <p> (that would probably be a fairly simple check, something like checking to see if <p> was the first child of <td>, <th> or <entry> -- depending on your table model). I think that is what I would try first. Then your authors could work as usual, opting to insert <p> 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 <p> 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 <p> do you wrap any other PCDATA that is not wrapped in a <p> or leave it alone? The order of the child nodes might matter here (first child is <p> followed by other children, or first child is
4. If the cell already contains a non-<p> element (if that is possible for your schema) is that OK? Do you still need to add a <p> 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 <p> is a required element inside your table cells. In this case XMetaL is still not going to automatically insert the <p> (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 <p> elements and they could then jump to each cell in the table using the Validation Log to insert them.
Logged
Pages: 1
Print
Jump to:  

email us