#1
|
|||
|
|||
![]()
Users input text into a variable data field. This data will include list items. Each new list row will be tagged with a "{" character. They will also have sublists that will be tagged with a "%" character. So for example: a user might type in some text that looks like this:
Code:
Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua Non odio euismod lacinia at quis risus. {Risus commodo viverra maecenas accumsan {lacus vel facilisis {consectetur adipiscing %elit sed do eiusmod tempor incididunt %ut labore et dolore magna aliqua on %odio euismod lacinia at quis risus. The resulting data should end up looking like this when the data is processed: Code:
Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua Non odio euismod lacinia at quis risus. •Risus commodo viverra maecenas accumsan • lacus vel facilisis • consectetur adipiscing ° elit sed do eiusmod tempor incididunt ° ut labore et dolore magna aliqua on ° odio euismod lacinia at quis risus. Using similar code as listed below, I am able to achieve the desired results. Code:
var str = Field("PARAGRAPH1"); //Bullet Lines str = str.replace(/({)([^{])/g,'<p override="true" hyphenate="false" tabstops="0;1250,Left,,;" lindent="2450"><t>• $2'); return str; Code:
Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua Non odio euismod lacinia at quis risus. 1. Risus commodo viverra maecenas accumsan 2. lacus vel facilisis 3. consectetur adipiscing a. elit sed do eiusmod tempor incididunt b. ut labore et dolore magna aliqua on c. odio euismod lacinia at quis risus. Any assistance with scripting this would be appreciated. Thanks! |
#2
|
||||
|
||||
![]()
You said that you got the desired results with "similar" code to what you listed. So my first task in answering the question is figuring out how to recreate something close to what you already had, which I did like this:
Code:
var text = ""; text += "Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor "; text += "incididunt ut labore et dolore magna aliqua Non odio euismod lacinia at quis risus. "; text += "{Risus commodo viverra maecenas accumsan "; text += "{lacus vel facilisis "; text += "{consectetur adipiscing "; text += "%elit sed do eiusmod tempor incididunt "; text += "%ut labore et dolore magna aliqua on "; text += "%odio euismod lacinia at quis risus."; //var str = Field("PARAGRAPH1"); var str = text; //Bullet Lines str = str.replace(/({)([^{])/g, '<p hyphenate="false" tabstops="0;R1250,Left,,;" lindent="2450"><t>• $2'); str = str.replace(/(%)([^%])/g, '<p hyphenate="false" tabstops="0;R1250,Left,,;" lindent="2450"><t><t>• $2'); return str; The first step in making this work the way you want is to change the second parameter of each String.replace call to be a function (changing this code after the "Bullet Lines" comment): Code:
str = str.replace(/({)([^{])/g, function(m, p1, p2) { return '<p hyphenate="false" tabstops="0;R1250,Left,,;" lindent="2450"><t>• ' + p2; } ); str = str.replace(/(%)([^%])/g, function(m, p1, p2) { return '<p hyphenate="false" tabstops="0;R1250,Left,,;" lindent="2450"><t><t>• ' + p2; } ); return str; Code:
var startNum1 = 1; var startNum2 = 1; str = str.replace(/({)([^{])/g, function(m, p1, p2) { return '<p hyphenate="false" tabstops="0;R1250,Left,,;" lindent="2450"><t>' + (startNum1++) + '. ' + p2; } ); str = str.replace(/(%)([^%])/g, function(m, p1, p2) { return '<p hyphenate="false" tabstops="0;R1250,Left,,;" lindent="2450"><t><t>' + Chr(Asc('a') - 1 + startNum2++) + '. ' + p2; } ); return str; Now, this isn't a completely robust solution, and there are some issues. For one thing, it won't work right if you have multiple sections with the first-level indent, each of which has a list of the second-level indents below it, such as: Code:
var text = ""; text += "Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor "; text += "incididunt ut labore et dolore magna aliqua Non odio euismod lacinia at quis risus. "; text += "{Risus commodo viverra maecenas accumsan "; text += "{lacus vel facilisis "; text += "{consectetur adipiscing "; text += "%elit sed do eiusmod tempor incididunt "; text += "%ut labore et dolore magna aliqua on "; text += "%odio euismod lacinia at quis risus."; text += "{second list: "; text += "%bread "; text += "%milk "; text += "%eggs.";
__________________
Dan Korn FusionPro Developer / JavaScript Guru / Forum Moderator PTI Marketing Technologies | Printable | MarcomCentral 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)}); ![]() |
#3
|
|||
|
|||
![]()
Dan,
Thank you very much. Worked perfectly. I was on the right track with function calls however I did not think to place the function where you did right in the same "str.replace" line. There will be an overview for users on usage which will hopefully prevent the repeating of lists issue. If it becomes a necessity, I believe I could resolve the problem simply by using another character (such as a "}") for the new list. I added the ability to choose either Bullets, Numbers/Letters or Roman Numerals. All three choices work great with the help of your code. I have included my entire code below for the benefit of this community. Please note that the triple-x letters within the roman numeral variables are automatically being switched by this forum to asterisk symbols. Must be something related to "adult" content. haha! Thanks again! Code:
var str = Field("PARAGRAPH1"); // Number and Letter list type variables var startNum1 = 1; var startNum2 = 1; // roman numeral variables var numeralCodesUP = [["","I","II","III","IV","V","VI","VII","VIII","IX"], // Ones ["","X","XX","***", "XL", "L", "LX", "LXX", "L***", "XC"], // Tens ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"]]; // Hundreds var numeralCodesDN = [["","i","ii","iii","iv","v","vi","vii","viii","ix"], // Ones ["","x","xx","***", "xl", "l", "lx", "lxx", "l***", "xc"], // Tens ["","c","cc","ccc","cd","d","dc","dcc","dccc","cm"]]; // Hundreds // Switch based on chosen list type switch(Field("LISTTYPE")){ case "BULLET": // Bullet Lines - Use { to denote start str = str.replace(/({)([^{])/g,'<p hyphenate="false" tabstops="0;1250,Left,,;2450,Left,,;" lindent="2450"><t>•<t>$2'); // Circle Lines - Use % to denote start str = str.replace(/(%)([^%])/g,'<p hyphenate="false" tabstops="0;3400,Left,,;4700,Left,,;" lindent="4700" suboffset="32" subratio="100"><t><subscript>○</subscript><t>$2'); break; case "NUMBERS": // Numbers Lines - Use { to denote start str = str.replace(/({)([^{])/g,function(m, p1, p2){return '<p hyphenate="false" tabstops="0;1250,Left,,;3700,Left,,;" lindent="3700"><t>' + (startNum1++) + '.<t>' + p2;}); //Letter Lines - Use % to denote start str = str.replace(/(%)([^%])/g,function(m, p1, p2){return '<p tabstops="0;4400,Left,,;6500,Left,,;" lindent="6500"><t>' + Chr(Asc('a') - 1 + startNum2++) + '.<t>' + p2;}); break; case "ROMAN": // Upper Roman Lines - Use { to denote start str = str.replace(/({)([^{])/g,function(m, p1, p2){return '<p hyphenate="false" tabstops="0;1250,Left,,;3700,Left,,;" lindent="3700"><t>' + (convert(startNum1++,1)) + '.<t>' + p2;}); //Lower Roman Lines - Use % to denote start str = str.replace(/(%)([^%])/g,function(m, p1, p2){return '<p tabstops="0;4400,Left,,;6500,Left,,;" lindent="6500"><t>' + (convert(startNum2++,2)) + '.<t>' + p2;}); break; } //regular Paragraph - Use # to denote start str = str.replace(/(#)([^#])/g,'<br><br><p tabstops="0;0,Left,,;" lindent="0" rindent="0">$2'); // Function to convert to roman numerals function convert(num,x) { var numeral = ""; var digits = num.toString().split('').reverse(); for (var i=0; i < digits.length; i++){ if(x==1){numeral = numeralCodesUP[i][parseInt(digits[i])] + numeral;} else{numeral = numeralCodesDN[i][parseInt(digits[i])] + numeral;} } return numeral; } return str; |
![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|