1 (edited by flx 2005-09-23 21:09)

Topic: Textile Replacement for BBCode 1.0.1

Textile Replacement for BBCode
there are many who want to use textile instead of bbcode.
inspired by this thread: http://punbb.org/forums/viewtopic.php?id=8734, i decided to make a mod who provides full textile functions (except own html codes) and is easy to install. the plugin can be installed in 3 minutes.

see the mod in action at http://html-forum.net/viewforum.php?id=9

first of all: what does textile do (for those who do not know)
    *  Replace single and double primes (' and ") used as quotation marks with HTML entities for opening and closing quotation marks (?? and ??) in readable text, while leaving untouched the primes required within HTML tags.

    * Replace double hyphens (--) with an em-dash (?) entity.

    * Replace single hyphens surrounded by spaces with an en-dash (?) entity.

    * Replace triplets of periods (...) with an ellipsis (?) entity.

    * Convert many nonstandard characters (?úß???) to browser-safe entities corresponding to keyboard input.

    * Apply block- and phrase-level structural tags automatically and at the discretion of the writer via quick tags.

    * Allow the quick creation of simple and complex tables

    * Allow the simple application of style, class, id, language and alignment attributes to elements

    * Create hyperlinks and insert images via quick tags.

    * Define acronyms via quick tags

    * Wrap an <acronym> tag around runs of three or more capital letters automatically.

    * Convert (TM), (R), and (C) to ?, ®, and ©

    * Convert the letter x to a dimension sign: 2x4 to 2×4 and 8 x 10 to 8×10

Examples

>> Test it here: http://textism.com/tools/textile/

Here is a quick reference:
Quick block modifiers:
Header: hn.
Blockquote: bq.
Footnote: fnn.
Numeric list: #
Bulleted list: *

Quick phrase modifiers:
_emphasis_
*strong*
??citation??
-deleted text-
+inserted text+
^superscript^
~subscript~
%span%

To apply attributes:
(class)
(#id)
{style}
[language]

To align blocks:
< right
> left
= center
<> justify

To insert a table:
|a|table|row|
|a|table|row|

To insert a link:
"linktext":url

To insert an image:
!imageurl!

To define an acronym:
ABC(Always Be Closing)

To reference a footnote:
[n]

But there is already a mod..
Yes theres a mod, however it can only be installed on clean punbbs. If you havent modified your punbb and want to be able to change between textile and bbcode use this mod:http://punres.org/desc.php?pid=42
However you can only decide once if you use bbcode or textile. once you forum posts are written with textile you can't easily switch to bbcode. the posts would be messed up.

Features
the mod really integrates well into punbb.
you can turn textile off and on just like bbcode.
you can turn images off and on just like bbcode.
you can differ between messages and signatures just like bbcode.
your users can't use <html> tags just like bbcode

plus it provides easier post formatting and much more possibilities to do it.
this post would have been easier to write and more structured with textile.

Readme Header

##
##
##        Mod title:  Textile replacement for BBCode
##
##      Mod version:  1.0.1
##   Works on PunBB:  1.2.7
##     Release date:  2005-09-13
##           Author:  Felix Brockherde (mail@brockherde.com)
##
##      Description:  Use Textile instead of BBCode. You can find more information
##               about Textile here: http://textism.com/tools/textile/ 
##
##   Affected files:  post.php
##               edit.php
##               profile.php
##               lang/English/common.php
##               lang/English/help.php
##               include/parser.php
##
##       Affects DB:  No
##
##            Notes:  "This space would otherwise be a good space to brag
##              about your mad modding skillz :)"
##              Actually this is my first mod ;) Give me some feedback!
##
##              This mod was inspired by Fire Fusion
##              http://punbb.org/forums/viewtopic.php?id=8734
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##
##

Download
finally wink
Download v1.0.3
update: signature fixed

2

Re: Textile Replacement for BBCode 1.0.1

AHHAHAHAHA smile

and you say TEXTILE IS EASIER FOR FINAL USER ??? Let me laugh very high.

It's simplier for a final user to learn directly CSS / XHTML than textile ... waouh : never textile please Rickard.

3

Re: Textile Replacement for BBCode 1.0.1

Well,
although it is really unpolite to laugh at somebody who made an effort to help out others  I agree that this doesn't look user friendly at all.

But then again, if people want it like this, why not?
People want Windows, you know... smile

The German PunBB Site:
PunBB-forum.de

4

Re: Textile Replacement for BBCode 1.0.1

Tobi wrote:

Well,
although it is really unpolite to laugh at somebody who made an effort to help out others  I agree that this doesn't look user friendly at all.

But then again, if people want it like this, why not?
People want Windows, you know... smile

Windows is more friendly than Linux smile even if Linux is powerful. People don't want necessary the best thing, but the easiest thing : and coders have to think about that.

5 (edited by Paul 2005-09-13 18:48)

Re: Textile Replacement for BBCode 1.0.1

Thanks Felix. Thats going make a lot of people happy.

Looking at it, Textile is nowhere near as difficult as I thought, most of the commands actually seem obvious once you see them. Especially useful I would imagine for those who want to write longer items to be published on their sites front page etc.

Just out of curiosity, is it possible to modify Textile to parse bbcode. That way you would have the best of both worlds with no need to worry about switching between the two.

Rod. This was a mod release announcement and is not the place to discuss the merits or otherwise of Textile, save that for the thread in "Feature requests".

Re: Textile Replacement for BBCode 1.0.1

Awesome!!!

Thank you so much for taking the time to make this. I can't wait to try it out.

7 (edited by Fire Fusion 2005-09-13 21:06)

Re: Textile Replacement for BBCode 1.0.1

All seems good expect the quote option no longer works like it should.

Also there are no auto paragraphs.

8

Re: Textile Replacement for BBCode 1.0.1

Interesting idea. I'd never thought about replacing BBCode with Textile or any other alternative formatting (wikipedia?). I suppose if you do it right, you could create a mod that would let people mix in whatever formatting codes make sense to them, on top of the BBCode. But that would probably slow down the forum - or um, I forget: is the XHTML of a post cached in the database? It's been too long ... But I'll admit, I always thought *bold* (textile) made more sense than the BBCode or wikipedia versions.

Re: Textile Replacement for BBCode 1.0.1

Louis wrote:

is the XHTML of a post cached in the database?

No, it's processed on the fly.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

10 (edited by flx 2005-09-14 06:29)

Re: Textile Replacement for BBCode 1.0.1

Paul wrote:

Just out of curiosity, is it possible to modify Textile to parse bbcode. That way you would have the best of both worlds with no need to worry about switching between the two.

Would be cool to parse bbcode and textile.. im thinking about it

Fire Fusion wrote:

All seems good expect the quote option no longer works like it should.

i will fix it today

Rod wrote:

and you say TEXTILE IS EASIER FOR FINAL USER ??? Let me laugh very high.

Everyone has to decide this for himself. I want to give you all bbcode features in textile:
*strong*
%{text-decoration:underline}underlined%
_emphasize_
%{color:#FF0000}red%
%{color:blue}blue%
"PunBB.org Forums":http://punbb.org/forums/
image: !http://punbb.org/img/small_logo.png!

bq. blockquote

@code@

It might be more difficult to learn but is easier to use in my opinion.

Nevertheless: big thx for your support! big_smile big_smile big_smile

Re: Textile Replacement for BBCode 1.0.1

Don't forget the paragraphs, it's a very important part. Hit the return button a couple of times and you'll see it does nothing to the final post.


And thanks again for making this smile

12

Re: Textile Replacement for BBCode 1.0.1

what paragraphs do you mean?
textile makes <p>s

quote option fixed
the quote option for posts works now. however its not possible to quote posts with empty lines. thats a problem of textile, not mine wink

see download link in first post

Re: Textile Replacement for BBCode 1.0.1

I mean you can't make an empty line space without using the p tag.

^ The space I made between this post and that one was done with the return button. That doesn't work with the Textile on.

14

Re: Textile Replacement for BBCode 1.0.1

A great guide / reference to textile: http://hobix.com/textile/

It's got clear examples for the most common features. The box on the left is the textile markup, the grey box is the browser markup, and the yellow box is what will be displayed in a browser. (What everyone will see.)

15

Re: Textile Replacement for BBCode 1.0.1

Fire Fusion wrote:

I mean you can't make an empty line space without using the p tag.

^ The space I made between this post and that one was done with the return button. That doesn't work with the Textile on.

textile makes this to

<p>I mean...</p>
<p>^ The space...</p>

in my forum (html-forum.net) the space between <p>s is not displayed somehow. its probably turned off by the stylesheet.
then it would marked up correctly. how much space you want between <p>s is your choice.
More than one empty line makes no sense in my opinion.

Or we have to replace lines which contain only \n with <p></p>. therefore the textile class has to be modified.

greets,
flx

16 (edited by Paul 2005-09-14 13:56)

Re: Textile Replacement for BBCode 1.0.1

PunBB's stylesheet kills all default margins and padding. To get the margins back on <p>'s in posts you have to change your stylesheet to .postmsg p {margin-bottom: whatever}

This paragraph thing is a pain even without textile. By default PunBB turns spaces in text into <br /><br />. Thats bad, two new lines should always generate a paragraph. That however raises a major problem. The only way to generate a double space is with an empty paragraph. Since empty tags are very bad practice the only solution is to not actually allow two empty lines so, for example, \n\n\n will just generate a new paragraph with normal spacing. I have been giving this some thought because long posts just consisting of text are all going to consit of one paragraph even though they look like a dozen paragraphs. That I understand is not good from an accessibility point of view.

NB: There is a way to do it but its a bit ugly. You just count the number of new lines. Two new lines generates a new paragraph, the number of excess new lines are then used to assign a class to the paragraph e.g. <p class="topspace<?php echo count lines - 2 ?>"> p.topspace3 {padding-top: 3em}. You would have to decide in advance how many blank lines you were going to allow but, on reflection, maybe no uglier than a load of  <br /> tags.

17 (edited by Rod 2005-09-14 14:12)

Re: Textile Replacement for BBCode 1.0.1

In same time, we speak about a forum, and not a blog or another page of a site. I don't think 2 br inside a post in the end of the world. Pun is very far of the other bbs about the quality of its markup.

However, I use a plugin under NUCLEUS which accompishes very well the "smart paragraphs" : maybe it can help you.

<?

// plugin needs to work on Nucleus versions <=2.0 as well
if (!function_exists('sql_table'))
{
    function sql_table($name) {
        return 'nucleus_' . $name;
    }
}
class NP_SmartParagraphs extends NucleusPlugin {
function getName() { return 'SmartParagraphs'; }
function getAuthor() { return 'Traweb'; }
function getURL() { return 'http://www.traweb.com/extra/nucleusplugin/'; }
function getVersion() { return '1.5.1'; }
function getDescription() {
    return 'This plugin will convert line breaks and paragraphs in your entries, by adding the corresponding markup tags to produce valid HTML or XHTML. It is smart enough not to insert these tags in places where they may conflict with block elements and other HTML markup tags you may already be using in your posts. Basically, this is a more powerful line break converter than the default one embedded in Nucleus. It is now based entirely on the autop script by Matthew Mullenweg - see at see at http://photomatt.net/scripts/autop.';
}

function supportsFeature($feature) {
    switch($feature) {
        case 'SqlTablePrefix': return 1;
        default: return 0;
    }
}

function getEventList() {
return array('PreItem','PrepareItemForEdit');
}

function event_PreItem($data) {
$this->doSmartParagraphs($data['item']->body);
$this->doSmartParagraphs($data['item']->more);
}

// remove before editing if auto convert breaks had been enabled
function event_PrepareItemForEdit($data) {
$this->undoSmartParagraphs($data['item']->body);
$this->undoSmartParagraphs($data['item']->more);
}

function autop(&$pee, $br=1) {

$pee = $pee . "\n"; // just to make things a little easier, pad the end
$pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
$pee = preg_replace('!(<(?:table|ul|ol|li|pre|form|blockquote|h[1-6])[^>]*>)!', "\n$1", $pee); // Space things out a little
$pee = preg_replace('!(</(?:table|ul|ol|li|pre|form|blockquote|h[1-6])>)!', "$1\n", $pee); // Space things out a little
$pee = preg_replace("/(\r\n|\r)/", "\n", $pee); // cross-platform newlines
$pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "\t<p>$1</p>\n", $pee); // make paragraphs, including one at the end
$pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
$pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
$pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
$pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
$pee = preg_replace('!<p>\s*(</?(?:table|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)!', "$1", $pee);
$pee = preg_replace('!(</?(?:table|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee);
if ($br) $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
$pee = preg_replace('!(</?(?:table|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*<br />!', "$1", $pee);
$pee = preg_replace('!<br />(\s*</?(?:p|li|div|th|pre|td|ul|ol)>)!', '$1', $pee);
$pee = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $pee);

}

function doSmartParagraphs(&$data) {
$this->autop($data);
}

function undoSmartParagraphs(&$data) {

$data = str_replace("<p>",'',$data);
$data = str_replace("</p>\n\n","\n\n",$data);
$data = str_replace("<br />\n","\n",$data);
}

}
?>

18

Re: Textile Replacement for BBCode 1.0.1

fixed the signature bug. new version is 1.0.3.

Re: Textile Replacement for BBCode 1.0.1

I noticed that bbcode-style [ code ] tags still work in your version. Would it be hard to allow the bbcode [ quote=foo ]
tags to work as well? The only drawback I've found in Textile so far is that I can't figure out multiline blockquotes.

20 (edited by flx 2005-11-03 15:52)

Re: Textile Replacement for BBCode 1.0.1

i had that problem, too and did a mixture between textile and bbcode.
- uninstall the textile replacement mod
- opern include/parser.php and search for "$pattern = array(" in function "function do_bbcode($text)"
- then replace the $pattern and $replace arrays with:

                     $pattern = array('/(^|\s)\*(.*?)\*(\s|$)/m',
                     '/(^|\s)\_(.*?)\_(\s|$)/m',
                     '/(^|\s)\+(.*?)\+(\s|$)/m',
                     '/(^|\s)\~(.*?)\~(\s|$)/m',
                     '/(^|\s)\^(.*?)\^(\s|$)/m',
                     '/(^|\s)\!(.*?)\!(\s|$)/m',
                     '#\[u\](.*?)\[/u\]#s',
                     '#\[url\]([^\[]*?)\[/url\]#e',
                     '#\[url=([^\[]*?)\](.*?)\[/url\]#e',
                     '#\[email\]([^\[]*?)\[/email\]#',
                     '#\[email=([^\[]*?)\](.*?)\[/email\]#',
                     '#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/color\]#s',
                     '/([^\s[{(>_*])?\'(?(1)|(?=\s|s\b|[[:punct:]]))/',   //  single closing
                     '/\'/',                                              //  single opening
                     //'/([^\s[{(>_*])?"(?(1)|(?=\s|[[:punct:]]))/',        //  double closing
                     //'/"/',                                               //  double opening
                     '/\b( )?\.{3}/',                                     //  ellipsis
                     '/\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/',        //  3+ uppercase acronym
                     '/\s?--\s?/',                                        //  em dash
                     '/\s-\s/',                                           //  en dash
                     '/(\d+) ?x ?(\d+)/',                                 //  dimension sign
                     '/\b ?[([]TM[])]/i',                                 //  trademark
                     '/\b ?[([]R[])]/i',                                  //  registered
                     '/\b ?[([]C[])]/i',                                                                    //  copyright
                     '/(^|\s)\-(.*?)\-(\s|$)/m');

    $replace = array(' <strong>$2</strong> ',
                     ' <em>$2</em> ',
                     ' <ins>$2</ins> ',
                     ' <sub>$2</sub> ',
                     ' <sup>$2</sup> ',
                     '<img class="postimg" src="$2" alt="$2" />',
                     '<span class="bbu">$1</span>',
                     'handle_url_tag(\'$1\')',
                     'handle_url_tag(\'$1\', \'$2\')',
                     '<a href="mailto:$1">$1</a>',
                     '<a href="mailto:$1">$2</a>',
                     '<span style="color: $1">$2</span>',
                     '$1?$2',                                        //  single closing
                     '?',                          //  single opening
                     //'$1?',                        //  double closing
                     //'?',                          //  double opening
                     '$1?',                        //  ellipsis
                     '<acronym title="$2">$1</acronym>', //  3+ uppercase acronym
                     '?',                          //  em dash
                     ' ? ',                        //  en dash
                     '$1×$2',                       //  dimension sign
                     '?',                          //  trademark
                     '®',                           //  registered
                     '©',                                                    //  copyright
                     ' <del>$2</del> ');

21

Re: Textile Replacement for BBCode 1.0.1

I think this is super baad!

one hassle: using the header code "hn." has a flaw (at least in safari and firefox on a mac) where the subsequent <h1></h1> doesn't close correctly. The closure happens at the end of the entry, thus everything posts as "h1."

Haven't found a good way to ask textile to close this tag correctly...

a.) what am i doing wrong?
b.) do other people have this hassle?

