Am trying to share a LESS CSS code in my forum. When I add the LESS variable syntax which looks like this @less-var, the variable get linked as if it were someone's username. Please how do I stop this from happening?
public static function replaceButProtectCodeBlocks($Search, $Replace, $Subject, $IsCallback = false) {
// Take the code blocks out, replace with a hash of the string, and
// keep track of what substring got replaced with what hash.
$CodeBlockContents = array();
$CodeBlockHashes = array();
$Subject = preg_replace_callback(
'/<code>.*?<\/code>/i',
function ($Matches) use (&$CodeBlockContents, &$CodeBlockHashes) {
// Surrounded by whitespace to try to prevent the characters
// from being picked up by $Pattern.
$ReplacementString = ' '.sha1($Matches[0]).' ';
$CodeBlockContents[] = $Matches[0];
$CodeBlockHashes[] = $ReplacementString;
return $ReplacementString;
},
$Subject
);
// Do the requested replacement.
if ($IsCallback) {
$Subject = preg_replace_callback($Search, $Replace, $Subject);
} else {
$Subject = preg_replace($Search, $Replace, $Subject);
}
// Put back the code blocks.
$Subject = str_replace($CodeBlockHashes, $CodeBlockContents, $Subject);
return $Subject;
}
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
you can certainly add the code, and see if works, but there may be other things that are changed as well to effect the change besides the protect code blocks,
I figure since 2.2 is relatively imminent - it might be worth the wait, instead of beating brains out to try to fix.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Comments
Actually, you should treat this as a piece of code, which it is. And for code, you better use a highlighter which will display it like this:
@less-var
I actually wrapped it in a code tag, and am using googlecodeprettify.
What formatter are you using?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
I don't understand what you mean.
But I know am using a customMention and here is the code:
Does removing your custom mentions formatter fix this issue?
If so, we know where to look.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
what editor plugin are you using. buttonbar wysiwyg, etc?
what inputformatter?
what version of vanilla are you using?
If I am not mistaken, it seems to me the code tags do not properly work in vanilla 2.1 to filter out @sign links. by default with html or markdown.
it is fixed in 2.2rc1 with the protectcodeblocks function and perhaps other fixes as well.
calls
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
No!
buttonbar.
html
2.1.13
you might wait until 2.2 is officially released. It seems to be fixed.
or if you want to retrieve interim imminent 2.2 version from github you could experiment with that.
but see the release notes and the readme and backup your database before installing, if you do.
regarding 2.1.13p1 - I could be wrong, but I think @mentions in code are links and not properly formatted.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
@peregrine can I incorporate the code in my customMention class like So:
you can certainly add the code, and see if works, but there may be other things that are changed as well to effect the change besides the protect code blocks,
I figure since 2.2 is relatively imminent - it might be worth the wait, instead of beating brains out to try to fix.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Incorporating the code didn't fix the issue.
Am just going to wait for 2.2.
@xm1
If you want to turn off mentions completely whether @ is in code blocks or not
(you may not want to do, but you can if you are not aware).
you can add this to conf/config.php
$Configuration['Garden']['Format']['Mentions'] = FALSE; // no linking for @mentions
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
@peregrine I do not want to turn it off completely.