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.

Embedding source code

Hello,

We created a Vanilla forum for our technology, and developers want to be able to paste in source code (a mix of XML and JavaScript).

Apologies for what seems like a very simple question, but I looked for some time and wasn't able to find the answer: How does one paste in, say, XML and have that appear as entered? More than "pre", I need something that maintains the formatting exactly as entered.

— Charles

Comments

  • peregrineperegrine MVP
    edited May 2014

    quick question - you don't want users to attach file uploads? which may be a way around the issue.

    and I'm not sure if the geshi plugin helps.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  •     <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
    
    
        </html>
    

    grep is your friend.

  • with markdown you should be able to encase in ~~~

    grep is your friend.

  • <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    
    </html>
    

    also indent of four spaces

    grep is your friend.

  • @peregrine said:
    quick question - you don't want users to attach file uploads? which may be a way around the issue.

    A good workaround, thanks. We could also post links to GitHub gists, but the engineering team thinks it's probaby better to have the code inline.

    — Charles

  • @x00 said:
    with markdown you should be able to encase in ~~~

    Cooool! This answer had me stumped me for a while, but I finally figured out that it would work once I changed my config's InputFormatter like so:

    $Configuration['Garden']['InputFormatter'] = 'Markdown';

    Thank you!

    @x00 said:
    also indent of four spaces

    Sorry, I don't understand. Mind elaborating a bit?

    Also: Even though we're now using the Markdown InputFormatter, could we write a custom plug-in (or extend a current one) to support the mixed XML/JavaScript source?

    — Charles

  • peregrineperegrine MVP
    edited May 2014

    .four spaces in front of all lines is equivalent to ~~~ (four space indent).

    http://daringfireball.net/projects/markdown/syntax

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Yes you can write a pre-formter plugin that would change to offend charaters to html entities, then it would go through the Markdown, HTML formatters. Or you can do some javascript post formating. Markdown is also HTML compatable (filtered by HTMLawed).

    However, in fact the pre behavior is actually correct. pre in itself doesn't render html entities as literal in the client, and HTMLawed is generally faithful to HTML.

    The html literal would rendering would be in a textarea, you could use jquery to get a "raw" .text() version of the rendering to put in a textarea.

    Whatever you want to do.

    grep is your friend.

Sign In or Register to comment.