DITA and XMetaL Discussion

XMetaL Community Forum DITA and XMetaL Discussion OnInsert scripting when wrapping a selection

  • paul_cpwr

    OnInsert scripting when wrapping a selection

    Participants 0
    Replies 1
    Last Activity 11 years, 2 months ago

    I've edited the CTM file such that the insertion of a draft-comment element runs a JScript function to automatically populate the author and time attributes. I did this using a JScript function loaded with the application and not an XMetaL macro (via Application.Run).

    When the selection is an insertion point, the function fires and I get a draft-comment with the attributes populated. However, when the selection is a range (text within a paragraph or a collection of multiple paragraphs), I get the element inserted, wrapping the selection like I want, but none of the attributes get populated. It's as if the OnInsert script is being ignored and the insert falls back to default behavior.

    I seem to remember that there is something I can do to handle the “wrap” case, but I can't remember it or find it in the doc.

    Here's the function being called, which handles the insertion of draft-comment elements and our specialized beta-comment element. For draft-comment, the OnInsert script is:


    The code for the actual function is:

    function codexInsertCommentElement(type) {
        var newElem = type + “-comment”;
    var author = getCodexAuthor();
    var d = new Date();
    if (author != “UNKNOWN”) Selection.ElementAttribute(“author”,newElem) = author;
    Selection.ElementAttribute(“time”,newElem) = d.getFullYear() + “-” + (d.getMonth() + 1) + “-” + d.getDate();

    Please ignore the getCodexAuthor() function call; that code is working.

    Any suggestions are welcome.

    Best regards,

    Paul Anderson
    Compuware Corporation


    Derek Read

    Reply to: OnInsert scripting when wrapping a selection

    Strictly speaking, making this type of mod to the DITA functionality is not supported (so you'll have to support your clients that are using this on your own). The approach I would take here is to insert a debugger statement into your code and then step through it. Hopefully you have Visual Studio or similar. If not you can try using Windows Script Debugger.

    I suspect that your code is attempting to do something that the DITA authoring code already does. If you step through your code you will likely see that eventually the debugger jumps out of your file into one of our scripts. At that point I'm not sure what your strategy should be. I don't recommend changing the code we ship but perhaps it will help you understand what is happening so you can modify yours.

    Another option would be to write up a feature request and submit it to XMetaL Support. This just needs to describe your goals (not design the feature) in the broadest possible terms. You might think the script is self explanatory, but there must be some background to this. The basic question to answer is “who is this for” (the type of user) and “why”. If it makes sense for the general population to have a feature that helps you (not necessarily the feature you think you want) then it would be considered for a future release.


  • You must be logged in to reply to this topic.

Lost Your Password?