Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2004-04-28 10:53:20
- djfoobarmatt
- New Member

- Registered: 2004-04-28
- Posts: 6
reverse textile
I’m planning to use textile and texpattern as part of a larger system but would need to be able to import textpattern articles from an external document. The way i thought i’d do it was to convert the doc to xhtml and then do a ‘reverse textile’ conversion if that’s a plausible idea. I can’t find any php that does this so i assume it’s a oneway process textile->xhtml at the moment.
matt
Offline
Re: reverse textile
I’m doing the same. Here’s my process.
1. copy article body out of old xhtml page
2. replace all: <code><p></code>, <code><br /></code> with nothing
3. replace all: heading tags and blockquotes with hn and bq
4. replace all: <code>< p class=”</code> with p(
5. replace all stylized quotes with straight-ASCII ones
That’s pretty much all except in a few special cases. With keyboard shortcuts, it goes pretty quick.
(edit: looks like formatting has changed, old tricks no longer work…)
Last edited by jdueck (2006-01-26 16:04:15)
Offline
#3 2004-05-05 12:22:37
- djfoobarmatt
- New Member

- Registered: 2004-04-28
- Posts: 6
Re: reverse textile
In case anyone is interested, code for this can be found here
patches and bug reports welcome.
matt
Last edited by djfoobarmatt (2004-05-05 12:23:21)
Offline
#4 2004-05-05 12:47:02
- djfoobarmatt
- New Member

- Registered: 2004-04-28
- Posts: 6
Re: reverse textile
Of course i’ve only just realised that most of it is not needed since textile let’s you put xhtml inline and it works ok. Perhaps I can cut out most of it and pass though the tags instead of trying to convert them all back.
matt
Offline
#5 2004-05-18 03:52:30
- djfoobarmatt
- New Member

- Registered: 2004-04-28
- Posts: 6
Re: reverse textile
if i do <code><i>italics</i></code> it works – <i>italics</i>
matt
Last edited by djfoobarmatt (2004-05-18 04:00:56)
Offline
#6 2004-06-02 10:11:03
- djfoobarmatt
- New Member

- Registered: 2004-04-28
- Posts: 6
Offline
Re: reverse textile
Anyone still have this script kicking around… I have a tonne of hand coded pages that I refuse to move into txp simply becuase I don’t want to re-write them using textile
Proud Canadian. Toronto Locksmith , Actualize Consulting
Offline
#8 2004-12-22 11:11:58
- djfoobarmatt
- New Member

- Registered: 2004-04-28
- Posts: 6
Re: reverse textile
http://www.matthewsmith.id.au/textpattern/classReverseTextile.phps link
http://www.matthewsmith.id.au/textpattern/demo.phps link
http://www.matthewsmith.id.au/textpattern/demo.php link
It’s not very forgiving because it parses as XML. For real HTML needs a bit of html tidy support as well. Apparently it’s possible to get html tidy working in PHP. I find it’s usable on small pages.
Last edited by djfoobarmatt (2004-12-22 11:17:34)
Offline
Re: reverse textile
I’ve been playing with this today and foudn the following problems:
I needed to just convert some HTML (not an entire webpage) but by missing out the html and body tags this code produced an error – due to its strict XML handling.
My solution:
- add html and body (starting and end tags to my HTML)
- perform the reverseTextile function
- remove the html and body (starting and end tags)
the code:
<p><code>$html = ‘<html><body>’.$text.’</body></html>’;
$rt = new ReverseTextile;
$text = $rt->ReverseTextileThis($html);
$text = preg_replace(‘|<html><body>|’, ‘’,$text);
$text = preg_replace(‘|</body</html>|’, ‘’,$text);
</code></p>
The preg_replace’s could be streamlined. I am not the best programmer but the thought is there!
Problems:
the code doesn’t work too hot with lists. And doesn’t add the space after the # or * thus negating their use to Textile. The code also doesn’t seem to add a carriage return after a list item has been converted to textile.
Last edited by doubleonegative (2005-08-22 11:55:05)
Offline
Re: reverse textile
This would be an interesting feature for Textpattern’s importing code. I have a ton of posts on my Blogger site that have embedded HTML. Fixing 2200 entries by hand is going to get old pretty quick…
[Lee]
Monkeys could have written a better post..
Offline
Re: reverse textile
Is there still anybody working on this? I would love to have the possibility to convert HTML to Textile…
Offline
Re: reverse textile
I ran into an instance where something like this would be helpful. Anyone know of anything happening?
Edit:
I messed around with it for a bit and found that you don’t need to remove the html and body tags after having a string converted — reverseTextile should take care of that for you. Concerning the truncation that was taking place I think that reverseTextile is looking for the first tag it finds after <html><body> and doesn’t begin “reversing” until then. I just need to use this for snippets rather than entire pages so I added the <html><body> tags that doubleonegative mentioned and then a <p>. So my string to convert code looks like: $string = '<html><body><p>'.$string.'</p></body></html>';.
Also, doubleonegative mentioned that reverseTextile wasn’t adding the spaces after * and # in list items. You can fix this by adding a space after them in the code at lines 279 and 287.
I’m still curious to see if there are other ways of reversing Textile whether it be for snippets of code or for entire pages.
Last edited by jdykast (2006-08-19 03:24:10)
Offline
Pages: 1