@uiw/react-markdown-editor
Version:
A markdown editor with preview, implemented with React.js and TypeScript.
52 lines (51 loc) • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.header = void 0;
var _jsxRuntime = require("react/jsx-runtime");
var header = exports.header = {
name: 'header',
keyCommand: 'header',
button: {
'aria-label': 'Add header text'
},
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
fill: "currentColor",
viewBox: "0 0 448 512",
height: "13",
width: "13",
children: /*#__PURE__*/(0, _jsxRuntime.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: function execute(_ref) {
var state = _ref.state,
view = _ref.view;
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: "".concat(mark, " ").concat(title)
},
// selection: EditorSelection.range(lineInfo.from + mark.length, lineInfo.to),
selection: {
anchor: lineInfo.from + mark.length + 1
}
});
}
};