* From the [[title|]] return link-text as though the used typed [[title|link-text]]
*
* For most links this be as though the user typed [[ns:title|title]]
- * However [[ns:title (context)]], [[ns:title, context]] and [[ns:title (context), context]]
+ * However [[ns:title (context)|]], [[ns:title, context|]] and [[ns:title (context), context|]]
+ * [[#title (context)|]] [[../context/title (context), context|]]
* all return the |title]] with no context or indicative punctuation.
*/
function getPipeTrickText( $link ) {
list( $tc, $nc ) = Parser::getPipeTrickCharacterClasses();
$rexps = array (
# try this first, to turn "[[A, B (C)|]]" into "A, B"
- "/^(:?$nc+:|:|)($tc+?)( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
- "/^(:?$nc+:|:|)($tc+?)( \\($tc+\\)|)(, $tc+|)$/" # [[ns:page (context), context|]]
+ "/^(:?$nc+:|[:#\/]|$tc+\\/|)($tc+?)( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
+ "/^(:?$nc+:|[:#\/]|$tc+\\/|)($tc+?)( \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|)$/", # [[ns:page (context), context|]]
);
}
$text = urldecode( $link );
if( !$rexps ) {
list( $tc, $nc ) = Parser::getPipeTrickCharacterClasses();
$rexps = array (
- "/^($nc+:|)$tc+?( \\($tc+\\))$/", # [[ns:page (context)]]
- "/^($nc+:|)$tc+?(, $tc+|)$/" # [[ns:page, context]]
+ "/^($nc+:|)$tc+?( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
+ "/^($nc+:|)$tc+?(?:(?: \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|))$/" # [[ns:page (context), context|]]
);
}
) );
# Links of the form [[|<blah>]] or [[<blah>|]] perform pipe tricks
+ # Note this only allows the # in the one position it works.
list( $tc, $nc ) = Parser::getPipeTrickCharacterClasses();
- $pipeTrickRe = "/\[\[(?:(\\|)($tc+)|($tc+)\\|)\]\]/";
- $text = preg_replace_callback( $pipeTrickRe, array( $this, 'pstPipeTrickCallback' ), $text);
+ $pipeTrickRe = "/\[\[(?:(\\|)($tc+)|(#?$tc+)\\|)\]\]/";
+ $text = preg_replace_callback( $pipeTrickRe, array( $this, 'pstPipeTrickCallback' ), $text );
# Trim trailing whitespace
$text = rtrim( $text );
*
* @param Array ("|" or "", text, link) $m
*/
- function pstPipeTrickCallback($m)
+ function pstPipeTrickCallback( $m )
{
if( $m[1] ) { # [[|<blah>]]
$text = $m[2];
[[:Bar:X (Y) Z|X (Y) Z]]
!! end
+!! test
+pre-save transform: context links ("pipe trick") based on current page
+!! options
+pst
+!! input
+[[#section|]]
+[[#section (context)|]]
+[[/relative|]]
+[[../context/relative|]]
+[[../context/relative (extra)|]]
+!! result
+[[#section|section]]
+[[#section (context)|section]]
+[[/relative|relative]]
+[[../context/relative|relative]]
+[[../context/relative (extra)|relative]]
+!! end
+
+!! test
+pre-save transform: context links ("pipe trick") with full-width characters
+!! options
+pst
+!! input
+[[title, context|]]
+[[title (context)|]]
+!! result
+[[title, context|title]]
+[[title (context)|title]]
+!! end
+
!! test
pre-save transform: context links ("pipe trick") with interwiki prefix
!! options