Jump to content

Module: Textile Text Formatter


ryan

Recommended Posts

Today I needed to install the latest Textile on an older site for a client, and figured I would go ahead and make a PW2 module out of it at the same time. Textile is the markdown language included with Textpattern CMS and apparently also used by Basecamp and Google+ to some extent. More information about Textile and syntax here: http://en.wikipedia....kup_language%29

Textile is very similar to Markdown (already included with PW), though now that I've spent some time with the syntax, I think I might like Textile a little more.

To Install
Download or clone from GitHub at: https://github.com/r...ormatterTextile

Place files in /site/modules/TextformatterTextile/. Go to Modules in the admin, 'Check for new modules' and click install for Textile under the Textformatter section.

You'll also see 'Textile Restricted' and that is a separate version of the module that may be used with untrusted input like user-supplied input or blog comments. The regular Textile should only be used with trusted input.

To use
Add this to any textarea (or text) field, and that field will interpret Textile codes and output XHTML markup on the front end of your site. Note that Textformatters appear on the 'Details' tab of the field editor when editing a text or textarea field. Use the regular 'Textile' unless the field in question may contain untrusted user input, in which case you should use 'Textile Restricted'.

Please note
Don't use this in combination with other text formatters like Markdown. Don't use with TinyMCE (there would be no point). This module may be used with any version of ProcessWire: 2.0, 2.1 or 2.2+.

Edited by netcarver
Updated github link to point to active repository.
  • Like 2
Link to comment
Share on other sites

Useful addition, not least of all just because Textile has a big following; I used Textpattern a fair bit at one point and still loosely involved in a project that runs 100+ copies of it... Wasn't sure why you'd want to use something like Textile when I first used it but warmed to it later and still use it to run a decent-sized ExpressionEngine site in which I used Textile for all the text boxes in the admin. Takes a little to bring a client up to speed but then much less likely for them to accidentally trash the site or produce HTML spaghetti than if using TinyMCE/CKEditor etc. also I think it's quite useful at times for a client to realise they're not just generating a word processing document but are creating web markup in the background; and by default Textile has some nice tweaks to text formatting like 'proper' quotes, em and en dashes etc. and, as you say, the syntax is quite good. On the other hand it is another proprietary markup language...

I think in a CMS admin it can sometimes also make more sense to clients since you're often re-using the same content in different contexts throughout a site and so 'WYSIWYG' is never really going to be a good analogy to try and fit since an individual chunk of content can look quite different in each context; in this respect I think Textpattern's more 'abstract' approach to content fields actually seems to fit well.

As an aside I noticed Textpattern seems to be enjoying a lot more activity of late and steadily moving towards their big new '5' release with a fully revised architecture after a couple of rocky years...

Link to comment
Share on other sites

Great points Martin. I think that lightweight markup languages (LML) like Textile and Markdown are in a lot of cases better with clients. The resulting markup is so much cleaner and maintains that integrity long term. And results in reduced support burden down the road. Plus, it gets the client into thinking in semantic terms rather than trying to "design" in the rich text editor. Still, everyone seems to want rich text editors these days, so I don't fight it. But if it were up to me, we'd all be using Markdown, Textile and the like. :) There is a ton of overhead that goes with TinyMCE and the like, and I'm not even talking about bandwidth and speed.

Link to comment
Share on other sites

Your implementation of TinyMCE is pretty ideal though, Ryan. Major props for that. I used to use WYSIWYG Pro and just let clients have the kitchen sink--embedded media, whatever. I found that it can result in a lot of wasted time during redesigns, so I headed toward Textile, but after trying PW's TinyMCE, I'm actually using TinyMCE as the main editor with some Textpattern sites I do. :D

Link to comment
Share on other sites

Thanks Ryan for the module. I already was wondereing what's about these textformaters, as I didn't really get into these until now , I know they exist but will maybe give it a try. I always thought they're too complicated and not intuitive for clients to use. But maybe I'm wrong. I would love to hear experiences from others using it.

I know it can make sense regarding the issues caused by wysiwygs. But if you know your way around in one of those you can pretty much configure it to your needs and restrict all things that could make troubles, but still it can be buggy in certain situations and inconstistent in different browsers. While a simple textarea you can't go wrong except not knowing how the markup tags work or make an error there, wouldn't it be possible or make sense to have a preview or a validator?

Link to comment
Share on other sites

Soma, I used markdown on a website, and the client loved it and got the hang of it very quickly.

I'm a Print Designer, and in the office I was even considering of making some kind of custom application with markup, so people could submit their tests to me instead of word or rtf documents. I tried to teach everyone to use styles in word, but people just seem to not understand the concept, and they ruin all the layout, and make it very tedious to correct everything... I agree with Martin, that it's good that editors are aware of the structure they are creating instead of relying on the visual thing.

edit 1: Maruchan, nice! I will bookmark that one :)

edit 2: For markdown there is this live preview http://softwaremaniacs.org/playground/showdown-highlight

Link to comment
Share on other sites

  • 3 weeks later...

The way Ryan has wrangled TinyMCE makes it easier to insert (and resize) images, link to other pages with your site. This is quite unintuitive with both Markdown and textile.

martkItUp!(http://markitup.jaysalvat.com/home/) might be nice to have when using textile and Markdown (especially when it comes to using custom styles), Ryan's implementation here wins me over.

Link to comment
Share on other sites

I'm, using the textile module on a site I'm building and there seems to be a bug when building tables.

When I do this:

| something here | something here |

| something here | something here |

| a line break

here | something here |

the line doesn't break. I looked for some reason, And apparently, people that had this problem solved it by adding a raw <br> (bah!), but even this doesn't work with me...

here everything works fine http://textile.thresholdstate.com/

Link to comment
Share on other sites

It's hard to say here. The one at thresholdstate.com is Textile 2.0 and we're using Textile 2.2 (a newer version). I don't know enough about Textile or it's code to be able to debug it very easily, so I think we should try to look at all other factors. Do you have any other text formatters applied to the field where textile is applied? Where did you read about others solving this problem with a <br>? It makes me wonder if this is some known issue with Textile. Also, can you post the full textile code that is failing? I'd like to try and duplicate it here.

Link to comment
Share on other sites

Ah... of course...

This was the code that was breaking it:

$(".menu td:first-child").text(function(n){
	var content = $(this).text();
	var dots = "...";
	var both = content + dots;
   	return both;
 });

EDIT: Ok, I manage a workaround, although it will mean a bit more complexity to the editor.

| _something here_ | something here |
| _something here_ | something here |
| _a line break 
here_ | something here |

$(".menu td em").append('...');

td em { font-style:normal }
Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...

Keithar, that looks like the output of the Markdown module rather than the Textile module. Can you double check that you are using Textile (only) in that field and not Markdown? I just tried it here with TextformatterTextile and this is the output I got:

<ul>
<li><em>name</em> <strong>price</strong></li>
</ul>

Please let me know what you find.

Link to comment
Share on other sites

I've just implemented a few changes/additions to this module:

To upgrade, replace your files in /site/modules/TextformatterTextile/ with the files from the new version.

Link to comment
Share on other sites

Interesting, I now get exactly the same thing as you with the Textile 2.3 update (same result in both Textile and Textile Restricted). I take it that everything here is correct except for the *cena* not being translated to <strong>cena</strong>. So I just tried this (taking ProcessWire out of the picture):

test.php

<?php
require("classTextile.php");									  
$textile = new Textile();
echo $textile->TextileThis('* %test% *cena*');

Result:

<ul>
   <li><span>test</span> *cena*</li>
</ul>

Bug in Textile 2.3?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...