-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
If I have a column value Lorem ipsum
and I change that into <a href="#">Lorem</a> ipsum <em>dolor</em> sit amet
the text will be updated but with stripped html. Is it possible to have the HTML intact?
I am not sure if this is WP DB Table Editor's issue or Slick does it?
I was thinking about recreating shortcuts for HTML tags like we can do in WordPress. When I select a part of text and press CTRL+i
the text should change from Lorem ipsum dolor sit amet
to Lorem ipsum <em>dolor</em> sit amet
.
The following code is maybe a mess but it works for surrounding text with italics.
// The popup editor doesn't exist in DOM unless user triggers editing process,
// and those divs don't even have any ID or class on them this is an improvisation to target it
jQuery("html").on("click", function() {
jQuery("body > div > textarea").on("keydown", function(e) {
var textarea = jQuery(this);
if (e.ctrlKey && e.key == "i") {
// get length of text
var length = textarea.val().length;
// starting text
var start_point = textarea[0].selectionStart;
// ending text
var end_point = textarea[0].selectionEnd;
// get selected text
var selectedText = jQuery(this)
.val()
.substring(start_point, end_point);
var replacement = "<em>" + selectedText + "</em>";
// Replace text
textarea.val(
textarea.val().substring(0, start_point) +
replacement +
textarea.val().substring(end_point, length)
);
// Since there is a bug with double inserting <em></em>, remove those empty ones :)
var newText = textarea.val().replace("<em></em>", "");
textarea.val(newText);
}
});
});
Metadata
Metadata
Assignees
Labels
No labels