General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › Inserting element example b(bold) i(Italic) in run time
-
karthic2861 September 17, 2012 at 9:34 am
Inserting element example b(bold) i(Italic) in run time
September 17, 2012 at 9:34 amParticipants 4Replies 5Last Activity 10 years, 4 months agoHi all,
Is that possible can we able to insert element like bold and other element in run time using script.
Please guide me
Regards
MDerek Read September 17, 2012 at 5:19 pm
Reply to: Inserting element example b(bold) i(Italic) in run time
September 17, 2012 at 5:19 pmYou 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.karthic2861 September 18, 2012 at 9:13 am
Reply to: Inserting element example b(bold) i(Italic) in run time
September 18, 2012 at 9:13 amHi 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.
Derek Read September 18, 2012 at 7:39 pm
Reply to: Inserting element example b(bold) i(Italic) in run time
September 18, 2012 at 7:39 pmCoincidentally, someone else just asked this question. See this post: http://forums.xmetal.com/index.php/topic,2496.0.html
karthic2861 September 19, 2012 at 10:30 am
Reply to: Inserting element example b(bold) i(Italic) in run time
September 19, 2012 at 10:30 amHi Derek,
Thanks for the reply
Can you please explain me bit more with javascript and i have xmetal author 5.5
Please guide
Regards
MDerek Read September 19, 2012 at 5:37 pm
Reply to: Inserting element example b(bold) i(Italic) in run time
September 19, 2012 at 5:37 pmDoes 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 -
AuthorPosts
- You must be logged in to reply to this topic.