debuggable

 
Contact Us
 

How To Transform HTML To Textile Markup - The CakePHP TextileHelper Revisited

Posted on 23/8/07 by Tim Koschützki

 
&nsbp;

You can skip to the end and add a comment.

[...] Koschuetzki has a new tutorial posted today for CakePHP users out there - it’s a method for transforming HTML content into [...]

Paul  said on Sep 12, 2007:

this works great. thank you thank you thank you for sharing!!! i was dreading the regular expressions.

Tim Koschuetzki said on Sep 13, 2007:

Np, Paul. :]

[...] You can read more here [...]

zollerwagner said on Mar 02, 2008:

This is a great help, Tim. Can you explain how you'd use this to convert an entire site?

Would you run it page by page, copying and pasting each page's HTML into a new PHP page based on this snippet:
detextile($htmlText);

?>

Or have you found a way to automate the process?

Tim Koschuetzki said on Mar 02, 2008:

So you have an entire arsenal of html pages that you want to textilize? Oh well that should be very easy to automate.

Depending on how your pages are represented (in the file system or in the dbd or wherever) you might use file_get_contents() or some database fetching. Invoke detextile() on the result and off you go. : )

You can use the glob() function or, what I prefer, the Folder class of CakePHP, to read all file names from a given folder (also recursively) and then use file_get_contents().

Or did you mean something else?

zollerwagner said on Mar 02, 2008:

Wow, that was a quick response! Thanks.

Yes, that does help.

(I'll try to post my code with broken tags and a bbcode-like container.)

To test, I'm trying to set up an HTML form into which I can past HTML to be converted. In the body I have this:

[code]
< form action="" method="post" id="detextile">

Original HTML

Conversion to Textile

[/code]

Then above the head I have this:

[code]
if (isset($_POST['htmlText']))

{

echo $textile->detextile($_POST['htmlText']);

}

[/code]

The script gets as far as the if then stops. What do I have to do differently to invoke your textile function? Man, I must be missing something really basic!

zollerwagner said on Mar 02, 2008:

Maybe I over did it. I'll submit the code again.

[code]<form action="" method="post" id="detextile">
Original HTML

Conversion to Textile

[/code]

The HTML form
[code]

if (isset($_POST['htmlText']))

{

echo $textile->detextile($_POST['htmlText']);

}

[/code]

zollerwagner said on Mar 02, 2008:

Darn. The HTML is still not showing. Feel free to delete that and I'll try again. I looks like youre running WP, so maybe will work.

<form action="" method="post" id="detextile">

the HTML
Original HTML

Conversion to Textile

Invoking your Textile function
if (isset($_POST['htmlText']))

{

echo $textile->detextile($_POST['htmlText']);

}

zollerwagner said on Mar 02, 2008:

Sorry about that. What's the trick for showing HTML?

Tim Koschuetzki said on Mar 03, 2008:

Yeah, html sowing is a little broken. Gotta fix that up. : )

So hrm, o you have a textarea that has the htmltext id or name? I don't see that in your form.. so the if cannot succeed.

Riyasha  said on Sep 16, 2008:

listing inside listing is not working..

# test
## item1

## item2

## item3

# test2

## new item

## new item1

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.