ElkArte Community

Title: Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed)
Post by: emanuele on June 02, 2014, 03:33:34 pm
Copy&paste of formatted text using Chrome (at least, maybe others as well) leads to strange effects, like for example:
Code: [Select]
[font=proxima-nova, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif]credits_intro[/font]
I was thinking to add a new entry to $mistake_fixes array in preparsecode that looks like:
Code: [Select]
				'~\[font=([^\[])+?,[^\[]*]~' => '[font=$1]',
Being a regexp and being in a pretty nasty position I'd like to have some feedback on that.
If I'm not mistaken, it should grab anything up to the first comma (if any) and use it as font.

Do you see any problem with it?
Title: Re: Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed)
Post by: Spuds on June 02, 2014, 09:25:39 pm
I think that may only capture the last character up to the first , so that may return
Code: [Select]
[font=a]
?  Not sure.  Also you may wan to look for the ending font tag to be more restrictive.

Perhaps (untested of course)
Code: [Select]
\[font=(?<=\=)(.*?)(?=\,).*\](.*?(?:\[/font\]))

find [font
find =
find and capture anything at that point, that is between the = and a , (positive look behind and ahead, the look behind probably not needed since we have it in the previous test)
find (and ignore) anything after the above up to the first ]
find and capture anything after the above ] and ending with the end font tag


I hit preview on this and the link tree showed:

Title: Re: Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed)
Post by: emanuele on June 07, 2014, 09:07:44 am
Works fine for the one above!
I was wondering if it would be possible to make it work with:
Code: [Select]
[font='Segoe UI', proxima-nova, 'Helvetica Neue', Arial, sans-serif]credits_intro[/font]
as well (i.e. the first font with single quotes).

About the linktree, is probably related to http://www.elkarte.net/community/index.php?topic=519.0
Title: Re: Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed)
Post by: Spuds on June 07, 2014, 10:27:02 am
you mean don't capture the 's ?
Code: [Select]
\[font=(?<=\=)'?(.*?)'?(?=\,).*\](.*?(?:\[/font\]))

or since we don't need that look behind since we are taking the first one, this should work as well
Code: [Select]
\[font='?(.*?)'?(?=\,).*\](.*?(?:\[/font\]))

Quote from: emanuele – About the linktree, is probably related to http://www.elkarte.net/community/index.php?topic=519.0
Humm ... could be (yup thats it!)
Title: Re: Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed)
Post by: emanuele on June 07, 2014, 11:25:01 am
AHA!
With some more slashes works! :P
Title: Re: Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed)
Post by: emanuele on June 07, 2014, 11:44:14 am
Sent with even some tests.