Jump to content

Change color of Arrows only


gregmaze

Recommended Posts

Greetings all...

 

I am having a small problem with formatting arrows/bullets. I am trying to get a colored arrow preceding text within a line. When the customer adds text in Marcom Central text editor, the preceding symbol(arrow) is a different color than the text. After entering a return(Mac) key, adding additional lines, there should still be a colored symbol(arrow). I am attaching a screen shot to demonstrate what I am getting. The symbol shows up in the right place, but the color does not change. I am also attaching the code I am using...

 

 

this is the main code:

 

return Rule("Change detail font color").replace(/<p>/g, "<p> <span><f name =\"Arial Bold\"><color name='PANTONE 382 U'> ⇒    </span>");

 

"Change detail font color" rule:

 

if (Field("Kitchen Detail")!= "")

{

return '<span><f name =\"Arial Bold\"><color name="PANTONE 382 U"> ⇒     </span>' + Field("Kitchen Detail");

}

return "";

 

I would appreciate any assistance...

Thanks

Screen-Shot.jpg.bbcba4dc1de9bae88985e4a61ab176f6.jpg

Link to comment
Share on other sites

I think you could accomplish this without the "Change detail font color" rule you've made. Just change your main code to this:

var spanTag = '<span font="Arial Bold" color="PANTONE 382 U">⇒    </span>';
return Field("Kitchen Detail").split('<p>').filter(String).map(function(s){return spanTag + s;}).join('<p>');

 

Here's a break down of what's going on:

var spanTag = '<span font="Arial Bold" color="PANTONE 382 U">⇒    </span>';

That's your arrow wrapped in span tags. Note: I used the 'font' and 'color' properties of the span tag rather than 'color' and 'f' tags.

 

Field("Kitchen Detail").split('<p>')

Create an array of the "Kitchen Detail" field. Each paragraph is now an element of an array. I'm assuming that returns are translated into paragraph tags in MarcomCentral.

 

.filter(String)

Filter out empty array positions. This handles the "if Field("Kitchen Detail") != ''" you had in your "Change detail font color" rule. It will also prevent multiple line breaks.

 

.map(function(s){return spanTag + s;})

Map each element in the array (represented by the 's' variable) to be prepended by the 'spanTags' variable.

 

.join('<p>')

Converts the array back to a string and adds back the '<p>' tags.

Link to comment
Share on other sites

I think that the <p> tags that your rule is trying to replace, which are added by the editor in MarcomCentral, probably have attributes in them, so it's not quite as simple as replacing <p> tags whole. (If they're even <p> tags; they might be <para> tags.) But it's hard to know for sure without seeing the data file that MarcomCentral generates, which is why this is really a MarcomCentral-specific question, which should probably be asked on the MarcomCentral forum. You might want to add a line such as:

Print(Field("Kitchen Detail"));

to the OnRecordStart rule, and then look in the composition log (.msg) file, which you can usually access by replacing the ".pdf" in the URL to the output with ".msg" in the browser. Then we'll have a better idea of what the actual tags are that Marcom is generating, and what we need to replace.

 

That said, I would think that, instead of replacing <p> or <para> tags, you would simply want to replace instances of the arrows themselves, like so:

return Field("Kitchen Detail").replace(/(⇒)/g, "<span><f name =\"Arial Bold\"><color name='PANTONE 382 U'>$1</span>");

Link to comment
Share on other sites

Hello Ste and Dan,

 

Thank you for these great responses... Your responses have given me some great ideas to try to wrap my head around. I did come up with another solution because of short time frame but I do want to try out these solutions... After reading Ste solution, I realized how extensive javascript can be.

 

Again thank you for your help

Link to comment
Share on other sites

  • 4 weeks later...

Good Morning Ste and Dan,

 

I just wanted to followup concerning this thread. The solution Ste first gave worked exactly as I wanted it to. This is a much better solution than I used. Thank you both for the solutions to try. I wanted to especially Thank both of you for actually breaking down what was/is going on in the scripts. That was very helpful in learning the code as opposed to just using it.

 

Again thank you very much and have a great day!!!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...