Format.ts 796 B

123456789101112131415161718
  1. import formatSVG from "../../assets/icons/outdent.svg";
  2. import {formatRender} from "../sv/formatRender";
  3. import {getEventName} from "../util/compatibility";
  4. import {getMarkdown} from "../util/getMarkdown";
  5. import {getSelectPosition} from "../util/selection";
  6. import {MenuItem} from "./MenuItem";
  7. export class Format extends MenuItem {
  8. constructor(vditor: IVditor, menuItem: IMenuItem) {
  9. super(vditor, menuItem);
  10. this.element.children[0].innerHTML = menuItem.icon || formatSVG;
  11. this.element.children[0].addEventListener(getEventName(), (event) => {
  12. formatRender(vditor, vditor.lute.FormatMd( getMarkdown(vditor)),
  13. getSelectPosition(vditor.sv.element, getSelection().getRangeAt(0)));
  14. event.preventDefault();
  15. });
  16. }
  17. }