Giter VIP home page Giter VIP logo

Comments (3)

mpratt avatar mpratt commented on June 2, 2024

Hi sunnysingh,

Thats a good idea but I dont have time to implement it right now. Perhaps for the next big version I'll be able to add an html aware option.

As a workaround you could just extract the data inside the <pre></pre> tags, pass the text through Embera and put the extracted data back inside the <pre> tags again.

Try with something like this:

$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. consectetur, ac dignissim https://www.youtube.com/watch?v=yzTuBuRdAyA .
<pre>
   Etiam scelerisque rutrum justo, https://www.youtube.com/watch?v=yzTuBuRdAyA 
</pre>';

$holder = array();
if (strpos($text, '<pre') !== false) {
    // Reserve the content inside the <pre> tags
    $text = preg_replace_callback('/\\s*(<pre\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i', function ($content) use (&$holder) {
        $placeholder = '%' . md5(time() . count($holder) . mt_rand(0, 500)) . '%';
        $holder[$placeholder] = $content['1'];
        return $placeholder;
    }, $text);
}

$embera = new \Embera\Embera();
$text = $embera->autoEmbed($text);

if (!empty($holder)) {
    $text = str_replace(array_keys($holder), array_values($holder), $text);
}

echo $text;

I think that should work, however you can organize the code better. I would create a new class called something like ReserveTag and put the logic into it.

By doing this you end up with something like this:

$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. consectetur, ac dignissim https://www.youtube.com/watch?v=yzTuBuRdAyA .
<pre>
   Etiam scelerisque rutrum justo, https://www.youtube.com/watch?v=yzTuBuRdAyA 
</pre>';

$reserve = new ReserveTag('pre');
$embera = new \Embera\Embera();
$text = $embera->autoEmbed($reserve->filter($text));
echo $reserve->restore($text);

Tell me if it helps! Like I said, I'll look into implementing something like that on the next major version.

Edit: Look at the Demo - http://3v4l.org/NRJ7E

from embera.

sunnysingh avatar sunnysingh commented on June 2, 2024

This is the best reply that I've seen, I really appreciate in you providing me a code sample and I can't believe that I didn't think of doing it this way.

Your code definitely works for this purpose, I'll use it in the meantime. The one change that I made was replace pre with code so that inline code would not be parsed either.

from embera.

mpratt avatar mpratt commented on June 2, 2024

Im glad it works!

Im marking this issue as closed but believe me, I'll keep this in the back of my head for the next major release of this library!

Cheers!

from embera.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.