Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Is it possible to Textile a custom field using a MySQL update query?
I have a custom field containing raw input that I currently parse with Textile using upm_textile. I need to merge this data into another field that contains content that’s already formatted in XHTML. Is there any way to parse the custom field content with Textile using a MySQL query? Is there a simple script I can run to do the same?
Thank you!
Offline
Re: Is it possible to Textile a custom field using a MySQL update query?
What do you mean by “merge”? Do you mean just concatenate the data in two custom fields, one of which needs to be parsed with Textile?
Offline
Re: Is it possible to Textile a custom field using a MySQL update query?
@aslsw66: Yes.
I decided I don’t need the complex punctuation processing rules, and that the main thing I needed was converting double linebreaks into paragraphs, and single linebreaks into br
elements. Converting the double linebreaks was a snap using MySQL’s REPLACE()
and CONCAT()
syntax:
update textpattern
set custom_X = replace(custom_X, '
', '</p>\n<p>');
update textpattern
set custom_X = concat('<p>', custom_X);
update textpattern
set custom_X = concat(custom_X, '</p>');
What I can’t figure out is how to replace the regular linebreaks into <br/>
elements without add <br/>
elements to every linebreak in the code.
Luckily, only thirteen articles are affected, so if it comes down to brute force, I can manually edit the field. But if there’s a query I can run instead, that would be great!
Offline
Re: Is it possible to Textile a custom field using a MySQL update query?
Not sure what you’re trying to achieve between the two fields, but my preference is always to use built-in tags and plugins first rather than coding by hand – it makes it easier to maintain in the long run.
Using both Textpattern tags and rah_replace
and/or pax_grep
, you should be able to pretty easily taking the existing contents of a custom field and do something cool with it.
Offline
Re: Is it possible to Textile a custom field using a MySQL update query?
Thanks, Anura. I actually use pax_grep on every site I build, and I’m pretty familiar with rah_replace too, but they won’t help me do what I need to do here.
I solved the remaining problem in my last post by first replacing >\n<
with ><
to get rid of all the HTML linebreaks, then replacing \n
with <br />\n
, then restoring the original HTML linebreaks by reversing the first REPLACE()
query.
The reason I couldn’t do this with a plugin is that the website’s data model changed: we realized that the data we were putting in custom_6 needed to be part of the article’s body. Since this site uses hak_tinymce, the body and body_html fields need to be identical and both contain formatted input.
Offline