• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Add tagged text mid paragraph

Community Beginner ,
Aug 10, 2017 Aug 10, 2017

Copy link to clipboard

Copied

I have a table of contents without the page numbers. I can't use the auto-TOC, so I'm trying to add the page numbers via script. The whole document is tagged, and I'm using those tags to find the page where each chapter starts. Now I just need to add the page number to the TOC reference. That's where I'm getting stuck.

I figured the easiest way to do it would be to create a temporary tag and add that to the end of each TOC reference, then set the contents of the temp tag to the page number, then untag it. It almost works, but the tag is added after the hard return (so it appears on the beginning of the next line, like so:

Screen Shot 2017-08-10 at 9.43.52 AM.png

The script I have so far is this:

function insertPageNumbers(tocItem, pageNum) {

    var tag1;

    tag1 = tocItem.xmlElements.add('TEMP');

    tag1.contents = pageNum;

}

The other idea I had was to add placeholder text (like 'xx' or something) first, then tag that text using a find, but that seems like it would be more cumbersome.

Can anyone give me an idea of how to insert the tag before the hard return, or do I need to go a different route?

TOPICS
Scripting

Views

311

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 10, 2017 Aug 10, 2017

Copy link to clipboard

Copied

LATEST

Hi,

     Its working for selection (ie., selection is xml element).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines