Extension:BacktickCode
| This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net. |
|
BacktickCode Release status: stable |
|||
|---|---|---|---|
| Implementation | Tag | ||
| Description | Wrap `text between backticks` in <code> tags. | ||
| Author(s) | Joel Thornton <mediawiki@joelpt.net> (joelpttalk) | ||
| Last version | 1.0 (December 30 2012) | ||
| MediaWiki | 1.5 or newer | ||
| License | GPL | ||
| Download | (Code available in the article.) | ||
|
|||
| Check usage and version matrix | |||
Contents |
Overview [edit]
This extension wraps <code> tags around wikitext which is placed `between backtick characters`.
This provides a handy wiki-editing shortcut for wikis that expect a lot of inlined <code> snippets in its pages, and functions similarly to the standard MediaWiki ''' -> <b> bold formatting shortcut.
Backtick characters within <pre> blocks will not be altered by this extension. Backticks outside of <pre> blocks can also be output to the page by escaping them as \`.
How to install [edit]
Installing the extension [edit]
Make the file 'BacktickCode.php' containing the following code, and place it in the 'extensions' directory.
<?php /** * @author Joel Thornton <mediawiki@joelpt.net> * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ if(!defined('MEDIAWIKI')) die("This is an extension to the MediaWiki package and cannot be run standalone."); // Register as an extention $wgExtensionCredits['parserhook'][] = array( 'name' => 'BacktickCode', 'version' => '1.0', 'url' => 'http://www.mediawiki.org/wiki/Extension:BacktickCode', 'author' => 'Joel Thornton <mediawiki@joelpt.net>', 'description' => 'Show text as <code> between backticks (`). To print just a ` character, type ` preceded by one backslash.', ); // Register hooks $wgHooks['ParserBeforeStrip'][] = 'backtickCodeParse'; // Parse function function backtickCodeParse( &$parser, &$text, &$stripState ) { // We replace '`...`' by '<code>...</code>' and '\`' by '`'. // Text between <pre> tags is not modified. $text = preg_replace_callback('/<pre>(.*?)<\/pre>/s', function ($match) { return '<pre>' . preg_replace('/`/', '\`', $match[1]) . '</pre>'; }, $text); $text = preg_replace('/([^\\\\]|^)`([^`]*)`/', '$1<code>$2</code>', $text); $text = preg_replace('/\\\\\`/', '`', $text); return true; }
Loading the extension [edit]
At the end of LocalSettings.php, add the following.
require_once("$IP/extensions/BacktickCode.php");
Credits [edit]
This extension is derived from Extension:DollarSign.
