Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Formatting Text

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old November 3rd, 2014, 01:17 PM
MeeshKB MeeshKB is offline
Regular Contributor
 
Join Date: Jun 2012
Location: Alberta, Canada
Posts: 64
Default Re: Superscript tag inside ReplaceSubstring rule

Dan's solution is (as expected) far more eloquent than mine.

Glad you got it to work. :-)
__________________
Michelle
Digital Services Coordinator at Rileys (print and electronic services provider) in Alberta, Canada
FusionPro VDP 9.1.0, Windows 7, Acrobat Pro XI , InDesign CS6, Avanti eAccess, EFI Digital Storefront
Reply With Quote
  #12  
Old August 15th, 2016, 01:56 PM
VernF88 VernF88 is offline
Junior Community Member
 
Join Date: Aug 2016
Posts: 11
Default Re: Superscript tag inside ReplaceSubstring rule

Quote:
Originally Posted by step View Post
You need to use superscript tags. Edits made in red:
Code:
var s = Rule("Fit Name Degree Designation");
s = ReplaceSubstring(s, "LEED", "LEED<superscript>&reg;</superscript>");
return s;
Hello, I have a customer who sends us documents that are plastered with disclaimer characters (ex. +, ^, etc.) that they expect us to change to superscript. Currently we highlight each disclaimer character in the text frame and click the "sup" button. I attempted javascript to remedy this with the code provided here modified for my purposes. Is it possible to locate and replace characters within a text frame to superscript? Thank you. Here is my attempt:

Code:
FusionPro.thisRuleReturnsTaggedText = true;

var myFrame = FindTextFrame("FullBody");

myFrame = ReplaceSubstring(myFrame, "+", "<superscript>+</superscript>");

return myFrame;
Reply With Quote
  #13  
Old August 15th, 2016, 03:01 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Superscript tag inside ReplaceSubstring rule

Quote:
Originally Posted by VernF88 View Post
Hello, I have a customer who sends us documents that are plastered with disclaimer characters (ex. +, ^, etc.) that they expect us to change to superscript. Currently we highlight each disclaimer character in the text frame and click the "sup" button.
You could try putting this in your OnRecordStart rule:
Code:
var chars = [
  '\\^',
  '\\+',
  // Add as many as you like
];

var text = FindTextFrame('FullBody').content
  .replace(/<variable name="([^"]*)">/g, 
    function(s,p) { 
      return FieldOrRule(p);
    })
  .replace(new RegExp('(' + chars.join('|') + ')', 'g'), 
    '<superscript>$1</superscript>');

FindTextFrame('FullBody').content = text;
The above code will superscript all occurrences of +/^ in a text frame named "FullBody." You can add additional characters to be superscripted to the 'chars' array. Keep in mind that both plus signs and carets have special meanings in regular expressions so they must be escaped.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #14  
Old August 15th, 2016, 03:05 PM
VernF88 VernF88 is offline
Junior Community Member
 
Join Date: Aug 2016
Posts: 11
Smile Re: Superscript tag inside ReplaceSubstring rule

Thank you so much! That works perfectly!
Reply With Quote
  #15  
Old August 15th, 2016, 03:20 PM
VernF88 VernF88 is offline
Junior Community Member
 
Join Date: Aug 2016
Posts: 11
Default Re: Superscript tag inside ReplaceSubstring rule

When I add in "†" and "‡" characters the rule doesn't seem to move them, also is there a way to make a similar rule to replace place holders? For example "<<first>>" being automatically replaced with "Field("First Name")"?

Last edited by VernF88; August 15th, 2016 at 04:07 PM..
Reply With Quote
  #16  
Old August 15th, 2016, 04:09 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Superscript tag inside ReplaceSubstring rule

Code:
var chars = {
// Find:        Replace:
  '\\^':        '<superscript>^</superscript>',
  '\\+':        '<superscript>+</superscript>',
  '<<first>>':  Field("First Name"),
}

var text = FindTextFrame('FullBody').content
  .replace(/<variable name="([^"]*)">/g, 
    function(s,p) { 
      return FieldOrRule(p);
    });

for (var i in chars)
  text = text.replace(new RegExp(i, 'g'), chars[i]);

FindTextFrame('FullBody').content = text;
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #17  
Old August 15th, 2016, 04:53 PM
VernF88 VernF88 is offline
Junior Community Member
 
