MarkdownLinkUtil.js 645 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * Utility for markdown link
  3. */
  4. class MarkdownLinkUtil {
  5. constructor() {
  6. this.linePartOfTableRE = /^([^\r\n|]*)\|(([^\r\n|]*\|)+)$/;
  7. this.isInTable = this.isInTable.bind(this);
  8. }
  9. getSelectedTextInEditor(editor) {
  10. return editor.getDoc().getSelection();
  11. }
  12. replaceFocusedMarkdownLinkWithEditor(editor, link) {
  13. editor.getDoc().replaceSelection(link);
  14. }
  15. isInTable(editor) {
  16. const curPos = editor.getCursor();
  17. return this.linePartOfTableRE.test(editor.getDoc().getLine(curPos.line));
  18. }
  19. }
  20. // singleton pattern
  21. const instance = new MarkdownLinkUtil();
  22. Object.freeze(instance);
  23. export default instance;