Jump to content

Formatting text based on special characters


Recommended Posts

i am building a printOne web template.


i want to offer one large, multi-line text box which will allow the user to enter something like this:




notice the following:

the "time" is always 38 point bold.

the "description" that appears below it is always 36 point.

the "text" is always three columns, and always 22 point.


how do i allow the user to determine the font name and size?


i don't think printable's on-line rich-text editor allows this much flexibility, so here's what i was thinking ...


IF the user types a pound sign (#), followed by the actual text ...

whatever he/she types on that line will appear in 38 point bold text.


IF the user types a dollar sign ($), followed by the actual text ...

whatever he/she types on that line will appear in 36 point text.


IF the user types a plus sign (+), followed by the actual text ...

whatever he/she types on that line will be preceded with a bullet character, and will appear in 22 point text.


so, in the multi-line text box, the user would type something like this:


#8:00–9:00 a.m.

$Here is a description of what happens between 8 and 9:

+text a text g text m

+text b text h text n

+text c text i text o

+text d text j text p

+text e text k text q

+text f text l text r


Can you help me write a rule which will do this?

(replace "#" with "<font size=36 ...>", etc)


Also, how would I address the three columns of bulleted text?

Link to comment
Share on other sites

I started playing with the logic for setting something up for your example, but don't have the time to totally flesh out a solution. I'm including my commented code below for you to possibly build upon.


Personally, I think it would be easier to provide separate text fields for user input to pre-separate values rather than trying to force the user to input text via some wiki-like formatting system. It would also help simplify the back-end code.


I'm also uncertain how allowing the end user to pick a custom font would affect output since each font comes with it's own spacing issues. At the very least, I would allow only a set number of font choices, perhaps in a dropdown list.


// input bulleted items as single entries (+textA \n +textB \n +textC \n...)
// rather than 3-item lines (+textA textG textM \n...)

// create array of input text splitting on new lines (or line breaks "<br>")
var input = Field("inputText").split("\n");

// split previous array into separate arrays for each entry type
var timeEntry = [];
var descriptionEntry = [];
var bulletEntry = [];
for (i=0; i<input.length; i++) {
if (Left(input[i],1) == "#") { 
} else if (Left(input[i],1) == "$") {
} else if (Left(input[i],1) == "+") {
	if (input[i+1] == "") {
	} else {
} else return FusionPro.ReportWarning("text input is not formatted correctly");

// Join bulletArray into one string and then split twice to create new array:
// * once by "%NEW%" to have separate value for each section
// * split those values into a sub-array by "+" for each bullet

// set static font names as they would appear in FP text editor
// if you plan to let end-user choose one of several fonts,
// you will have to generate FP font name based on contents of field
// perhaps via a function using a switch statement?
var TimeFont = ;
var DescriptionFont = ; 
var TextFont = ;

// generate table structure and populate cells with data from
// previous arrays
var timeTag = "<font size=\"38\" name=\"" + TimeFont + "\">";
var descriptionTag = "<font size=\"36\" name=\"" + DescriptionFont + "\">";
var textTag = "<font size=\"22\" name=\"" + TextFont + "\">";

Set up embedded loops to cycle through each array's data as table tags are
var table = "<table>\n";
table += ; //...

// make sure tagged text option is checked
return table;

Link to comment
Share on other sites

the user can potentially add any number of headlines (8:00-9:00 am), any number of sub-headlines (Here is a description...) and any number of body text lines.


in order to accommodate that i would have to have a potentially large number of text boxes.


so i thought it would be best to just give the user one big text box and let them enter whatever they want, and control the formatting by using special characters.


i'm not sure this is the way to go and i wish printable would one day expand the capabilities of their on-line rich text editor.


in the meantime i have a huge project that requires this functionality.


thanks for your help.

i'll try it now and post the results...

Link to comment
Share on other sites

  • 11 months later...

Most of the templates I create would benefit from expanded functionality in the rich text editor due to the exact same reason: to create flexibility. The ability to have drop down styles to apply to text in the rich text editor would solve so many issues. I would want to have control over the styles and then let the end user of the template apply them to their text at will.


I do not know how many times someone will want to use certain styles (in EricC's case: Time, Description, and Text), so I want them to be able to select the text and apply that style instead of filling out an entry box. I would have to otherwise create a template with a silly number of entry fields which they would then have to fill out in order to make it output they way they want. That is a completely unrealistic solution.


While I'm at it, adding in bullets would be a bonus. I find it funny that the WYSYWYG editor of this forum has it (including other features such as indent and numbered list) but the templates do not.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...