suseona avatar

[Marked] If there is an image in the html

pishio

Published: 26 Dec 2022 › Updated: 26 Dec 2022[Marked] If there is an image in the html

[Marked] If there is an image in the html

alt

Used library: https://marked.js.org/

Emergency handling for cases where there is an image in the html tag during the mark down case.

(Unrefined code, if you have a good method, please share it in the comments)

Sample

Let's look at a sample case first.
The mark down is written as below, and when it is drawn, it should come out like the image below.

mark down

<table>
<tr>
<td>https://images.hive.blog/DQmWwFSXs6264npQxbEnBmYkjHCXDi8CGhUKY1DDJ8xBXYy/DSC_1973.JPG
<td>https://images.hive.blog/DQmQRExbzza6Mv2dbtDfETtKMEDH9ozy9zk8vEQuTWiC3Gk/DSC_1974.JPG
</tr>
</table>

markdown normal rendering

alt

Below is the situation before adding the exception code. The image is being exposed as text.

A bug fix is urgently needed.

markdown error rendering

alt
in https://delog.io

Resolution (Marked)

      html(html) {
        if (html.includes('http')) {
          if (html.includes('.JPG')) {
            html = html.replace(/http/gi, `);
            html = html.replace(/.JPG/gi, `.JPG"/>`);
          } else if (html.includes('.jpg')) {
            html = html.replace(/http/gi, `);
            html = html.replace(/.jpg/gi, `.jpg"/>`);
          } else if (html.includes('.png')) {
            html = html.replace(/http/gi, `);
            html = html.replace(/.png/gi, `.png"/>`);
          } else if (html.includes('.jpeg')) {
            html = html.replace(/http/gi, `);
            html = html.replace(/.jpeg/gi, `.jpeg"/>`);
          }
        }
        return `${html}`;
      },

The above code came out.
It's a very ignorant code, but I applied it because I didn't have time.

If you look at the contents, since html is included in the markdown, the html function is used, and the image part is surrounded by tags.

Once solved!.

web3.0 blogging service

https://delog.io

Witness vote

pishio@pishio https://vote.hive.uno/@pishio

Leave [Marked] If there is an image in the html to:

Written by

Witness, Creator of blog.suseona.com

Read more #hive-152717 posts


Best Posts From suseona

We have not curated any of pishio's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From suseona