A JavaScript Example for Formatting DITA Topics

JavaScript examples and a conditional text setup in Adobe FrameMaker.

It’s time to make an automated tool for some easy work: the script will set font styles and heading formatting on some DITA topics in FrameMaker. The script automatically loops through your topics, finds headings, and applies a predefined style to them.

JavaScript Script Example:

This script sets the font to “Arial” and applies the heading style to any text that matches the “Heading1 context” tag.

// JavaScript to format all headings in a FrameMaker document

var doc = app.ActiveDoc; // get the active document
var paragraphFormat = doc.ParagraphFormats.Item(“Heading1”); // style for Heading1

// Loop through all the Paragraphs in the document
for(var i=1; i<= doc.Paragraphs.Count; i++) {
var para = doc.Paragraphs.Item(i);

// Check if the paragraph is a Heading1
if (para.Format.Name == “Heading1”) {
// Set Heading1 paragraph to Arial font
para.TextFont = “Arial”;

// Apply Heading1 defined style
para.Format = paragraphFormat;
}
}

How to Run the Script?

  1. Open FrameMaker and have your DITA content opened.
  2. File > Scripts > Script Editor: Opens the JavaScript editor.
  3. Copy the script into the editor.
  4. Click Run to apply font and heading formatting to all headings found in the document.

What This Script Does:

  1. It applies to all Heading1 paragraphs found in the current document.
  2. The font for these headings is set to Arial.
  3. It ensures that Heading1 style is applied uniformly for all matching paragraphs.

Leave a Comment

Your email address will not be published. Required fields are marked *