Textile and Tcl

To maintain your website you can use a content management system but in general you have to waste time for installing and administrating the system. Including CSS features in your CMS managed system will take some further amount of energy.

So why not use a wiki-based markup language, write the pages and upload them finally converted to Html files to your website?

My favourite wiki language is Textile because it has a very smart and easy-to-use syntax and is very easily bound to your CSS-file, e.g.

    p.(myClass)   ->        <p class = myClass>
    p.(#myId)     ->        <p id = myId >

A small Tcl batch programm will glue the components Textile-text, Textile-parser and browser. Because there is no translation to Tcl the original Textile parser classTextile.php we will use the most recent version to be found in the Textpattern directory:

https://code.google.com/p/textpattern/source/browse/development/4.0/textpattern/lib/classTextile.php?r=2985

Some PHP code in a helper file with code showed below will fire the translation. Because the command exec will interpret the "<" characters in the Textile source as redirections we cannot take the source by commandline but have to get the Textile source passed by a file. The result will be saved in a temporary file named textile.html.


<?php
require_once('classTextile.php');
$textile = new Textile;

// Version for getting input from commandline:
// echo $textile->TextileThis($argv[1]);

// Version for getting the content in a file
// Output is sent to textile.html:

$wiki = file_get_contents($argv[1]);
$html = $textile->TextileThis($wiki);
file_put_contents("textile.html", $html);

// For untrusted user input, use TextileRestricted instead:
// echo $textile->TextileRestricted($in);
?>

Presumably, you have installed PHP and the classTextile.php in your build directory the Tcl code below for a simple commandline version could be sufficient:


#!/bin/sh
# the next line restarts using wish \
exec tclsh8.5 "$0" ${1+"$@"}

# commandline tool to create Html code from Textile wiki formatted text
# 
# txl2html.tcl ?-option value? filename

package require Tcl 8.5

namespace eval textile {}

proc ::textile::Init {} {
    # init default values
    set ::textile::Destination {}
    set ::textile::css {} 
        
    set ::textile::header {\
<!DOCTYPE HTML PUBLIC "-W3CDTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<HEAD>
<TITLE>zdia.homelinux.org</TITLE>
<META http-equiv="content-type" content="text/html; charset=utf-8">
<LINK REL="stylesheet" TYPE="text/css" title="Liste" HREF=}
                
    append textile::header $::textile::css
    append textile::header {>
</HEAD>
<body>
}
        
    set ::textile::tail {\
</body>
</html>}
}

proc textile::Usage {} {
    puts "Usage: txl2html.tcl ?-option value? filename
Options:
 -o, --output\tname of output-file
 --css\t\tname of CSS-file
"
}

proc textile::ParseCommandline {} {
    # parses options and name of Textile file in argv
    # returns name of Textile file
    if {$::argc % 2 == 0} {
            puts "Wrong number of arguments\n"
            textile::Usage
            exit
    }
    
    # check filename
    set file [lindex $::argv end]
    if {![file exists $file]} {
        puts "Error: File $file not found"
        exit
    } else {
        set optionList [lrange $::argv 0 end-1]
    }

    # parse options
    foreach {option value} $optionList {
        switch -glob -- $option {
            --output - -o {
                set ::textile::Destination $value
            } --css {
                set ::textile::css $value
            } default {
                puts "Error: Unknown option $option!"
                textile::Usage
                exit
            }

        } ;# end switch
    } ;# end foreach
    
    return $file
}

Then you are able to create your Html page based on a Textile file with the command:

txl2html.tcl -o destPath/destName source.txl

Enjoy!