Join Date: Aug 2016
Posts: 11
Default Re: Superscript tag inside ReplaceSubstring rule

Quote:
Originally Posted by step View Post
Code:
var chars = {
// Find:        Replace:
  '\\^':        '<superscript>^</superscript>',
  '\\+':        '<superscript>+</superscript>',
  '<<first>>':  Field("First Name"),
}

var text = FindTextFrame('FullBody').content
  .replace(/<variable name="([^"]*)">/g, 
    function(s,p) { 
      return FieldOrRule(p);
    });

for (var i in chars)
  text = text.replace(new RegExp(i, 'g'), chars[i]);

FindTextFrame('FullBody').content = text;
Here's what I've got after completing what I would want done in the format above:
Code:
var chars = {

// Find:        Replace:

  '\\^':        '<superscript>^</superscript>',

  '\\+':        '<superscript>+</superscript>',

  '\\†':        '<superscript>†</superscript>',

  '\\‡':        '<superscript>‡</superscript>',     

  '<<first>>':  Field("First Name"),

  '<<last>>':    Field("Last Name"),

  '<<year>>':    Field("Year"),

  '<<make>>':    Field("Make"),

  '<<model>>':   Field("Model"),

  '<<model2>>':  Field("Model2"),

  '<<model3>>':  Field("Model3"),

  '<<V1>>':      Field("V1"),

  '<<V2>>':      Field("V2"),

  '<<V3>>':      Rule("V3R"),

  '<<V4>>':      Rule("V4R"),

  '<<V5>>':      Field("V5"),

  '<<more>>':    Rule("MoreR"),

  '<<actual>>':  Rule("ActualR"),

  '<<winno>>':   Field("WinNo"),

}



var text = FindTextFrame('FullBody').content

  .replace(/<variable name="([^"]*)">/g, 

    function(s,p) { 

      return FieldOrRule(p);

    });



for (var i in chars)

  text = text.replace(new RegExp(i, 'g'), chars[i]);



FindTextFrame('FullBody').content = text;
The only thing that is affecting inside of the text frame is the "+" and "^" characters. Am I keying something wrong?

Last edited by VernF88; August 15th, 2016 at 05:13 PM..
Reply With Quote
  #18  
Old August 15th, 2016, 05:25 PM
VernF88 VernF88 is offline
Junior Community Member
 
Join Date: Aug 2016
Posts: 11
Default Re: Superscript tag inside ReplaceSubstring rule

Okay for troubleshooting purposes I input 'first' instead of '<<first>>'. It then inserted the field, so it's the <<>> characters causing it to not work properly. Still not sure why the "†" and "‡" characters are not going to superscript though.
Reply With Quote
  #19  
Old August 15th, 2016, 06:18 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,369
Default Re: Superscript tag inside ReplaceSubstring rule

Quote:
Originally Posted by step View Post
You could try putting this in your OnRecordStart rule:
Code:
var chars = [
  '\\^',
  '\\+',
  // Add as many as you like
];

var text = FindTextFrame('FullBody').content
  .replace(/<variable name="([^"]*)">/g, 
    function(s,p) { 
      return FieldOrRule(p);
    })
  .replace(new RegExp('(' + chars.join('|') + ')', 'g'), 
    '<superscript>$1</superscript>');

FindTextFrame('FullBody').content = text;
The above code will superscript all occurrences of +/^ in a text frame named "FullBody." You can add additional characters to be superscripted to the 'chars' array. Keep in mind that both plus signs and carets have special meanings in regular expressions so they must be escaped.
Or you could just do this:
Code:
var frame = FindTextFrame('FullBody');
frame.content = frame.content.replace(/([\^\+]+)/g, '<superscript>$1</superscript>');
Also, why are you doing this?
Quote:
Originally Posted by step View Post
Code:
  .replace(/<variable name="([^"]*)">/g, 
    function(s,p) { 
      return FieldOrRule(p);
    })
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #20  
Old August 15th, 2016, 06:20 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,369
Default Re: Superscript tag inside ReplaceSubstring rule

Quote:
Originally Posted by VernF88 View Post
When I add in "†" and "‡" characters the rule doesn't seem to move them, also is there a way to make a similar rule to replace place holders? For example "<<first>>" being automatically replaced with "Field("First Name")"?
Where are these "place holders" coming from? Is this from a Data Merge in InDesign? If so, then in FusionPro 10, those will automatically be converted to variables when you export.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:37 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.