Path: blob/master/src/packages/frontend/editors/slate/elements/html/index.tsx
1698 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { register, SlateElement } from "../register";6import { toSlate as toSlateImage } from "../image";7import HTML from "@cocalc/frontend/components/html-ssr";89export interface HtmlInline extends SlateElement {10type: "html_inline";11isInline: true;12isVoid: true;13html: string;14}1516export interface HtmlBlock extends SlateElement {17type: "html_block";18isInline: false;19isVoid: true;20html: string;21}2223const StaticElement = ({ attributes, element }) => {24const html = ((element.html as string) ?? "").trim();25if (element.type == "html_inline") {26return (27<span {...attributes} style={{ display: "inline" }}>28<HTML inline value={html} />29</span>30);31} else {32return (33<div {...attributes}>34<HTML value={html} />35</div>36);37}38};3940register({41slateType: ["html_inline", "html_block"],4243toSlate: ({ type, token, children }) => {44// Special case of images (one line, img tag);45// we use a completely different function.46if (47token.content.startsWith("<img ") &&48token.content.trim().split("\n").length <= 149) {50return toSlateImage({ type, token, children });51}52return {53type: token.type,54isVoid: true,55isInline: token.type == "html_inline",56html: token.content,57children,58};59},6061StaticElement,62});636465