[Marked] If there is an image in the html

pishio(69)
Published in
dev
Words
154
Reading
1 min
Listen
Play
4y

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