Jump to content
ryan

Module: Textile Text Formatter

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

Share this post


Link to post
Share on other sites

Great job! I have never really used either of those (markdown or textile), but I was thinking about markdown on my discussions module. Now I have more options to choose from :)

Share this post


Link to post
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...

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

I like MarkItUp. Actually I used that in PW1 as an option in addition to TinyMCE. Would be good to bring back at some point.

Share this post


Link to post
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/

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

It's working now, even without raw tags. I redid everything and don't really know what fixed it. I will report if there is something else.

Share this post


Link to post
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 }

Share this post


Link to post
Share on other sites

Thanks Marc, I will plan to put in this update soon.

Share this post


Link to post
Share on other sites

Diogo, ProcessWire 1.x actually used MarkItUp and it's a great editor. I definitely want to get it going again in 2.x, hopefully soon unless someone beats me to it. :)

Share this post


Link to post
Share on other sites

Hey, thanks for this useful module. I found small problem on PW 2.2. This code:

* _name_ *price*

gives me

<li><em>name</em> <em>price</em></li>

Is this incopability problem with the new PW?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
* %test% *cena*

After update I get:

Textile

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

Textile Restricted

<p>* <span>test</span> <strong>cena</strong></p>

So it's a progress :)

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. Field widths entered into the Template Field Widths inputfield are only applied if the Edit Template form is submitted with the Template Field Widths inputfield in an opened state. "Collapsed" is the recommended setting if you think you might also use core inputs for setting field widths in a template context. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By adrian
      Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 35+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
    • By adrian
      This module allows you to automatically rename file (including image) uploads according to a configurable format
      This module lets you define as many rules as you need to determine how uploaded files will be named and you can have different rules for different pages, templates, fields, and file extensions, or one rule for all uploads. Renaming works for files uploaded via the admin interface and also via the API, including images added from remote URLs.   Github: https://github.com/adrianbj/CustomUploadNames
      Modules Directory: http://modules.processwire.com/modules/process-custom-upload-names/
      Renaming Rules
      The module config allows you to set an unlimited number of Rename Rules. You can define rules to specific fields, templates, pages, and file extensions. If a rule option is left blank, the rule with be applied to all fields/templates/pages/extensions. Leave Filename Format blank to prevent renaming for a specific field/template/page combo, overriding a more general rule. Rules are processed in order, so put more specific rules before more general ones. You can drag to change the order of rules as needed. The following variables can be used in the filename format: $page, $template, $field, and $file. For some of these (eg. $field->description), if they haven't been filled out and saved prior to uploading the image, renaming won't occur on upload, but will happen on page save (could be an issue if image has already been inserted into RTE/HTML field before page save). Some examples: $page->title mysite-{$template->name}-images $field->label $file->description {$page->name}-{$file->filesize}-kb prefix-[Y-m-d_H-i-s]-suffix (anything inside square brackets is is considered to be a PHP date format for the current date/time) randstring[n] (where n is the number of characters you want in the string) ### (custom number mask, eg. 001 if more than one image with same name on a page. This is an enhanced version of the automatic addition of numbers if required) If 'Rename on Save' is checked files will be renamed again each time a page is saved (admin or front-end via API). WARNING: this setting will break any direct links to the old filename, which is particularly relevant for images inserted into RTE/HTML fields. The Filename Format can be defined using plain text and PW $page variable, for example: mysite-{$page->path} You can preserve the uploaded filename for certain rules. This will allow you to set a general renaming rule for your entire site, but then add a rule for a specific page/template/field that does not rename the uploaded file. Just simply build the rule, but leave the Filename Format field empty. You can specify an optional character limit (to nearest whole word) for the length of the filename - useful if you are using $page->path, $path->name etc and have very long page names - eg. news articles, publication titles etc. NOTE - if you are using ProcessWire's webp features, be sure to use the useSrcExt because if you have jpg and png files on the same page and your rename rules result in the same name, you need to maintain the src extension so they are kept as separate files.
      $config->webpOptions = array(     'useSrcExt' => false, // Use source file extension in webp filename? (file.jpg.webp rather than file.webp) ); Acknowledgments
      The module config settings make use of code from Pete's EmailToPage module and the renaming function is based on this code from Ryan: http://processwire.com/talk/topic/3299-ability-to-define-convention-for-image-and-file-upload-names/?p=32623 (also see this post for his thoughts on file renaming and why it is the lazy way out - worth a read before deciding to use this module). 
       
       
      NOTE:
      This should not be needed on most sites, but I work with lots of sites that host PDFs and photos/vectors that are available for download and I have always renamed the files on upload because clients will often upload files with horrible meaningless filenames like:
      Final ReportV6 web version for John Feb 23.PDF

×
×
  • Create New...