Implementing a Custom Author Action to Split a Table
-
Follow the steps 1,3, 4 and 5 listed in this older blog post to create an extension of the DITA framework: Customizing the DITA Visual Editing Experience.
-
In the Document Type Association preferences page, edit the DITA framework extension you just created. Go to the Author->Actions tab and create a new action with the ID split.table. Use the predefined JSOperation to invoke a custom Javascript code. The custom action definition would look like this:
- Set as value to the script parameter of the operation the following
Javascript
code:
function doOperation(){ current = authorAccess.getDocumentController().getNodeAtOffset(authorAccess.getEditorAccess().getCaretOffset()); tableNode = null; rowNode = null; while(current != null) { if(tableNode == null && ("table".equals(current.getName()) || "informaltable".equals(current.getName()))) { tableNode = current; } if(rowNode == null && ("row".equals(current.getName()) || "strow".equals(current.getName()))) { rowNode = current; } current = current.getParent(); } if(tableNode != null && rowNode != null) { //Create a fragment starting from the row to the end of the table secondTable = authorAccess.getDocumentController().createDocumentFragment(rowNode.getStartOffset(), tableNode.getEndOffset()); //Delete the content from the first table. authorAccess.getDocumentController().delete(rowNode.getStartOffset(), tableNode.getEndOffset() - 1); //Insert the second table. authorAccess.getDocumentController().insertFragment(tableNode.getEndOffset() + 1, secondTable); } }
-
Go to the Author->Toolbar tab and use the Current actions panel to add the action with ID split.table to the toolbar.
-
When editing a DITA topic, pressing the toolbar action for splitting the table should now call your custom action and split the current table.
- You can add keyboard shortcuts for all custom actions either when defining them or from the Oxygen main menu Preferences->Menu Shortcut Keys page.