Extension:BacktickCode

The BacktickCode extension wraps  tags around wikitext which is placed.

This provides a handy wiki-editing shortcut for wikis that expect a lot of inlined  snippets in its pages, and functions similarly to the standard MediaWiki     bold formatting shortcut.

Backtick characters within  blocks will not be altered by this extension. Backticks outside of  blocks can also be output to the page by escaping them as.

Code
' and '\`' by '`'.
 * BacktickCode.php (PHP 5.3+)

// This is hard, because MediaWiki itself uses backticks in       // the `UNIQ and QINU` blocks. We find that when we just // change pairs of ` `, we break the stripstate badly. So       // first we're going to "hide" those by turning the backticks // into tildes. //       $fixprefix = preg_replace('/`/', '~', Parser::MARKER_PREFIX); $fixsuffix = preg_replace('/`/', '~', Parser::MARKER_SUFFIX);

$text = str_replace(Parser::MARKER_PREFIX, $fixprefix, $text); $text = str_replace(Parser::MARKER_SUFFIX, $fixsuffix, $text);

// Now that those are tildes, we can do the replace. We check // for \x7f to ensure our pair of backticks isn't spanning a       // UNIQ/QINU set. $text = preg_replace('/([^\\\\]|^)`([^`\x7f]*)`/', '$1 ', $text); $text = preg_replace('/\\\\\`/', '`', $text);

// Now put the prefix/suffixes back to normal. $text = str_replace($fixprefix, Parser::MARKER_PREFIX, $text); $text = str_replace($fixsuffix, Parser::MARKER_SUFFIX, $text);

return true; };