Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<pre class="language-"><code> #215

Closed
kbitlive opened this issue Nov 17, 2021 · 5 comments · Fixed by #238
Closed

<pre class="language-"><code> #215

kbitlive opened this issue Nov 17, 2021 · 5 comments · Fixed by #238

Comments

@kbitlive
Copy link

kbitlive commented Nov 17, 2021

Version(s) affected

5.0.2

Description

How to reproduce

html

<pre class="language-"><code>GET /announcements
 </code></pre>

after convert

```
<pre class="language-">```
GET /announcements

```
```
@52fhy
Copy link

52fhy commented Feb 10, 2022

  $markdown_show = $converter->convert($content);
  // strip_tags pre
  $markdown_show = strip_tags($markdown_show);

@mhadaily
Copy link

mhadaily commented Jan 13, 2023

Depends you need <pre> tag or not. you can do this for now. I will see if I can send a PR to fix this issue

If you need to remove pre, use a function to stripe it out - strip_tags_only needs to be written

$clean_content = str_replace(array("```\n```"), array("```\n"), strip_tags_only($markdown_content, 'pre'));

If not and you want to close the tag

$clean_content = str_replace(array("```\n```", "```\n<pre"), array("```\n</pre>", "\n<pre"), $markdown_content);

a work around of this bug for now.

@mhadaily
Copy link

mhadaily commented Jan 13, 2023

I have done a better solution which I want to share
in fact, if you have HTML already. you can removecode tag and then replace pre tag to code since, it has language class too. it will be way better because the output will have backticks with no pre tag and with proper language assigned.

$html_content = $post['content']['rendered'];
		$html_remove_code_tag = strip_tags_only($html_content, array('code'));
		$html_pre_to_code_tag = str_replace(array('<pre','</pre>'), array('<pre><code','</code></pre>'), $html_remove_code_tag);
		$markdown_content = $daextulmap_converter->convert( $html_pre_to_code_tag );

$echo $markdown_content;

I think it's better that the library does this. but for now. it works.

@kito-inv
Copy link

I think this issue comes from this line

$preContent = \str_replace(['<pre>', '</pre>'], '', $preContent);

It's not considering any attributes the pre tag could have like it's done in here
$code = \preg_replace('/<code\b[^>]*>/', '', $code);

I might be able to submit a PR later

stbneb added a commit to stbneb/html-to-markdown that referenced this issue Jul 12, 2023
@colinodell colinodell linked a pull request Jul 12, 2023 that will close this issue
@colinodell
Copy link
Member

Fixed in version 5.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants