All files / src/parsers image.ts

100% Statements 5/5
54.54% Branches 6/11
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31    1x 3x 3x 3x   3x                                              
import { OutputBlockData } from "@editorjs/editorjs";
 
export const image = ({ data }: OutputBlockData): string => {
  const url = data.file?.url || data.url || "";
  const caption = data.caption || "";
  const isCaptionBlank = !caption || caption.trim() === "";
 
  return `<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr>
        <td align="center" style="padding-top:20px;${isCaptionBlank ? "padding-bottom:20px;" : "padding-bottom:5px;"}">
          <img 
            src="${url}" 
            alt="${caption}" 
            width="500" 
            height="auto" 
            style="display:block; max-width:500px; width:100%; height:auto; border:0; outline:none; text-decoration:none;" 
          />
        </td>
      </tr>
      ${
        !isCaptionBlank
          ? `<tr>
          <td align="center" style="padding-bottom:20px;">
            <p style="margin:0; font-size:14px; line-height:1; color:#999999; text-align:center;">${caption}</p>
          </td>
        </tr>`
          : ""
      }
    </table>`;
};