Extension talk:BacktickCode

Adaptation notes
I adapted this extension for the ConTeXt wiki, so that it would also leave alone backticks inside  and  tags. Things to take into account when adapting:


 * The current regex is case-sensitive: f.ex. is matched and backticks inside it are ignored; if the tag is written, this does not happen..
 * The current regex does not match tags with attributes. We discovered this when our adapted version properly matched and ignored the contents of tags, but did not ignore backticks inside.

Adapted code that allows tag attributes (but is still case-sensitive): --Sietse (talk) 22:39, 30 May 2013 (UTC)

Compatibility with Mediawiki 1.27.0
For some reason this extension will not work with Mediawiki version 1.27.0,
 * when used, all text is will be garbled with "uniq" (prefix) "qinu" (suffix).
 * seems to be a parsing problem:


 * https://www.mediawiki.org/wiki/QINU_fix
 * https://www.mediawiki.org/wiki/Thread:Extension_talk:Favorites/UNIQ...QINU_parser_problem

BackTick/BackQuote/Grave seems to work in MediaWiki out of the box

This Code works for me

 * This didn't work for me, I still got QINU, until I removed the require_once in LocalSetting --JimmyRoxburgh (talk) 03:15, 19 August 2016 (UTC)
 * Update: Actually it stop replace backticks, so i put the require_once back in - and it is now working, no QINU. I suspect a rebuildall helped --JimmyRoxburgh (talk) 00:19, 23 August 2016 (UTC)

', $text);       $text = preg_replace('/\\\\\`/', '`', $text);    }

}

// Running MediaWiki? if ( defined( 'MEDIAWIKI' ) ) {   // Register our MediaWiki parser hooks $wgHooks['ParserBeforeStrip'][] = 'BacktickCode::onParserBeforeStrip';

} // End MediaWiki env else {   die("This is an extension to the MediaWiki package and cannot be run standalone."); }

The root cause, and another solution
The problem with the above solution, i.e. running it on the  hook, is that backtick pairs inside   blocks may still get processed.

The root cause of the whole thing is that the parser marker prefix and suffix contain backticks themselves, if you look closely:. If you run the backtick filter before stripping, you get around that problem but you break nowiki tags.

So here's a version which respects nowiki tags. It runs on the  hook, after   blocks are protected, and it's smart enough to not mangle the marker affixes (or rather, it mangles them and then unmangles them ...)

' and '\`' by '`'.

// 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; } }

Hope this is both useful and instructive. Sk4p (talk) 15:19, 15 October 2016 (UTC)
 * This is wonderful! Have you considered updating the extension page or making your own for this? James Kevin Martindale (talk) 04:57, 23 October 2016 (UTC)

Backtick code is same as Markdown
Ћ Back-tick code and Backslash escape is same as Ћ Markdown’s syntax. Can we have something like  (with two back-ticks/graves), and   (using two backslashes for a replacement of   tag.

46.130.146.196 08:28, 3 September 2016 (UTC)