xdan / jodit

Jodit - Best WYSIWYG Editor for You
https://xdsoft.net/jodit/
MIT License
1.67k stars 351 forks source link

How to add inline styles to bold fonts #1090

Open alindas opened 7 months ago

alindas commented 7 months ago

When using the bold option on the toolbar to bold the text, I noticed that it added a strong label to the selected dom text, and I want to add an inline style to the strong label. What can I do?

I have tried listening for "bold" and "common: bold" events, but none of them worked? Do you provide any callback functions? Where can I implement my ideas

kemotx90 commented 7 months ago

you can create a custom plugin for your job

import {Jodit} from "jodit";

Jodit.plugins.add('my-plugin', {
  init(editor: Jodit) {
    editor.events.on('afterCommand', function (command: any): false | void {

      //Do nothing if not clicked bold
      if (command != 'bold') return;

      const current = editor.selection.current()?.parentNode;
      //do your task here on current...
    }
  },
  destruct(editor: Jodit) {
    editor.events.off('beforeCommand');
  }
})
alindas commented 7 months ago

you can create a custom plugin for your job

import {Jodit} from "jodit";

Jodit.plugins.add('my-plugin', {
  init(editor: Jodit) {
    editor.events.on('afterCommand', function (command: any): false | void {

      //Do nothing if not clicked bold
      if (command != 'bold') return;

      const current = editor.selection.current()?.parentNode;
      //do your task here on current...
    }
  },
  destruct(editor: Jodit) {
    editor.events.off('beforeCommand');
  }
})

nice bro! i will try it soon