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: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Why does matchChunk not see HTML tags?

Post by kaveh1000 »

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: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Why does matchChunk not see HTML tags?

Post by bogs »

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...
html and htmlText...
html and htmlText...
Image
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: Why does matchChunk not see HTML tags?

Post by kaveh1000 »

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: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Why does matchChunk not see HTML tags?

Post by dunbarx »

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: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Why does matchChunk not see HTML tags?

Post by bogs »

I could be wrong, its been known to happen :D
Image
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: Why does matchChunk not see HTML tags?

Post by kaveh1000 »

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: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Why does matchChunk not see HTML tags?

Post by dunbarx »

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: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: Why does matchChunk not see HTML tags?

Post by kaveh1000 »

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: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Why does matchChunk not see HTML tags?

Post by dunbarx »

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