Why does matchChunk not see HTML tags?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Why does matchChunk not see HTML tags?

Post by kaveh1000 » Sun Dec 02, 2018 12:12 am

Consider the following code

Code: Select all

put "good morning" into fld 1
get matchChunk(fld 1, "(mor)", temp_start, temp_end)
put the htmlText of fld 1 into htmltemp 
get matchChunk(htmltemp, "(mor)", temp_start, temp_end)
temp_start and temp_end are 6 and 8 as expected, in the first case. But in the second case I expect them to be 9 and 11, because htmltemp should be

Code: Select all

<p>good morning</p>
Why is the <p> not taken into account?
Kaveh

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Why does matchChunk not see HTML tags?

Post by bogs » Sun Dec 02, 2018 12:58 am

put the htmlText of fld 1 into htmltemp
My guess would be because there is no <p> in htmlTemp.

For instance, the top field in this picture gets the raw text in a url, then puts the 'htmlText' of that into field 2. When you do that, all tags are stripped I think...
Extract HTML and Images_005.png
html and htmlText...
Image

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Why does matchChunk not see HTML tags?

Post by kaveh1000 » Sun Dec 02, 2018 1:05 am

But when I put

Code: Select all

put char 1 of htmltemp
before the last line, I get

Code: Select all

<
in the message box
Kaveh

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Why does matchChunk not see HTML tags?

Post by dunbarx » Sun Dec 02, 2018 1:05 am

Why the parentheses within the quoted literal?
get matchChunk(fld 1, "(mor)", temp_start, temp_end)
Didn't you mean:

Code: Select all

get matchChunk(fld 1, "mor", temp_start, temp_end)
Craig Newman

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Why does matchChunk not see HTML tags?

Post by bogs » Sun Dec 02, 2018 1:11 am

I could be wrong, its been known to happen :D
Image

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Why does matchChunk not see HTML tags?

Post by kaveh1000 » Sun Dec 02, 2018 1:58 am

No Craig. You need the brackets so matchChunk remembers what it found. Try each of these two lines in the Message box:

Code: Select all

get matchChunk("hello", "e", temp_start, temp_end); put temp_start

Code: Select all

get matchChunk("hello", "(e)", temp_start, temp_end); put temp_start
Only the second one gives you "2" correctly. ;-)
Kaveh

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Why does matchChunk not see HTML tags?

Post by dunbarx » Sun Dec 02, 2018 6:50 pm

Ah. I should read the dictionary more often.

But I do get both the "6,8" and "9,11" in your code snippet.

Craig

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Why does matchChunk not see HTML tags?

Post by kaveh1000 » Sun Dec 02, 2018 8:13 pm

Now I am getting them too. Have no idea what I did wrong!!! Anyway looks like happy ending.
Kaveh

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Why does matchChunk not see HTML tags?

Post by dunbarx » Sun Dec 02, 2018 8:40 pm

I am positive, starting with Hyoercard in 1987, that here and there a code run will fail, and then, without changing a thing, work just fine.

This is due either to gremlins or to problems in my brain. I do not believe it can be due to both.

Craig

Post Reply

Return to “Talking LiveCode”