Improve GitLab embed

This commit is contained in:
Tom Moor
2024-03-23 22:30:08 -04:00
parent d8d60814ce
commit 8b6a760e02
3 changed files with 51 additions and 21 deletions

View File

@@ -1,30 +1,25 @@
import * as React from "react";
import styled from "styled-components";
import Frame from "../components/Frame";
import { EmbedProps as Props } from ".";
const Iframe = styled.iframe`
margin-top: 8px;
`;
function Gist(props: Props) {
const gistUrl = new URL(props.attrs.href);
const id = gistUrl.pathname.split("/")[2];
const gistLink = `https://gist.github.com/${id}.js`;
const gistScript = `<script type="text/javascript" src="${gistLink}"></script>`;
const styles =
"<style>*{ font-size:12px; } body { margin: 0; } .gist .blob-wrapper.data { max-height:150px; overflow:auto; }</style>";
"<style>*{ font-size:12px; } body { margin: 0; } .gist .blob-wrapper.data { max-height:300px; overflow:auto; }</style>";
const iframeHtml = `<html><head><base target="_parent">${styles}</head><body>${gistScript}</body></html>`;
return (
<Iframe
<Frame
src={`data:text/html;base64,${btoa(iframeHtml)}`}
className={props.isSelected ? "ProseMirror-selectednode" : ""}
frameBorder="0"
width="100%"
height="200px"
scrolling="no"
height="355px"
id={`gist-${id}`}
title="GitHub Gist"
dangerouslySkipSanitizeSrc
/>
);
}