MeeshKB Posted August 14, 2014 Share Posted August 14, 2014 I currently have this rule which replaces the word "LEED" with "LEED®". var s = Rule("Fit Name Degree Designation"); s = ReplaceSubstring(s, "LEED", "LEED<®>"); return s; The one tweak I need to make is to superscript the Registered Trademark symbol. Just not sure of the syntax for doing that within the ReplaceSubstring expression. Could someone please point me in the right direction? Thanks so much! Quote Link to comment Share on other sites More sharing options...
step Posted August 15, 2014 Share Posted August 15, 2014 You need to use superscript tags. Edits made in red: var s = Rule("Fit Name Degree Designation"); s = ReplaceSubstring(s, "LEED", "LEED<[color="Red"]superscript>[/color]®[color="red"]</superscript[/color]>"); return s; Quote Link to comment Share on other sites More sharing options...
MeeshKB Posted August 15, 2014 Author Share Posted August 15, 2014 Thanks so much, Ste. I knew the <superscript> tags would be involved, but wasn't sure of the syntax inside the ReplaceSubstring expression. I really appreciate the direction. Quote Link to comment Share on other sites More sharing options...
brobinson Posted October 30, 2014 Share Posted October 30, 2014 Hello, I am running into the same issue, however the <superscript></superscript> tags don't seem to be working for me. It's obvious the code is working: return Field("Disclaimer").replace(/SM/g,<superscript>SM</superscript>); because I can replace the SM with anything else, and it does change it, however, does not make is superscript. I've tried changing fonts to see if that made a difference, but it has not. I am running 9.1.0 on Windows. Any help would be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
MeeshKB Posted October 30, 2014 Author Share Posted October 30, 2014 Try this... return Field("Disclaimer").replace(/SM/g,'<superscript>'+ "SM" + '</superscript>'); That worked for me. Quote Link to comment Share on other sites More sharing options...
brobinson Posted October 30, 2014 Share Posted October 30, 2014 Sadly that didn't seem to work either. It actually returned this: Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 30, 2014 Share Posted October 30, 2014 You need some quotes around the literal string in your code: return Field("Disclaimer").replace(/SM/g,"<superscript>SM</superscript"); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 30, 2014 Share Posted October 30, 2014 Sadly that didn't seem to work either. It actually returned this: You also need to check the "Treat returned strings as tagged text" box. Quote Link to comment Share on other sites More sharing options...
brobinson Posted October 30, 2014 Share Posted October 30, 2014 OMG, you are amazing! That was perfect! Thank you, thank you! I am by no means a javascript person, I had one computer programming class in like the 11th grade, so I appreciate the help! Quote Link to comment Share on other sites More sharing options...
brobinson Posted October 30, 2014 Share Posted October 30, 2014 Also thank you so much to MeeshKB! Quote Link to comment Share on other sites More sharing options...
MeeshKB Posted November 3, 2014 Author Share Posted November 3, 2014 Dan's solution is (as expected) far more eloquent than mine. Glad you got it to work. :-) Quote Link to comment Share on other sites More sharing options...
VernF88 Posted August 15, 2016 Share Posted August 15, 2016 You need to use superscript tags. Edits made in red: var s = Rule("Fit Name Degree Designation"); s = ReplaceSubstring(s, "LEED", "LEED<[color="Red"]superscript>[/color]®[color="red"]</superscript[/color]>"); 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: FusionPro.thisRuleReturnsTaggedText = true; var myFrame = FindTextFrame("FullBody"); myFrame = ReplaceSubstring(myFrame, "+", "<superscript>+</superscript>"); return myFrame; Quote Link to comment Share on other sites More sharing options...
step Posted August 15, 2016 Share Posted August 15, 2016 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: 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. Quote Link to comment Share on other sites More sharing options...
VernF88 Posted August 15, 2016 Share Posted August 15, 2016 Thank you so much! That works perfectly! Quote Link to comment Share on other sites More sharing options...
VernF88 Posted August 15, 2016 Share Posted August 15, 2016 (edited) 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")"? Edited August 15, 2016 by VernF88 Quote Link to comment Share on other sites More sharing options...
step Posted August 15, 2016 Share Posted August 15, 2016 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; Quote Link to comment Share on other sites More sharing options...
VernF88 Posted August 15, 2016 Share Posted August 15, 2016 (edited) 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: 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? Edited August 15, 2016 by VernF88 Quote Link to comment Share on other sites More sharing options...
VernF88 Posted August 15, 2016 Share Posted August 15, 2016 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. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 16, 2016 Share Posted August 16, 2016 You could try putting this in your OnRecordStart rule: 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: var frame = FindTextFrame('FullBody'); frame.content = frame.content.replace(/([\^\+]+)/g, '<superscript>$1</superscript>'); Also, why are you doing this? .replace(/<variable name="([^"]*)">/g, function(s,p) { return FieldOrRule(p); }) Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 16, 2016 Share Posted August 16, 2016 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. Quote Link to comment Share on other sites More sharing options...
VernF88 Posted August 16, 2016 Share Posted August 16, 2016 Or you could just do this: var frame = FindTextFrame('FullBody'); frame.content = frame.content.replace(/([\^\+]+)/g, '<superscript>$1</superscript>'); Also, why are you doing this? Hello Dan, Currently we've been attempting this: 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 rub is that the field's aren't filling because of the "<<>>" on each side of the space holder. Also the alt characters "†" and "‡" aren't being replaced with superscript. Quote Link to comment Share on other sites More sharing options...
step Posted August 16, 2016 Share Posted August 16, 2016 Also, why are you doing this? I converted the '<variable name="...">' tags to the actual strings that they're supposed to return before replacing the symbols in case a field or rule being returned in the text frame contains one of the symbols. Quote Link to comment Share on other sites More sharing options...
step Posted August 16, 2016 Share Posted August 16, 2016 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. Maybe you could post the template and data that you're working with so that we could take a closer look? My guess is that your template is converting those special characters to their HTML entities. Meaning the < is converted to < and the > is converted to >. So your find pattern is unable to come up with a match. I imagine the same is true for the daggers. If that assumption is true, this will probably work for you: var chars = { // Find: Replace: '\\^': '<superscript>^</superscript>', '\\+': '<superscript>+</superscript>', '[color="red"]†[/color]': '<superscript>†</superscript>', '[color="Red"]‡[/color]': '<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); }) [color="red"] .replace(/&([lg])t;/g, function(s,p) { return p == 'l' ? '<' : '>'; });[/color] for (var i in chars) text = text.replace(new RegExp(i, 'g'), chars[i]); FindTextFrame('FullBody').content = text; Quote Link to comment Share on other sites More sharing options...
VernF88 Posted August 16, 2016 Share Posted August 16, 2016 That works great! Thank you again for all your help!!! Quote Link to comment Share on other sites More sharing options...
VernF88 Posted August 16, 2016 Share Posted August 16, 2016 The only other thing I'm struggling on with this is trying to get something like this to work: '<<actual>>++': Rule("ActualR1"), '<<actual>>+': Rule("ActualR2"), '<<actual>>†': Rule("ActualR3"), '<<actual>>‡': Rule("ActualR4"), The reason being is the "actual" field in the letter is 36 point, so the superscript doesn't go up high enough. I made 4 rules applying each occurrence of the character options at the appropriate superscript height. It won't recognize this as text within the frame though. Thank You! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.