Skip to main content
Topic: Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed) (Read 2113 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed)

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?
Bugs creator.
Features destroyer.
Template killer.

Re: Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed)

Reply #1

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:

Last Edit: June 03, 2014, 04:37:22 pm by Spuds

Re: Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed)

Reply #2

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
Bugs creator.
Features destroyer.
Template killer.

Re: Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed)

Reply #3

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\]))

Humm ... could be (yup thats it!)

Re: Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed)

Reply #4

AHA!
With some more slashes works! :P
Bugs creator.
Features destroyer.
Template killer.

Re: Chrome (maybe other browsers) copy&paste in WYSIWYG (regexp master needed)

Reply #5

Sent with even some tests.
Bugs creator.
Features destroyer.
Template killer.