Get Off My Lawn
Get Off My Lawn

Reputation: 36311

Add a class to a markdown code block

I am using a https://github.com/michelf/php-markdown to convert markdown to html, and I can't find any information on this, but how can I add a class to a code block?

I am running the following:

$html = Markdown::defaultTransform($value);
return $html;

To parse something that looks like this:

My Paragraph

    if($something){
        // Do something here
    }

Most of the examples I have seen add {.test} to the end which adds the class so I tried that and nothing happend. I tried the beginning as well and still nothing.

Tried this:

    if($something){
        // Do something here
    }
{.test}

And This:

{.test}
    if($something){
        // Do something here
    }

How can I add a class with this library?

Upvotes: 0

Views: 413

Answers (1)

Coderrrr
Coderrrr

Reputation: 230

Hopefully I didn't miss the scope of the question - it was a little ambiguous, I hadn't realised it might not be until I had already written this

To add a new class using the class functionality you want to extend the class

Extending a class allows you to copy the existing functionality and add your own extended functionality (as per the name!)

Extending looks like this class MardownExtended extends Markdown {

From here you can add your own method

public static function myParagraph() { 
    // ...
}

You will want to use the class MarkdownExtended in your code, rather than the original class

MarkdownExtended::myParagraph();

Upvotes: 1

Related Questions