You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Joseph Balderson <ne...@joeflash.ca> on 2014/04/10 00:24:22 UTC

TLF and Regex Problem

Now before y'all lynch me for parsing XML with regex like Stackoverflow is want
to do, hear me out:

I'm trying to insert a link in TLF with a button like in a rich text editor.
Simple, right? Normally you would simply simply use

var linkElement:LinkElement = textArea.textFlow.interactionManager.applyLink( ... );

But no, that alone doesn't work: if your selection crosses format boundaries it
completely fails to assert the link formatting so you have no idea where the
link is that you've just created. Simply adding a LinkElement via addChild()
doesn't work either.

I've got a rudimentary version working for now which rips out the textFlow for
the selection with interactionManager.cutTextScrap(...), wraps that text in a
LinkElement and then "pastes" it back in with interactionManager.applyLink( ...
)...

But that only works so long as the link doesn't span across paragraphs and list
items. If it does, it completely and utterly crashes and burns: paragraph and
list structures collapse.

...so I've had to implement validation which disallows the user from creating
links spanning across different FlowElements (paragraphs or listitems). Which is
kludgy, and not very good UX.


So I have to create my own link insertion routine.

What I've resolved to do is to:

1) convert the textflow of the entire document to a string

2) find the start and end indexes of the selection within the textflow string

3) insert the following string at the start index:

</span><a href="[hrefVar]" target="[targetVar]"><span>

4) insert the following string at the end index:

</span></a><span>

5) reconvert the textflow string into a textflow object for the TextArea

And voila! Instant RTF link!

The only problem is... I have no idea how to write a regex parsing equation
which can find the start and ending indexes for a string match inside XML markup
where the result may be spread across several tags.

For instance, if the TextFlow is (abbreviated):

<TextFlow><p><span>Lorem Ip</span><span fontWeight="bold">sum do</span><span>
lor sit am</span><span fontStyle="italic">et, consectetur adipiscing elit.
</span></p></TextFlow>

And if, for instance, the user has selected "Ipsum dolor sit amet" to be
converted into a link. I need to find the first and last indexes of "Ipsum dolor
sit amet" within that RTF markup, and then insert the strings indicated in 3) &
4) above, so that the end result looks like this:

<TextFlow><p><span>Lorem </span><a href="http://www.google.ca" target="_blank">
<span>Ip</span><span fontWeight="bold">sum do</span><span>lor sit am</span>
<span fontStyle="italic">et</span></a><span>, consectetur adipiscing elit.
</span></p></TextFlow>

What I need is the regex to do step 2).

I know the regex to ignore tags and strip out the text between tags, and how to
find a string match of the selected text in the stripped textflow text... but
not how to find the match indexes within the original (unstripped) textflow string.

Anyone?



-- 
_______________________________________________________________________

Joseph Balderson, Flex & Flash Platform Developer :: http://joeflash.ca
Author, Professional Flex 3 :: http://tinyurl.com/proflex3book

RE: TLF and Regex Problem

Posted by Maurice Amsellem <ma...@systar.com>.
>Of course, we don't have the code for it, but I doubt if it has been hacked to work in this way.	

Someone (John Cunliffe) posted a link to the source of TLF demo on the other ML:

http://sourceforge.net/projects/tlf.adobe/files/3.0/current/samples.zip/download

and it's using applyLink().

HTH

Maurice 

-----Message d'origine-----
De : omuppi1@gmail.com [mailto:omuppi1@gmail.com] De la part de OmPrakash Muppirala
Envoyé : jeudi 10 avril 2014 00:39
À : users@flex.apache.org; news@joeflash.ca
Objet : Re: TLF and Regex Problem

I see what you are trying to do here.  My only problem with this approach is what if there are more than one occurrence of the exact words that the user has selected?  Even if the regex matches, you still need which one that the user meant to make a link.  Or do you handle this case and I don't get it?

BTW, the TLF demo app seems to have this use case working properly [1].
Have you tried that? Of course, we don't have the code for it, but I doubt if it has been hacked to work in this way.

Thanks,
Om

[1] http://www.adobe.com/devnet-apps/tlf/demo/


On Wed, Apr 9, 2014 at 3:24 PM, Joseph Balderson <ne...@joeflash.ca> wrote:

