Home Forums General XMetaL Discussion Clipboard (copy/paste)Javascript Functionality in Xmetal Reply To: Clipboard (copy/paste)Javascript Functionality in Xmetal

Derek Read

Reply to: Clipboard (copy/paste)Javascript Functionality in Xmetal

I see. So, you want basically this (I'm still guessing a little bit, sorry if this is wrong):

You have a custom DTD or Schema and that you have created your own customization for (CSS, CTM, MCR files, possibly other things).
You copy from a PDF document and that text goes onto the clipboard. The text contains newline characters (one or more “lines” separates by newline characters).
You paste from the clipboard into XMetaL Author (Enterprise? / Essential?).
When you paste into XMetaL Author you want each of those “lines” to be inserted into its own element. (Can I assume your DTD is DocBook then?)

The simplest case (if you are working with text only) is to use the event On_Document_Before_DropText.
See the Programmers Guide topic “When text is dropped” for a discussion and examples.

I think the basic logic in your case would be:

Inside an event called On_Document_Before_DropText
1) Put the text from ActiveDocument.DropText property into a new string.
2) Put each “line” from the string into an array by breaking the string on newline characters. If it is this simple I would just use the JScript function [url=http://msdn.microsoft.com/en-us/library/windows/apps/t5az126b%28v=vs.85%29.aspx]split()[/url] (the Programmers Guide example loads the text into MSXML which sounds like overkill in your case).
3) Build a new string by looping through the array and wrapping each item it contains (each “line”) with tags.
4) Set the property ActiveDocument.DropText equal to the new string.

If you need to use the HTML (or anything else) that is put onto the clipboard then things get more complicated. The benefit in this case is that you can try to preserve some of the markup in the original HTML by transforming it to whatever markup makes sense for your DTD / Schema. In this case you need to register a “drop format” with XMetaL in order to fire an event that handles that content. See the Programmers Guide topic “When objects are dropped” (“dropped” in the Windows context here includes “pasted”). It discusses how to do this but does not discuss how to transform HTML into any particular form (that will vary widely depending on your DTD / Schema). The DITA authoring functionality in XMetaL Author Enterprise does this so you could adapt part of that code to use as an example for your own DTD.

Reply

Products
Downloads
Support