Grow your CSS skills. Land your dream job.

Markdown that doesn’t strip data attributes

  • # September 10, 2012 at 2:14 pm

    My goal on the forums is for you to be able to embed CodePens if you want.

    All that you need to do is:

    But… Vanilla forums strips the data attributes which is what makes this work. It leaves classes and ID’s alone, so there is hope.

    This is the Markdown file that it uses to process the text : https://gist.github.com/3692655

    Any ideas?

    # September 10, 2012 at 4:38 pm

    Sorry Chris I stink at php, but have you considered asking this question on StackOverflow?

    # September 16, 2012 at 11:30 am

    So it just return something like this?

    <pre><code></code></pre>

    I think it have something to do with these

    function doCodeBlocks($text) {
    $text = preg_replace_callback('{
    (?:nn|An?)
    ( # $1 = the code block -- one or more lines, starting with a space/tab
    (?>
    [ ]{'.$this->tab_width.'} # Lines must start with a tab or a tab-width of spaces
    .*n+
    )+
    )
    ((?=^[ ]{0,'.$this->tab_width.'}S)|Z) # Lookahead for non-space at line-start, or end of doc
    }xm',
    array(&$this, '_doCodeBlocks_callback'), $text);

    return $text;
    }

    function _doCodeBlocks_callback($matches) {
    $codeblock = $matches[1];

    $codeblock = $this->outdent($codeblock);
    $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);

    # trim leading newlines and trailing newlines
    $codeblock = preg_replace('/An+|n+z/', '', $codeblock);

    $codeblock = "<pre><code>$codeblockn</code></pre>";
    return "nn".$this->hashBlock($codeblock)."nn";
    }

    Anyway, I agree with @Mottie, ask [StackOverflow](http://stackoverflow.com/questions/tagged/php)

    # September 16, 2012 at 11:35 am

    Do you want to allow them to embed arbitrary HTML, or still have *some* limitations, but allow data-* attributes?

    # September 16, 2012 at 11:39 am

    @TabAtkins I guess either way would be fine.

    I have no real problem with arbitrary HTML being posted – with the exception of security problems like script tags and such, but this forum software like strips that stuff.

    @Mottie @Mobilpadde I will ask there, thanks.

    # September 16, 2012 at 12:17 pm

    The problem lies in regexp used to parse the HTML blocks: search for (?=[s"'/a-zA-Z0-9]) and replace with (?=[s"'/a-zA-Z0-9-]) and it should work.

    # September 16, 2012 at 12:21 pm

    Here is the correct version http://pastebin.com/6fZkxNC6

    # September 16, 2012 at 12:22 pm

    @InerciaCreativa – Thanks for digging in! That appears twice in the file and I replaced them both but no dice.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".