Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-12-06 12:08:28

majkinetor
Member
Registered: 2007-10-10
Posts: 13

[textile] Textile Preview

I created little script to let me preview Textile from my editor instead editing articles directly using TextPattern.
You can connect it with any editor. I am using EditPlus and in it setup looks like this:

Menu Text: Preview Textile
Command: C:\Php\php.exe
Argument: C:\TextilePreview\textilePrev.php “$(FilePath)”

$FilePath is replaced by the actual path I am editing.

This is the textilPrev php script:

<?php
require_once('classTextile.php');

	$fileIn = $GLOBALS['argv'][1];
	$style  = 'style.css';

	$hIn     = fopen($fileIn, 'r') or die("Can't open file");
	$hStyle  = fopen($style, 'r') or die("Can't open style file");
	$data    = fread($hIn, filesize($fileIn));
	$style   = fread($hStyle, filesize($style));
	fclose($hIn);

	$textile = new Textile();
	$data = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><HTML><HEAD><style type="text/css">' . $style . '</STYLE></HEAD><BODY>' . 
			$textile->TextileThis($data) . '</BODY></HTML>'; 


	$fileOut = getenv('TEMP') . "\_mm_textile_preview.html";
	if (file_exists($fileOut)) unlink($fileOut);

	if (!$hOut = fopen($fileOut, 'a')){
		echo "Cannot open file for writting";
		exit;
	}

	if (fwrite($hOut, $data) === FALSE) {
		   echo "Cannot write to file ($fileOut)";
		   exit;
	}
	fclose($hOut);
	exec($fileOut);
?>

TextilePreview directory content:

 classTextile.php
  textilPrev.php
  style.css

Somebody may find this useful.

Last edited by majkinetor (2007-12-06 12:09:19)

Offline

Board footer

Powered by FluxBB