Code

Code 2.2.0

No permission to download
Generally, it works, but has some bugs + not all icons are rendering correctly.

I will fix this problems these satudary, sunday, if I have time. To many things to do these days...
 
It seems the addon CSS styles have some confilcts with your forum style...
@Ehren has kindly looked into this for me and was able to replicate it with the default style.

If I had to guess there is something in within the code-block.js file as part of this add-on that is not quite right with the preview functionality, because everything works fine once the code is posted and live.


191370
It's being caused by a hard-coded max-height: 0px; tag, which is not part of my code.


I located the mentioned code when looking at the page source:
HTML:
<div class="bbCodeBlock-content" dir="ltr" style="max-height: 12px; height: 14px; min-height: 14px;">
        <pre class=" line-numbers bbCodeCode language-code" dir="ltr" data-xf-init="code-block" data-lang="code"><code class=" language-code">Test
Test
Test<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>
    </div>
 
Last edited:
Thanks for the addon. It would be great to be able to disable the option for "Code block title" to maintain full BBCode compatibility.

That almost could be done here by disabling template modification:
192003
But then the associated JS crashes:
editor-compiled.js?_v=a37783e5:125 Uncaught TypeError: Cannot read property 'toLowerCase' of undefined

On unrelated note, it looks like the source in GitHub repository is outdated.
 
Last edited:
CMTV updated Code with a new update entry:

Update 2.1.0 – XenForo 2.1 support & New features

Code 2.1.0 was rewritten from scratch. It is not compatible with previous addon version and XF below 2.1 but it can handle code block titles from previous addon versions! There is no way to upgrade existing addon!

Remove installed Math addon from you forum. After this install this version as a new addon!

