UNPKG

@uiw/react-markdown-editor

Version:

A markdown editor with preview, implemented with React.js and TypeScript.

48 lines 1.54 kB
import { jsx as _jsx } from "react/jsx-runtime"; export var header = { name: 'header', keyCommand: 'header', button: { 'aria-label': 'Add header text' }, icon: /*#__PURE__*/_jsx("svg", { fill: "currentColor", viewBox: "0 0 448 512", height: "13", width: "13", children: /*#__PURE__*/_jsx("path", { d: "M448 448c0 17.69-14.33 32-32 32h-96c-17.67 0-32-14.31-32-32s14.33-32 32-32h16V272H112v144h16c17.67 0 32 14.31 32 32s-14.33 32-32 32H32c-17.67 0-32-14.31-32-32s14.33-32 32-32h16V96H32C14.33 96 0 81.69 0 64s14.33-32 32-32h96c17.67 0 32 14.31 32 32s-14.33 32-32 32h-16v112h224V96h-16c-17.67 0-32-14.31-32-32s14.33-32 32-32h96c17.67 0 32 14.31 32 32s-14.33 32-32 32h-16v320h16c17.7 0 32 14.3 32 32z" }) }), execute: _ref => { var { state, view } = _ref; if (!state || !view) return; var lineInfo = view.state.doc.lineAt(view.state.selection.main.from); var mark = '#'; var matchMark = lineInfo.text.match(/^#+/); if (matchMark && matchMark[0]) { var txt = matchMark[0]; if (txt.length < 6) { mark = txt + '#'; } } if (mark.length > 6) { mark = '#'; } var title = lineInfo.text.replace(/^#+/, ''); view.dispatch({ changes: { from: lineInfo.from, to: lineInfo.to, insert: mark + " " + title }, // selection: EditorSelection.range(lineInfo.from + mark.length, lineInfo.to), selection: { anchor: lineInfo.from + mark.length + 1 } }); } };