Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
put replaceText(tFairy,"[\r\n]+(?=(?:[^<]+|<(?!/?p\b))*</p>)"," ") into tFairy
But it does not work! I think it "regex" and not "PCRE" although I would not say nonsense!
Can you help me?
Thank you so much for the support given to us beginners! Never lose patience with our stupid demands!
We are learning! Sooner or later we will learn! And when we are good we will help beginners, based on your generosity and your example!
Thank you all!
Mariasole
(=^..^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator
Hi Craig!
I wish it were that simple!
Unfortunately my stories are in HTML, and to me it is mainly that between <p> and </p> tags the returns are replaced with a space. Other tags must remain intact with their respective return!
Thank you for your reply!
Mariasole
(=^..^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator
on mouseUp
put fld "IN" into txt
set linedel to "<p>"
set itemdel to "</p>"
repeat with i=2 to the num of lines of txt
replace cr with space in item 1 of line i of txt
end repeat
put txt into fld "OUT"
end mouseUp
Last edited by [-hh] on Thu Jul 07, 2016 4:59 pm, edited 1 time in total.
on mouseUp
put fld "IN" into txt
replace "<p>" with numToChar(1) in txt
replace "</p>" with numToChar(2) in txt
set linedel to numToChar(1)
set itemdel to numToChar(2)
repeat with i=2 to the num of lines of txt
replace cr with space in item 1 of line i of txt --> see ***
end repeat
replace numToChar(1) with "<p>" in txt
replace numToChar(2) with "</p>" in txt
put txt into fld "OUT"
end mouseUp
<span>this is a span tag</span>
<span>this is another span tag</span>
<p>All work and
no play
makes Jack a
dull boy
All work and no play makes
Jack a dull boy
All work and no play makes
Jack a dull boy
</p>
<span>this is the end span tag</span>
<span>this is a span tag</span> <span>this is another span tag</span> <p>All work and no play makes Jack a dull boy All work and no play makes Jack a dull boy All work and no play makes Jack a dull boy </p>
<span>this is the end span tag</span>
<span>this is a span tag</span>
<span>this is another span tag</span>
<p>All work and no play makes Jack a dull boy All work and no play makes Jack a dull boy All work and no play makes Jack a dull boy </p>
<span>this is the end span tag</span>
Second problem:When html lines are many, the system is very slow ...
So, probably, the solution with regex might be the best, just that I have no idea how to spell !!!
put replaceText(tFairy,"[\r\n]+(?=(?:[^<]+|<(?!/?p\b))*</p>)"," ") into tFairy
????????????
I put an X on the window and turned on the light, let's see if PERLman will find a solution ...
Mariasole,
this was a beginners error (sorry, corrected above):
Of course the repeat should start with i=2, because the first "<p>"-line is *before* the first "<p>".
Hope it works now as you wish.
Here is moreover a faster solution if your input is large, use with LC 6.
Needs here (2.5 GHz Mac mini) < 500 ms for 2 MByte of input.
--- For LC 6 (easier but slower with LC 7/8)
on mouseUp
lock screen; lock messages
put the millisecs into m1
put fld "IN" into txt; put the num of lines of txt into n1
put numToChar(1) into c1
put numToChar(2) into c2
replace "<p>" with c1 in txt
replace "</p>" with c2 in txt
set linedel to c1; set itemdel to c2
put line 1 of txt into txt2 --> we start AFTER first "<p>"
repeat for each line L in (line 2 to -1 of txt)
replace cr with space in item 1 of L
replace c2 with "</p>" in L
put "<p>" & L after txt2
end repeat
put txt2 into fld "OUT"
set linedel to cr
put length(txt2) & " / replaced " & (n1-the num of lines of txt2) & \
" / " & (the millisecs - m1) & " ms" into fld "timing"
unlock screen; unlock messages
end mouseUp
FourthWorld wrote:The presence or absence of white space between HTML tags does not affect how it renders. What is the goal of this exercise?
Hi Richard!
It is not a Feng Shui test code , but rather for the readability of the code. I know it sounds strange, but for my "biggest experiment" , that of fables that I mentioned a while ago, I want to keep the readability of sources in html!
Grazie!
!(=^..^=)!
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator
Grazie [-hh]! the new code works perfectly and is very fast! I do not understand the differences with LC7 and LC8 , but maybe I will understand when I pass to new versions.
For now 6.x is hard enough for me! Thank you so very much for giving me the solution, and for showing me the very elegant code that I can study and imitate!
I will continue to test the code, and if you had something wrong I'll let you know.
Thanks again!
Mariasole
(=^..^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator