[wp-testers] Code Kvetching

Alexander Beutl xel at netgra.de
Tue May 6 15:58:55 GMT 2008


There shouldn't be any "shorthand"s for creating a specific look and 'code'
definitly is not one of those.
pre is a meaningless element but today the only way to be sure spaces are
kept like intended... Sure there are ways to get the same with CSS but since
you can not be sure a browser will respect css perfectly I'd prefere pre
anyway.

Whatever code and pre are ment to be - I fixed this one in my plugin and am
willing to update it this evening again... (Hopefully I will soon get my
plugin hosting activated at wordpress.org for automatic updates being
possible...)

Came to a great idea when I saw the plugin Text-Control[1] which will enable
you to change from wptexturize to some others or just use no formatting.

Now I will do the following:
stop wptexturize from working automatically
add my own function instead
split the content at
`[pre]...[/pre]`,`[code]...[/code]`,`<pre>...</pre>`,`<code>...</code>` [2]
so I get an array with
- normal text
- my shortcodes and whats inside them (including attributes of course!)
- normal pre and code tags
in the very same order it was inside the posts content.

I will then loop through the array and use wptexturize on each element which
doesn't start with `[cod`, `[pre`, `<cod` or `<pre`
Those which do start with that will be preserved from being formatted with
wptexurize.
then all of this snipplets will be put together again and be served to
wordpress for further processing.

I have to admit this plugin will not work together with Text-Control - but
as if your using Text Control allready you will be able to solve the problem
via disabling wptexturize for that post this is not such bad I hope.

[1] http://dev.wp-plugins.org/wiki/TextControl
[2] For all RegExp fanatics like myselfe:
preg_split(

"@(\[code[^]]*\].*\[/code\])|(\[pre[^]]*\].*\[/pre\])|(\<pre[^>]*>.*\</pre>)|(\<code[^>]*>.*\</code>)@isU",
            $content,
            -1,
            PREG_SPLIT_DELIM_CAPTURE
        );
You may as well tell me if there is a better regexp to fit my needs if you
know one - I'm still in the process of learning regexp and would be happy
for every advise.

- Alex


More information about the wp-testers mailing list