> Now before y'all lynch me for parsing XML with regex like 
> Stackoverflow is want to do, hear me out:
>
> I'm trying to insert a link in TLF with a button like in a rich text 
> editor.
> Simple, right? Normally you would simply simply use
>
> var linkElement:LinkElement =
> textArea.textFlow.interactionManager.applyLink( ... );
>
> But no, that alone doesn't work: if your selection crosses format 
> boundaries it completely fails to assert the link formatting so you 
> have no idea where the link is that you've just created. Simply adding 
> a LinkElement via
> addChild()
> doesn't work either.
>
> I've got a rudimentary version working for now which rips out the 
> textFlow for the selection with interactionManager.cutTextScrap(...), 
> wraps that text in a LinkElement and then "pastes" it back in with 
> interactionManager.applyLink( ...
> )...
>
> But that only works so long as the link doesn't span across paragraphs 
> and list items. If it does, it completely and utterly crashes and 
> burns: paragraph and list structures collapse.
>
> ...so I've had to implement validation which disallows the user from 
> creating links spanning across different FlowElements (paragraphs or 
> listitems).
> Which is
> kludgy, and not very good UX.
>
>
> So I have to create my own link insertion routine.
>
> What I've resolved to do is to:
>
> 1) convert the textflow of the entire document to a string
>
> 2) find the start and end indexes of the selection within the textflow 
> string
>
> 3) insert the following string at the start index:
>
> </span><a href="[hrefVar]" target="[targetVar]"><span>
>
> 4) insert the following string at the end index:
>
> </span></a><span>
>
> 5) reconvert the textflow string into a textflow object for the 
> TextArea
>
> And voila! Instant RTF link!
>
> The only problem is... I have no idea how to write a regex parsing 
> equation which can find the start and ending indexes for a string 
> match inside XML markup where the result may be spread across several 
> tags.
>
> For instance, if the TextFlow is (abbreviated):
>
> <TextFlow><p><span>Lorem Ip</span><span fontWeight="bold">sum 
> do</span><span> lor sit am</span><span fontStyle="italic">et, 
> consectetur adipiscing elit.
> </span></p></TextFlow>
>
> And if, for instance, the user has selected "Ipsum dolor sit amet" to 
> be converted into a link. I need to find the first and last indexes of 
> "Ipsum dolor sit amet" within that RTF markup, and then insert the 
> strings indicated in
> 3) &
> 4) above, so that the end result looks like this:
>
> <TextFlow><p><span>Lorem </span><a href="http://www.google.ca"
> target="_blank">
> <span>Ip</span><span fontWeight="bold">sum do</span><span>lor sit 
> am</span> <span fontStyle="italic">et</span></a><span>, consectetur adipiscing elit.
> </span></p></TextFlow>
>
> What I need is the regex to do step 2).
>
> I know the regex to ignore tags and strip out the text between tags, 
> and how to find a string match of the selected text in the stripped 
> textflow text...
> but
> not how to find the match indexes within the original (unstripped) 
> textflow string.
>
> Anyone?
>
>
>
> --
> ______________________________________________________________________
> _
>
> Joseph Balderson, Flex & Flash Platform Developer :: 
> http://joeflash.ca Author, Professional Flex 3 :: 
> http://tinyurl.com/proflex3book
>

Re: TLF and Regex Problem

Posted by OmPrakash Muppirala <bi...@gmail.com>.
I see what you are trying to do here.  My only problem with this approach
is what if there are more than one occurrence of the exact words that the
user has selected?  Even if the regex matches, you still need which one
that the user meant to make a link.  Or do you handle this case and I don't
get it?

BTW, the TLF demo app seems to have this use case working properly [1].
Have you tried that? Of course, we don't have the code for it, but I doubt
if it has been hacked to work in this way.

Thanks,
Om

[1] http://www.adobe.com/devnet-apps/tlf/demo/


On Wed, Apr 9, 2014 at 3:24 PM, Joseph Balderson <ne...@joeflash.ca> wrote:

> Now before y'all lynch me for parsing XML with regex like Stackoverflow is
> want
> to do, hear me out:
>
> I'm trying to insert a link in TLF with a button like in a rich text
> editor.
> Simple, right? Normally you would simply simply use
>
> var linkElement:LinkElement =
> textArea.textFlow.interactionManager.applyLink( ... );
>
> But no, that alone doesn't work: if your selection crosses format
> boundaries it
> completely fails to assert the link formatting so you have no idea where
> the
> link is that you've just created. Simply adding a LinkElement via
> addChild()
> doesn't work either.
>
> I've got a rudimentary version working for now which rips out the textFlow
> for
> the selection with interactionManager.cutTextScrap(...), wraps that text
> in a
> LinkElement and then "pastes" it back in with
> interactionManager.applyLink( ...
> )...
>
> But that only works so long as the link doesn't span across paragraphs and
> list
> items. If it does, it completely and utterly crashes and burns: paragraph
> and
> list structures collapse.
>
> ...so I've had to implement validation which disallows the user from
> creating
> links spanning across different FlowElements (paragraphs or listitems).
> Which is
> kludgy, and not very good UX.
>
>
> So I have to create my own link insertion routine.
>
> What I've resolved to do is to:
>
> 1) convert the textflow of the entire document to a string
>
> 2) find the start and end indexes of the selection within the textflow
> string
>
> 3) insert the following string at the start index:
>
> </span><a href="[hrefVar]" target="[targetVar]"><span>
>
> 4) insert the following string at the end index:
>
> </span></a><span>
>
> 5) reconvert the textflow string into a textflow object for the TextArea
>
> And voila! Instant RTF link!
>
> The only problem is... I have no idea how to write a regex parsing equation
> which can find the start and ending indexes for a string match inside XML
> markup
> where the result may be spread across several tags.
>
> For instance, if the TextFlow is (abbreviated):
>
> <TextFlow><p><span>Lorem Ip</span><span fontWeight="bold">sum
> do</span><span>
> lor sit am</span><span fontStyle="italic">et, consectetur adipiscing elit.
> </span></p></TextFlow>
>
> And if, for instance, the user has selected "Ipsum dolor sit amet" to be
> converted into a link. I need to find the first and last indexes of "Ipsum
> dolor
> sit amet" within that RTF markup, and then insert the strings indicated in
> 3) &
> 4) above, so that the end result looks like this:
>
> <TextFlow><p><span>Lorem </span><a href="http://www.google.ca"
> target="_blank">
> <span>Ip</span><span fontWeight="bold">sum do</span><span>lor sit am</span>
> <span fontStyle="italic">et</span></a><span>, consectetur adipiscing elit.
> </span></p></TextFlow>
>
> What I need is the regex to do step 2).
>
> I know the regex to ignore tags and strip out the text between tags, and
> how to
> find a string match of the selected text in the stripped textflow text...
> but
> not how to find the match indexes within the original (unstripped)
> textflow string.
>
> Anyone?
>
>
>
> --
> _______________________________________________________________________
>
> Joseph Balderson, Flex & Flash Platform Developer :: http://joeflash.ca
> Author, Professional Flex 3 :: http://tinyurl.com/proflex3book
>