Skip to content

Commit

Permalink
editor: add support for converting md link syntax to link on paste (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
alihamuh authored Dec 18, 2023
1 parent d136540 commit ff36f02
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions packages/editor/src/extensions/link/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,36 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { markInputRule } from "@tiptap/core";
import { markInputRule, markPasteRule } from "@tiptap/core";
import TiptapLink from "@tiptap/extension-link";

const linkRegex = /(?:__|[*#])|\[(.*?)\]\(.*?\)/gm;
const regExp = /\((.*?)\)/;
const regExp = /\((.*?)\)/gm;

export const Link = TiptapLink.extend({
addInputRules() {
return [
markInputRule({
find: linkRegex,
type: this.type,
getAttributes: (match) => ({
href: regExp.exec(match[0])?.[1]
})
getAttributes: (match) => {
return {
href: regExp.exec(match[0])?.[1]
};
}
})
];
},
addPasteRules() {
return [
markPasteRule({
find: linkRegex,
type: this.type,
getAttributes(match) {
return {
href: regExp.exec(match[0])?.[1]
};
}
})
];
}
Expand Down

0 comments on commit ff36f02

Please sign in to comment.