The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Markdown that doesn’t strip data attributes

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • #39770
    Chris Coyier

    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 :

    Any ideas?


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


    So it just return something like this?


    I think it have something to do with these

    function doCodeBlocks($text) {
    $text = preg_replace_callback('{
    ( # $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
    ((?=^[ ]{0,'.$this->tab_width.'}S)|Z) # Lookahead for non-space at line-start, or end of doc
    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](


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

    Chris Coyier

    @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.

    @Mobilpadde I will ask there, thanks.


    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.


    Here is the correct version

    Chris Coyier

    @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)
  • The forum ‘Back End’ is closed to new topics and replies.