Naval Posted February 8, 2017 Share Posted February 8, 2017 Hi guys, Can anyone tell me if i can format 1 text field like with first like being a bold font for headline and the rest being regular font for the paragraph or even have a hard return on the first line so that the first line of text is spaced from the body text. Hope this makes sense. I am new to fusionpro so sorry if this can be achieved fairly easily, learning javascript as i go. Looking forward for your help Thanks in advanced. Naval FusionPro version 9.2 Quote Link to comment Share on other sites More sharing options...
step Posted February 8, 2017 Share Posted February 8, 2017 Is your first line and body text all part of the same text field? If so, you might try something like this: var paragraph = 'This is the first line. This is the second line'; // Or Field("YOUR PARAGRAPH FIELD"); var boldFont = '75 Helvetica Bold'; return paragraph.replace(/^([^\.\?!]+.)/, '<span font="' + boldFont + '">$1</span><br>'); The code uses a Regular Expression to capture (from the beginning of a string) one or more characters that aren't an exclamation mark (!), period (.), or question mark (?) and then captures the next character – which should be the punctuation. Then it replaces that captured string with the string that was captured wrapped in a span tag to assign the bold font followed by a break tag. Quote Link to comment Share on other sites More sharing options...
Naval Posted February 28, 2017 Author Share Posted February 28, 2017 Hi Thanks for that. I have attached a zip file would you be kind enough to see where i am going wrong. I have also attached the Capture.JPG for a clear understanding of the formating i am trying to achieve. I know i have the rule done wrong as it is giving me error. So essentially there is one text field where the first line (Header / Title) will be formatted in UPPERCASE characters and second line (Content) will be in sentence case or normal. These will all be user input fields. There is no set values for these fields. Customer types in the these variables. I know i initially asked for bold font but the customers changed their mind as they do. Can you please help me out here as i am fairly new to javascript. Thanks for your help and sorry to be a bother. Looking forward to hear from you NavalParagraph Formatting.zip Quote Link to comment Share on other sites More sharing options...
step Posted February 28, 2017 Share Posted February 28, 2017 Hi Thanks for that. I have attached a zip file would you be kind enough to see where i am going wrong. I have also attached the Capture.JPG for a clear understanding of the formating i am trying to achieve. I know i have the rule done wrong as it is giving me error. What error are you getting? From the looks of the file you attached, it appears you just copied the rule I posted without swapping out the static string with your field name. For the record, what front end are you using? MarcomCentral? If so, you might considering asking this question in the MarcomCentral forum. I am not able to get your template to work with the data you supplied but I'm assuming that's because I don't have a MarcomCentral license so it isn't honoring the field list specified in your XML file. So essentially there is one text field where the first line (Header / Title) will be formatted in UPPERCASE characters and second line (Content) will be in sentence case or normal. These will all be user input fields. There is no set values for these fields. Customer types in the these variables. Okay, that's a little confusing. You say that there is "essentially one text field" but then you reference multiple fields when you say "these will all be user input fields." What do you mean by "essentially one text field"? Is it one field or multiple? I know i initially asked for bold font but the customers changed their mind as they do. Can you please help me out here as i am fairly new to javascript. Assuming you mean they now want the first sentence in uppercase, that's a simple enough change: var paragraph = 'This is the first line. This is the second line'; // Or Field("YOUR PARAGRAPH FIELD"); return paragraph.replace(/^([^\.\?!]+.)\s*/, function(s,p) { return ToUpper(p) + '<br>'; }); 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.