22

Re: Textile Replacement for BBCode 1.0.1

flx wrote:

i had that problem, too and did a mixture between textile and bbcode.
- uninstall the textile replacement mod
- opern include/parser.php and search for "$pattern = array(" in function "function do_bbcode($text)"
- then replace the $pattern and $replace arrays with:

You're saying that you now allow both textile and bbcode simply by making this change?

Re: Textile Replacement for BBCode 1.0.1

dss wrote:
flx wrote:

i had that problem, too and did a mixture between textile and bbcode.
- uninstall the textile replacement mod
- opern include/parser.php and search for "$pattern = array(" in function "function do_bbcode($text)"
- then replace the $pattern and $replace arrays with:

You're saying that you now allow both textile and bbcode simply by making this change?

It doesn't look like it. It looks like he's just replacing some of the bbcode formatting tags with textile characters. What I'd like to figure out is a way to allow both like the textpattern and textdrive forums seem to do, but the guy who set that up is being really really cagey about it.

24

Re: Textile Replacement for BBCode 1.0.1

wouldn't this simply be a matter of adding the function?

I mean, there's nothing wrong with bbcode. I dig it. But i do want to have access to more html tags, and textpattern is a novel way of doing that (adding H1, H2, etc...)

Why not just add this, as opposed to replacing the bbcode?

Re: Textile Replacement for BBCode 1.0.1

I'm guessing because it's harder to allow both to work at once. But that's just a guess.