[Marked] If there is an image in the html

pish
2 min readDec 26, 2022

--

markdown

Used library: https://marked.js.org/ (javascript)

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

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

in https://delog.io

Resolution (Marked)

html(html) {
if (html.includes('http')) {
if (html.includes('.JPG')) {
html = html.replace(/http/gi, ``);
} else if (html.includes('.jpg')) {
html = html.replace(/http/gi, ``);
} else if (html.includes('.png')) {
html = html.replace(/http/gi, ``);
} else if (html.includes('.jpeg')) {
html = html.replace(/http/gi, ``);
}
}
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!.

--

--

pish
pish

Written by pish

https://delog.io/@pishio Publish your creations and get rewards on a fully decentralized platform.

No responses yet