[Assorted-commits] SF.net SVN: assorted:[1026] wp-easy-filter/trunk/src
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-10-22 22:40:47
|
Revision: 1026 http://assorted.svn.sourceforge.net/assorted/?rev=1026&view=rev Author: yangzhang Date: 2008-10-22 22:40:35 +0000 (Wed, 22 Oct 2008) Log Message: ----------- added wp-easy-filter src and README Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Added Paths: ----------- wp-easy-filter/trunk/README wp-easy-filter/trunk/src/easyfilt.php Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2008-10-22 20:02:01 UTC (rev 1025) +++ shell-tools/trunk/src/bash-commons/common.bash 2008-10-22 22:40:35 UTC (rev 1026) @@ -271,7 +271,7 @@ find "$@" -type l | while read file ; do if [ ! -e "$file" ] ; then - sudo -u pkg rm "$file" + rm "$file" fi done } Added: wp-easy-filter/trunk/README =================================================================== --- wp-easy-filter/trunk/README (rev 0) +++ wp-easy-filter/trunk/README 2008-10-22 22:40:35 UTC (rev 1026) @@ -0,0 +1,41 @@ +Overview +-------- + +This is a simple, general filter plug-in for WordPress. You specify a mapping +from tags to commands, such as: + + $tag2cmd = array('pandoc' => '/usr/bin/pandoc -s --tab-stop=2'); + +Then, for posts which are prefixed with a shebang line containing that tag, as in: + + #!pandoc + + Hello, world. + +Then the plug-in will feed the post contents to that command's stdin and return +the rendered output to WordPress for display. + +This plug-in was designed to allow me to start using [Pandoc] for writing my +blog posts. (I couldn't force myself to use the [PHP Markdown Extras] +plug-in.) + +It disables the `wpautop` filter, which automatically inserts `<p>` tags (among +other magic), because that filter cannot properly parse the style of HTML that +Pandoc outputs. + +Setup +----- + +Drop `easyfilt.php` into your `wp-content/plugins/` directory, then activate +the plug-in from the admin interface. + +Notes +----- + +The author of [PHP Markdown Extras] wrote an [informative blog post] describing +problems he had getting his filter to work properly and co-exist with the other +built-in filters. + +[Pandoc]: http://johnmacfarlane.net/pandoc/ +[PHP Markdown Extras]: http://michelf.com/projects/php-markdown/extra/ +[informative blog post]: http://michelf.com/weblog/2005/wordpress-text-flow-vs-markdown/ Added: wp-easy-filter/trunk/src/easyfilt.php =================================================================== --- wp-easy-filter/trunk/src/easyfilt.php (rev 0) +++ wp-easy-filter/trunk/src/easyfilt.php 2008-10-22 22:40:35 UTC (rev 1026) @@ -0,0 +1,90 @@ +<? +/* +Plugin Name: Easy Filter +Plugin URI: http://assorted.sf.net/wp-easy-filter/ +Description: Easy filtering of blog posts. +Version: 1.0 +Author: Yang Zhang +Author URI: http://www.mit.edu/~y_z/ +*/ + +/* +Copyright 2008 Yang Zhang + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +# +# Configuration options. +# + +$tag2cmd = array( + 'pandoc' => '/mit/y_z/.local/armed/bin/mit-pandoc -S --tab-stop=2' +); + +# +# More configuration options. +# + +$debug = false; +$debugfile = '/mit/y_z/web_scripts/wp/wp-content/plugins/easyfilt/log.txt'; +add_filter('the_content', 'filter_custom', 1); +remove_filter('the_content', 'wpautop'); + +# +# Constants. +# + +$descriptorspec = $descriptorspec = array( + 0 => array("pipe", "r"), // stdin is a pipe that the child will read from + 1 => array("pipe", "w"), // stdout is a pipe that the child will write to + 2 => array("pipe", "w") // stderr is a file to write to +); + +# +# Custom filter. +# + +function filter_custom($content) { + global $debug, $tag2cmd, $wp_filter, $descriptorspec; + $lines = explode("\n", $content); + $tag = trim(substr($lines[0], 2)); + if (substr($lines[0], 0, 2) === '#!' && $tag2cmd[$tag]) { + $cmd = $tag2cmd[$tag]; + $process = proc_open($cmd, $descriptorspec, $pipes); + $body = implode("\n", array_slice($lines, 1)); + if (is_resource($process)) { + fwrite($pipes[0], $body); + fclose($pipes[0]); + + $filtered = stream_get_contents($pipes[1]); + fclose($pipes[1]); + + $retval = proc_close($process); + } + } else { + $filtered = $content; + } + if ($debug) { + $f = fopen($debugfile, 'w'); + fwrite($f, print_r($wp_filter, true)); + fwrite($f, print_r($lines, true)); + fwrite($f, substr($lines[0], 0, 2) . " " . (substr($lines[0], 0, 2) === '#!') . " " . $cmd . " " . $tag2cmd[$cmd]); + fwrite($f, "\n===\n$content\n===\n$filtered"); + fclose($f); + } + return $filtered; +} +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |