General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Inserting element example b(bold) i(Italic) in run time

  • karthic2861

    Inserting element example b(bold) i(Italic) in run time

    Participants 4
    Replies 5
    Last Activity 10 years ago

    Hi all,

    Is that possible can we able to insert element like bold and other element in run time using script.

    Please guide me

    Regards
    M

    Reply

    Derek Read

    Reply to: Inserting element example b(bold) i(Italic) in run time

    You might use one of the following APIs:
      Selection.ToggleInline()
      Selection.InsertElement()
      Range.InsertElement()
      DOMNode_object.insertBefore()

    Here are a few simple examples written in JScript:

    [code]//XMetaL Script Language JScript:
    //If selection is not inside “bold” wrap it in “bold” if allowed by DTD.
    //If selection is inside “bold” and selection is entire element content then remove the containing element
    //or split it (depending on selection and DTD).
    Selection.ToggleInline(“bold”);[/code]

    [code]//XMetaL Script Language JScript:
    //Insert the element named “bold” at the current selection.
    //If not an insertion point the current selection will be replaced, if legal according to the DTD.
    Selection.InsertElement(“bold”);[/code]

    [code]//XMetaL Script Language JScript:
    //Insert the element named “bold” after the current selection.
    //Range is often preferable over Selection as manipulating a Range does not usually move the user's Selection.
    var rng = ActiveDocument.Range;
    rng.Collapse(sqCollapseEnd);
    rng.InsertElement(“bold”);[/code]

    [code]// XMetaL Script Language JScript:
    // Insert a new Sect1 element (node) before the first Sect1 in the document.
    //Paste this example in a “Journalist” DTD document.

    // Get the top level node
    var topElem = ActiveDocument.documentElement;
    if (topElem) {
    // Create the new Sect1 node
    var newSect1 = ActiveDocument.createElement(“Sect1”);
    // Visit each child node of the top-level node
    // until the desired node (if it exists) is found
    var nextChild=topElem.firstChild;
    while (nextChild && nextChild.nodeName!=”Sect1″) {
    nextChild = nextChild.nextSibling;
    }
    // If the desired node was found, insert the new
    // node before it. if (nextChild){
    var firstSect1 = nextChild;
    topElem.insertBefore(newSect1,firstSect1);
    }[/code]

    Depending on your exact needs you may need to add additional logic to those scripts.

    Many APIs let you insert elements. One of the following (or others I have missed) might be more suitable depending on your exact need:

      DOMNode_object.appendChild()
      DOMNode_object.insertBefore()
      Selection.Surround()
      Selection.SurroundNS()
      Selection.SplitContainer()
      Selection.InsertElementNS()
      Selection.InsertWithTemplate()
      Selection.InsertWithTemplateNS()
      Selection.InsertWithRequired()
      Selection.InsertWithRequiredNS()
      Selection.InsertCaption()
      Selection.InsertImage()
      Selection.InsertTable()
      Selection.InsertCALSTable()
      Selection.InsertRowsAbove()
      Selection.InsertRowsBelow()
      Selection.InsertColumnsLeft()
      Selection.InsertColumnsRight()
      Selection.TypingSplit()
      Selection.SplitToElementType()
      Selection.SplitToElementTypeNS()
      Range.Surround()
      Range.SurroundNS()
      Range.SplitContainer()
      Range.InsertElementNS()
      Range.InsertWithTemplate()
      Range.InsertWithTemplateNS()
      Range.InsertWithRequired()
      Range.InsertWithRequiredNS()
      Range.InsertCaption()
      Range.InsertImage()
      Range.InsertTable()
      Range.InsertCALSTable()
      Range.InsertRowsAbove()
      Range.InsertRowsBelow()
      Range.InsertColumnsLeft()
      Range.InsertColumnsRight()
      Range.TypingSplit()
      Range.SplitToElementType()
      Range.SplitToElementTypeNS()

    Additional useful APIs (that work with or support those listed above):

      Document_object.createElement()
      Document_object.createElementNS()
      Document_object.createDocumentFragment()
      Selection.CanInsert
      Selection.CanInsertList
      Selection.CanSplitContainer
      Selection.CanSurround
      Range.CanInsert
      Range.CanInsertList
      Range.CanSplitContainer
      Range.CanSurround
      Many Selection and Range methods that allow you to move the Selection and Range
      Many properties and methods that allow you to obtain a Selection or Range element name, attribute value, attribute name, etc.

    Reply

    karthic2861

    Reply to: Inserting element example b(bold) i(Italic) in run time

    Hi Derek,

    How to listen to toolbar button (B , I , U) click events in Xmetal using Macro,Script? To create tags accordingly

    for example if I press (B) from the toolbar in the xml i need to create tag as b.

    Please guide us.

    Reply

    Derek Read

    Reply to: Inserting element example b(bold) i(Italic) in run time

    Coincidentally, someone else just asked this question. See this post: http://forums.xmetal.com/index.php/topic,2496.0.html

    Reply

    karthic2861

    Reply to: Inserting element example b(bold) i(Italic) in run time

    Hi Derek,

    Thanks for the reply

    Can you please explain me bit more with javascript and i have xmetal author 5.5

    Please guide

    Regards
    M

    Reply

    Derek Read

    Reply to: Inserting element example b(bold) i(Italic) in run time

    Does the Journalist sample do what you want your customization to do?
    If so, please have another look at my answer at http://forums.xmetal.com/index.php/topic,2496.0.html

    Reply

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

Lost Your Password?

Products
Downloads
Support