New features
  • New way of setting parameters for code BB code: [code...

Read the rest of this update entry...
 
@CMTV
Does this look like a bug on latest XF 2.1 and this latest version
Code:
ErrorException: Template error: strtolower() expects parameter 1 to be string, array given src/XF/BbCode/Renderer/Html.php:523
Generated by: Vincent_Wang 3/4/19 at 12:20 PM
Stack trace
#0 [internal function]: XF\Template\Templater->handleTemplateError(2, 'strtolower() ex...', '/home/nginx/dom...', 523, Array)
#1 src/XF/BbCode/Renderer/Html.php(523): strtolower(Array)
#2 [internal function]: XF\BbCode\Renderer\Html->renderTagCode(Array, Array, Array, Array, Object(XF\BbCode\Renderer\EmailHtml))
#3 src/XF/BbCode/Renderer/Html.php(294): call_user_func(Array, Array, Array, Array, Array, Object(XF\BbCode\Renderer\EmailHtml))
#4 src/XF/BbCode/Traverser.php(61): XF\BbCode\Renderer\Html->renderTag(Array, Array)
#5 src/XF/BbCode/Traverser.php(37): XF\BbCode\Traverser->renderSubTree(Array, Array)
#6 src/XF/BbCode/Traverser.php(20): XF\BbCode\Traverser->renderAst(Array, Object(CMTV\Code\XF\BbCode\RuleSet), Array)
#7 src/XF/SubContainer/BbCode.php(219): XF\BbCode\Traverser->render('Hi,

The proble...', Object(XF\BbCode\Parser), Object(CMTV\Code\XF\BbCode\RuleSet), Array)
#8 src/XF/Template/Templater.php(2014): XF\SubContainer\BbCode->render('Hi,

The proble...', 'emailHtml', 'post', Object(XFMG\XF\Entity\Post), Array)
#9 src/XF/Template/Templater.php(2019): XF\Template\Templater->fnBbCode(Object(XF\Mail\Templater), false, 'Hi,

The proble...', 'post', Object(XFMG\XF\Entity\Post), Array, 'emailHtml')
#10 [internal function]: XF\Template\Templater->fnBbCodeType(Object(XF\Mail\Templater), false, 'emailHtml', 'Hi,

The proble...', 'post', Object(XFMG\XF\Entity\Post))
#11 src/XF/Template/Templater.php(915): call_user_func_array(Array, Array)
#12 internal_data/code_cache/templates/l1/s24/email/watched_forum_thread.php(17): XF\Template\Templater->fn('bb_code_type', Array, false)
#13 src/XF/Template/Templater.php(1294): XF\Template\Templater->{closure}(Object(XF\Mail\Templater), Array)
#14 src/XF/Mail/Mailer.php(155): XF\Template\Templater->renderTemplate('watched_forum_t...', Array)
#15 src/XF/Mail/Mail.php(319): XF\Mail\Mailer->renderMailTemplate('watched_forum_t...', Array, Object(XF\Language), Object(QuantNet\Quiz\XF\Entity\User))
#16 src/XF/Mail/Mail.php(375): XF\Mail\Mail->renderTemplate()
#17 src/XF/Mail/Mail.php(406): XF\Mail\Mail->getSendableMessage()
#18 src/XF/Notifier/Post/AbstractWatch.php(128): XF\Mail\Mail->queue()
#19 src/XF/Service/AbstractNotifier.php(92): XF\Notifier\Post\AbstractWatch->sendEmail(Object(QuantNet\Quiz\XF\Entity\User))
#20 src/XF/Service/AbstractNotifier.php(44): XF\Service\AbstractNotifier->notifyType(Object(XF\Notifier\Post\ForumWatch), Array, G)
#21 src/XF/Service/AbstractNotifier.php(56): XF\Service\AbstractNotifier->notify(3)
#22 src/XF/Service/Thread/Creator.php(328): XF\Service\AbstractNotifier->notifyAndEnqueue(3)
#23 src/XF/Pub/Controller/Forum.php(593): XF\Service\Thread\Creator->sendNotifications()
#24 src/XF/Pub/Controller/Forum.php(751): XF\Pub\Controller\Forum->finalizeThreadCreate(Object(XF\Service\Thread\Creator))
#25 src/XF/Mvc/Dispatcher.php(321): XF\Pub\Controller\Forum->actionPostThread(Object(XF\Mvc\ParameterBag))
#26 src/XF/Mvc/Dispatcher.php(244): XF\Mvc\Dispatcher->dispatchClass('XF:Forum', 'PostThread', Object(XF\Mvc\RouteMatch), Object(XenMax\PrefixFilter\XF\Pub\Controller\Forum), NULL)
#27 src/XF/Mvc/Dispatcher.php(100): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XenMax\PrefixFilter\XF\Pub\Controller\Forum), NULL)
#28 src/XF/Mvc/Dispatcher.php(50): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#29 src/XF/App.php(2177): XF\Mvc\Dispatcher->run()
#30 src/XF.php(390): XF\App->run()
#31 index.php(20): XF::runApp('XF\\Pub\\App')
#32 {main}
Request state
array(4) {
  ["url"] => string(34) "/forum/adv-level-8.123/post-thread"
  ["referrer"] => string(68) "https://quantnet.com/forum/adv-level-8.123/post-thread?inline-mode=1"
  ["_GET"] => array(1) {
    ["/forum/adv-level-8_123/post-thread"] => string(0) ""
  }
  ["_POST"] => array(13) {
    ["prefix_id"] => string(2) "29"
    ["title"] => string(52) "PathEvent(res) and EndOfSimulation() do not response"
    ["message_html"] => string(2683) "<p>Hi,</p><p><br></p><p>The problem is that in my start method of MCMediator.h the PathEvent(res) and EndOfSimulation do not work at all but the program can still go to the end without any bugs. I am wondering where I got it wrong . Possible places are the following :</p><p><br></p><p>1. In the initialization of MCMediator, two of my passed-in parameters are &nbsp;const path_signal&amp; optionPaths, &nbsp;const end_signal&amp; finishOptions. And I use "PathEvent.connect(optionPaths);" and "EndOfSimulation.connect(finishOptions);" to connect with them. &nbsp; (where path_signal is boost::signals2::signal&lt;void(const vector&lt;double&gt;&amp; )&gt; and end_signal alike). &nbsp; But I think it is rarely wrong.</p><p><br></p><p>2. In the test.cpp, I use "MCMediator mcp(partsa, builder.GetPaths(), builder.GetEnd(), get&lt;6&gt;(data));" to initialize my mediator. I felt confused here as builder.GetPaths(), builder.GetEnd() can work here ( they are rvalue, but parameter list of MCMediator is lvalue . What's wrong here?) &nbsp;The GetPaths method is as following :</p><p><br></p><p>[CODE=cpp]using path_signal = boost::signals2::signal&lt;void(const vector&lt;double&gt;&amp; )&gt;;// Send a path array&nbsp;</p><p><br></p><p>template &lt;typename GSDE, typename GFDM, typename GRng&gt;</p><p>class MCBuilder{</p><p>private:</p><p>&nbsp;&nbsp; &nbsp;path_signal PathEvent;</p><p>public:</p><p>...</p><p>&nbsp;&nbsp; &nbsp;path_signal GetPaths() { return boost::move(PathEvent); };</p><p>}</p><p>
</p><p><br></p><p>3. In the MCBuilder.h part, we have method GetPricer , in which we connect signal with pricer method . I implemented it as following :</p><p>[CODE lang="cpp" title="MCBuilder.h"]using Payoff = function&lt;double(double)&gt;;</p><p>using Discounter = function&lt;double(void)&gt;;</p><p><br></p><p>template &lt;typename GSDE, typename GFDM, typename GRng&gt;</p><p>class MCBuilder{</p><p>public:</p><p><br></p><p>&nbsp;&nbsp; &nbsp;shared_ptr&lt;IPricer&gt; GetPricer(Payoff payoff, Discounter discounter) {</p><p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;shared_ptr&lt;IPricer&gt; op(new EuropeanPricer(payoff, discounter));</p><p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;auto path_f = [&amp;](vector&lt;double&gt; vec) {return op-&gt;ProcessPath(vec);};</p><p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;auto end_f = [&amp;]() {op-&gt;PostProcess();};</p><p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;PathEvent.connect(boost::ref(path_f));</p><p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;EndOfSimulation.connect(boost::ref(end_f));</p><p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return op;</p><p>&nbsp;&nbsp; &nbsp;}</p><p>&nbsp; &nbsp; }[/CODE]</p><p><br></p><p>@APalley @GONG CHEN&nbsp;</p><p>thanks!</p>"
["attachment_hash"] => string(32) "5cddd2ffcddb7889a956e89fc8828a83"
["attachment_hash_combined"] => string(83) "{"type":"post","context":{"node_id":123},"hash":"5cddd2ffcddb7889a956e89fc8828a83"}"
["watch_thread"] => string(1) "1"
["watch_thread_email"] => string(1) "1"
["_xfSet"] => array(1) {
["watch_thread"] => string(1) "1"
}
["poll"] => array(5) {
["question"] => string(0) ""
["new_responses"] => array(1) {
[0] => string(0) ""
}
["max_votes_type"] => string(6) "single"
["change_vote"] => string(1) "1"[/code]
 
Just tried to install the latest 2.1.1 update and got the following error message:
  • invalid class: CMTV\Code\Xf\BbCode\Renderer\EmailHtml
  • Please enter a valid extension class.
Any idea? I am using XF v2.1.0
 
Hello :)
I am trying to update this add-on, but it give me this error:
  • Invalid class: CMTV\Code\Xf\BbCode\Renderer\EmailHtml
  • Please enter a valid extension class.
 
@applelappalala this addon just makes code blocks more pretty and functional. It does not add any languages. You can add them yourself:
 
Top Bottom