thephpleague / html-to-markdown

Convert HTML to Markdown with PHP
MIT License
1.77k stars 204 forks source link

How do I preserve certain tags while using the 'strip_tags' option? #222

Closed aihoshistar closed 2 years ago

aihoshistar commented 2 years ago

Description

Clearing all tags using the 'strip_tags' option. As a result, the contents inside 'iframe' are deleted.

But I don't want to erase some tags. (for example, iframe)

It's not known by "READEM". Does the library have this feature?

Example

My code

$converter = new HtmlConverter();
$converter->getConfig()->setOption('strip_tags', true);

...
...

$markdown = $converter->convert($html);

$html

<div class="content">
    <a href="/phpstorm/category/videos/" class="tag">비디오</a>
    <h1>새 비디오: PHP 8.1의 새로운 기능</h1>
    <div class="post-info">
        <img
            src="https://secure.gravatar.com/avatar/269798998e24876e4f3ea6f6d1effdc7?s=200&amp;r=g"
            width="200"
            height="200"
            alt="로만 프론스키"
            loading="lazy"
            class="avatar avatar-200 wp-user-avatar wp-user-avatar-200 photo avatar-default"
        />
        <div class="post-info__text">
            <a href="https://blog.jetbrains.com/author/rpronskiy"
                >로만 프론스키</a
            >
            <time
                class="publish-date"
                data-year="2021"
                data-month="11"
                data-day="26"
                datetime="2021-11-26"
            ></time>
        </div>
    </div>
    <p>
        PHP 8.1이 출시되었으며 많은 멋진 새 기능이 포함되어 있습니다. 그러나
        우리의 말을 그대로 받아들이지 마십시오.
        <a href="https://twitter.com/brendt_gd">Brent Roose</a> , PHP 커뮤니티
        회원 및 이러한 기능의 작성자인
        <a href="https://twitter.com/nikita_ppv">Nikita Popov</a> ,
        <a href="https://twitter.com/Crell">Larry Garfield</a> ,
        <a href="https://twitter.com/dstogov">Dmitry Stogov</a> ,
        <a href="https://twitter.com/matthieunapoli">Matthieu Napoli</a> 및
        <a href="https://twitter.com/_trowski">Aaron Piotrowski</a> 가 설명하는
        비디오를 보십시오.
    </p>
    <p align="center">
        <iframe
            width="560"
            height="315"
            src="https://www.youtube.com/embed/rgrQSmUiFJQ"
            title="유튜브 비디오 플레이어"
            frameborder="0"
            allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
            allowfullscreen=""
        ></iframe>
    </p>
</div>

Result

[비디오](/phpstorm/category/videos/) 새 비디오: PHP 8.1의 새로운 기능 
========================

![로만 프론스키](https://secure.gravatar.com/avatar/269798998e24876e4f3ea6f6d1effdc7?s=200&r=g) [로만 프론스키](https://blog.jetbrains.com/author/rpronskiy) 

 PHP 8.1이 출시되었으며 많은 멋진 새 기능이 포함되어 있습니다. 그러나 우리의 말을 그대로 받아들이지 마십시오. [Brent Roose](https://twitter.com/brendt_gd) , PHP 커뮤니티 회원 및 이러한 기능의 작성자인 [Nikita Popov](https://twitter.com/nikita_ppv) , [Larry Garfield](https://twitter.com/Crell) , [Dmitry Stogov](https://twitter.com/dstogov) , [Matthieu Napoli](https://twitter.com/matthieunapoli) 및 [Aaron Piotrowski](https://twitter.com/_trowski) 가 설명하는 비디오를 보십시오.

I want.

[비디오](/phpstorm/category/videos/) 새 비디오: PHP 8.1의 새로운 기능 
========================

![로만 프론스키](https://secure.gravatar.com/avatar/269798998e24876e4f3ea6f6d1effdc7?s=200&r=g) [로만 프론스키](https://blog.jetbrains.com/author/rpronskiy) 

 PHP 8.1이 출시되었으며 많은 멋진 새 기능이 포함되어 있습니다. 그러나 우리의 말을 그대로 받아들이지 마십시오. [Brent Roose](https://twitter.com/brendt_gd) , PHP 커뮤니티 회원 및 이러한 기능의 작성자인 [Nikita Popov](https://twitter.com/nikita_ppv) , [Larry Garfield](https://twitter.com/Crell) , [Dmitry Stogov](https://twitter.com/dstogov) , [Matthieu Napoli](https://twitter.com/matthieunapoli) 및 [Aaron Piotrowski](https://twitter.com/_trowski) 가 설명하는 비디오를 보십시오.

### Here!!
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/rgrQSmUiFJQ" title="유튜브 비디오 플레이어" width="560"></iframe>

The contents of 'iframe' should not be deleted, and I want to maintain 'iframe'.

Did this project help you today? Did it make you happy in any way?

This library made me convenient and helped me a lot to get good performance.