Path: blob/master/src/packages/frontend/editors/slate/elements/paragraph/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";67export interface Paragraph extends SlateElement {8type: "paragraph";9}1011register({12slateType: "paragraph",1314toSlate: ({ token, children, state }) => {15if (token.hidden) {16// this is how markdown-it happens to encode the17// idea of a "tight list"; it wraps the items18// in a "hidden" paragraph. Weird and annoying,19// but I can see why, I guess. Instead, we just20// set this here, and it propagates up to the21// enclosing list. Whichever tightness is first takes22// precedence.23state.tight = true;24}25return { type: "paragraph", children } as Paragraph;26},2728StaticElement: ({ attributes, children, element }) => {29if (element.type != "paragraph") throw Error("bug");30// textIndent: 0 is needed due to task lists -- see slate/elements/list/list-item.tsx31return (32<p {...attributes}>33<span style={{ textIndent: 0 }}>{children}</span>34</p>35);36},3738sizeEstimator({ node, fontSize }): number {39const numLines = Math.round(JSON.stringify(node).length / 60);40return numLines * 1.4 * fontSize + fontSize;41},42});434445