2

How can I define custom html tags in ckeditor.

  • When user select a word e.g. Apple.
  • Then I want to replace this with profileTag Apple /profileTag".
  • But if the selected word already has a tag then it should append the profile tag.
  • For example if anchorTag Apple /anchorTag then after user selection it will be profileTag anchorTag Apple /anchorTag /profileTag.

The above thing is working. But when I execute the below code the output is null in case of custom html tag like profile tag.

var current_selected_element = editor.getSelection().getSelectedElement(); console.log(current_selected_element);

1
  • Appending the tags is working. But the output of below code is null. var current_selected_element=editor.getSelection().getSelectedElement(); console.log(current_selected_element);
    – Lalit
    Dec 11, 2015 at 7:36

1 Answer 1

4

The problem is that CKeditor's advanced content filter is filtering out your custom tags ... you're going to have to configure the ACF to accept the custom tags your plugin is creating and inserting into the DOM. There are a couple ways this can be done. The most basic would be to implement config.extraAllowedContent = 'profile' or whatever the name of your custom markup will be. Otherwise you can work with the global CKEditor.filter object. There's more documentation on the CKEDITOR.filter object here.

2
  • thanks it helped me a lot. How can I remove custom html tags when user select a text. Like if I have 2 custom tags and one standard html tag customtag1_start customtag2_start anchortag_start Apple anchortag_end customtag2_end customtag1_end. Now I have to remove one custom html tag. It can be anyone customtag1 or customtag2.
    – Lalit
    Dec 16, 2015 at 10:09
  • If you are needing to easily remove elements that you've custom added to the page, I would look into using the CKeditor widget plugin interface. That lets you define a template and upcast that template that is used as an object that can be easily placed and deleted on the page.
    – Jason
    Dec 16, 2015 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.