Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

HtmLawed and other input format

cdavidcdavid New
edited November 2010 in Vanilla 2.0 - 2.8
Dear all (especially @Todd @Lincoln ),

I am trying to set up a plugin which allows you to write in a different format than HTML, mainly TeX / LaTeX. All seems to work fine, but I can't get HtmLawed (or Vanilla?) to play nicely with the new plugin.

So, in the interface I have a radio button that allows a user to select the input format (LaTeX / HTML). If the users selects LaTeX, the content is then sent to a web service that takes LaTeX and returns properly formatted XHTML (and I can guarantee that) that is added to the database in a special column (BodyXHTML), alongside with Format=LaTeX in GDN_Discussion / Comment.

The problem is that HtmLawed / Vanilla are too smart and are purifying this such that an input such as:
$123+3241<999$
which would translate into XHTML + MathML
<div class="document"> <div class="para"> <p style="" class="p"> <m:math display="inline"> <m:semantics> <m:mrow> <m:mrow> <m:mn>123</m:mn> <m:mo>+</m:mo> <m:mn>3242</m:mn> </m:mrow> <m:mo><</m:mo> <m:mn>999</m:mn> </m:mrow> </m:semantics> </m:math> </p> </div> </div>

is actually rendered as
<p> 123+3242</p>

I am already hooking into: DiscussionController_BeforeCommentBody_Handler to do:
if(isset($Sender->EventArguments["Comment"])){ $Sender->CurrentComment->Body = $Comment->BodyXHTML; } else{ $Sender->Discussion->Body = $Comment->BodyXHTML; } and in public function PostController_BeforeCommentBody_Handler($Sender) { $Sender->CurrentComment->Body = $Sender->EventArguments['Comment']->BodyXHTML; }

Disabling HtmLawed doesn't solve anything, making me think it's a more intricate Vanilla problem.

Any suggestions and pointers are welcome.

Thanks a lot,

/cd
Tagged:

Comments

  • Out of my element on this one, sorry. I think @Todd did the filter work. This is an area where my knowledge of V2 is still limited.
  • Thanks anyways.

    So, I am still experimenting: I leave the format to be Html for the comments and disable HtmLawed by putting return $Html; before the actual call to the htmLawed function (a crude disable) and everything works perfectly for LaTeX posts. Still, since now HtmLawed is disabled, any mention of < > in the posts will break the XHTML ...

    /cd
  • ToddTodd Vanilla Staff
    edited November 2010
    One thing I would suggest is make your Latex style html a different named formatter that will do what you want. Here is the relevant code:

    In your event handlers after you assign body:

    $Sender->CurrentComment->Format = 'LatexHtml';
    Add a formatter function to your plugin:

    public function Format($String) {
    // You can do what you want to format the string.
    // This will grab the current Html formatter which would be Htmlawed in most cases.
    $Formatter = Gdn::Factory('HtmlFormatter');
    if ($Formatter)
    $String = $Formatter->Format($String);
    return $String;
    }
    Above your class definition you'll have to to tell the framwork about your formatter:

    // Make sure you substitute your classname below.
    // The Htmlawed plugin does this so you can have a look if you are confused.
    Gdn::FactoryInstall('LatexHtmlFormatter', 'PluginClassName', __FILE__, Gdn::FactorySingleton);
  • Thanks @Todd . I'll take a look and come back with results.

    /cd
  • @Todd -- thanks a lot, works like a charm!
Sign In or Register to comment.