Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

How paste XML code sample into a DITA topic and have tags ignored?


How paste XML code sample into a DITA topic and have tags ignored?

Hi, all...

I'd like to paste a code sample between <codeblock> tags for a DITA topic in Arbortext Editor 5.3 M010. The code sample is itself DITA XML. How can I paste this text and have Arbortext ignore tags, e.g. by automatically converting angle brackets and other characters that must be escaped into entities? Or some other way to do this...whatever works.

I don't want to have to create the entities by hand before pasting. Oxygen, for example,does this for you when you paste.

The code to paste looks like this:

<title>Information Model</title>
<author>John Smith</author>
<topicref format="dita" href="c_RevisionHistory.dita"></topicref>
<topicref format="dita" href="c_Introduction.dita"></topicref>




Hi Steve-

You can use code like this:



The easiest thing would be to put it in a function and hang it off a
menu item and/or assign a keyboard shortcut, like so:

function pasteCode() {

# assumes cursor is positioned appropriately and clipboard contains
code sample

local buf;




menu_add .Edit. "Paste Code Sample" -cmd { pasteCode() }

map control-shift-v { pasteCode() }



Thanks, Clay and Paul...

Clay, your suggestion worked fine. However, after adding the menu choice to the Edit menu, it disappeared after I opened a document. I guess that is because the Edit menu changes depending on context. Do either of you have a way of making the new menu choice stick around?

Paul, your way seems more straightforward, but I like the idea of a single keystroke that pastes the clipboard as text. This way, we don't have to worry about "modes." (Am I in "paste as text" mode or "paste as XML" mode?). I find that users don't do well with modes, and research by Apple Computer confirms this. This is why the very first Macintosh (actually, the Lisa), used an insertion point cursorand did away with insert or overwrite modes.

I suppose I could write a small script that sets sgmlselection=off, does a paste (can I do that from a script?), and then sets sgmlselection back on, and I could map a key to that script.

May I ask you to comment, please?


In Reply to Paul Grosso:

Hi Steve--

Yes, the code for modifying your menu to add the Paste Code option will need to be in one of your startup files. If the change only applies to a particular doctype or doctypes, you can add the menu_add command to the instance.acl file for the relevant doctype(s).

If you want the change to be globally available, you might want to copy into your custom directory and add the new menu option there.



Maybe I'm missing something. Why can't you first insert a CDATA section, then any markup you want inside that? Or, doesn't DITA support that?

Dave Hintz

Getting persistent custom menu options was kinda hit-and-miss (at least
up through 5.2, they seem to have improved since then). Even with
custom menus in a startup file, certain contexts will reload the menus
and lose the custom menu option. The is an option, but you
have to reconcile it with the distributed one when you upgrade your
Editor clients.

One method I've used for FedEx menus (absolutely has to be there every
time), is the menuloadhook.

You have to be careful in how you code your menu_add commands to ensure
that your menus will load regardless of the menu context that may load
depending on document type (and other conditions), but attaching a
function for your menu_add commands to a menuloadhook function will
ensure that menus get loaded every time
Top Tags