Path: blob/master/src/packages/frontend/editors/slate/elements/references/editable.tsx
1698 views
/*1This is not actually editable. It just shows there references2and the hover text over the word "References" says that you need3to edit markdown source. Also, you can't type [Sage][2]space and4have it autoformat as a reference (say), since there references5aren't known to the autoformatter. Both of those are things6to do later. The point of the below is just to not mangle content7that uses reference links.89Another point -- it's currently possible to move the cursor after the10references at the bottom of the document and delete them all. Maybe that11is good, but it could be confusing. Undo will put them back though.12*/1314import { register } from "../register";15import { CodeMirrorStatic } from "@cocalc/frontend/jupyter/codemirror-static";16import infoToMode from "../code-block/info-to-mode";17import { Tooltip } from "antd";1819function fromSlate({ node }) {20if (!node.value) return "";21let v: string[] = [];22for (const name in node.value) {23const { title, href } = node.value[name];24let line = `[${name}]: ${href ? href : "<>"}`;25if (title) {26line += ` '${title.replace(/'/g, "\\'")}'`;27}28v.push(line);29}30return "\n" + v.join("\n") + "\n";31}3233register({34slateType: "references",3536Element: ({ attributes, children, element }) => {37if (element.type != "references") throw Error("references");38return (39<div {...attributes} contentEditable={false}>40<hr />41<div style={{ color: "#666", fontWeight: "bold", fontSize: "large" }}>42<Tooltip title="The references below must be edited in the markdown source.">43References44</Tooltip>45</div>46<CodeMirrorStatic47no_border48style={{ marginBottom: 0 }}49options={{ mode: infoToMode("md"), lineWrapping: true }}50value={fromSlate({ node: element })}51/>52{children}53</div>54);55},5657fromSlate,58});596061