function addTag(tag) {
const textarea = document.getElementById('postContent');
if (textarea) {
switch (tag) {
case 'read_more':
textarea.value += "\n\n";
break;
case 'img':
textarea.value += "\n
\n";
break;
case 'list':
textarea.value += "\n
\n";
break;
}
}
}
function wrapSelectedTextWithTag(tag) {
const textarea = document.getElementById('postContent');
const selectionStart = textarea.selectionStart;
const selectionEnd = textarea.selectionEnd;
const before = textarea.value.substring(0, selectionStart);
const selectedText = textarea.value.substring(selectionStart, selectionEnd);
const after = textarea.value.substring(selectionEnd);
const newValue = before + `<${tag}>` + selectedText + `${tag}>` + after;
textarea.value = newValue;
const newPos = selectionStart + tag.length + 2 + selectedText.length + tag.length + 3;
textarea.focus();
textarea.setSelectionRange(selectionStart, newPos);
}