Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
How to paste arbitrary code
Below is a simple program for converting code into a form that can be posted to this forum.
I’ve wasted hours trying to figure out how to paste code to the forum without Textile mucking it up. These approaches do not always work. As far as I can tell, Textile does not have a way to blindly escape everything between two markers.
Then KurtRaschke pointed me to pastebin, which worked nicely except that a week after making my pastebin post the pastebin post disappeared. So much for pastebin.
So I created a simple web page that allows you to submit the code you want to post and be returned a page whose source is pastable directly to the forum. The submit page has a checkbox for optionally converting tabs to spaces, since leaving tabs in the source seems to make the code unreadable on my browser (as it appears in a post).
There is one serious drawback, though: you have to submit your post immediately after pasting the code without first previewing. This is because the preview page (or the browser) converts all the escaped characters back into their unescaped forms and leaves Textile free to muck with everything. Better to preview your post before inserting the code, or if you must, insert the code, preview the post, and then re-insert the code before submitting.
It’s one PHP file that I call sanitize.php:
<pre><code>
<?php
if(!isset($_POST['submit']))
{
?>
<html style="text-align: center">
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<h2>Sanitize code for inclusion in Textile</h2>
<p>Paste the code into the box and press <b>Sanitize</b>:</p>
<p><textarea name="code" style="width:80%; border: 2px solid #000;" rows=24></textarea></p>
<p>
<input type="checkbox" name="notabs" value="1" />Convert tabs to spaces
&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Sanitize" /></p>
</form>
</html>
<?php
}
else
{
$code = $_POST['code'];
if(get_magic_quotes_gpc())
?>
</code></pre>
Offline
Re: How to paste arbitrary code
many thanks for this, jtlapp.
Maybe this can be “officially” added as a tool for the TXP forum, in the shape of a pop-up window…
Offline
Pages: 1