@uiw/react-markdown-editor
Version:
A markdown editor with preview, implemented with React.js and TypeScript.
60 lines (53 loc) • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.header = void 0;
var _jsxRuntime = require("react/jsx-runtime");
var header = {
name: 'header',
keyCommand: 'header',
button: {
'aria-label': 'Add header text'
},
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
width: "12",
height: "12",
viewBox: "0 0 512 512",
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
fill: "currentColor",
d: "M496 80V48c0-8.837-7.163-16-16-16H320c-8.837 0-16 7.163-16 16v32c0 8.837 7.163 16 16 16h37.621v128H154.379V96H192c8.837 0 16-7.163 16-16V48c0-8.837-7.163-16-16-16H32c-8.837 0-16 7.163-16 16v32c0 8.837 7.163 16 16 16h37.275v320H32c-8.837 0-16 7.163-16 16v32c0 8.837 7.163 16 16 16h160c8.837 0 16-7.163 16-16v-32c0-8.837-7.163-16-16-16h-37.621V288H357.62v128H320c-8.837 0-16 7.163-16 16v32c0 8.837 7.163 16 16 16h160c8.837 0 16-7.163 16-16v-32c0-8.837-7.163-16-16-16h-37.275V96H480c8.837 0 16-7.163 16-16z"
})
}),
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
}
});
}
};
exports.header = header;
//# sourceMappingURL=header.js.map