#4260
Vlad
Member

We can do better than installing a dozen plugins or macros. The Execute Extension plugin can be configured to insert tags, but configuring it is a pain. Here is a script version of tagger, it generates popup menu with tags to insert:


// TAGGER.JSEE -- tagger and clip library, inserts strings around selected text or at the cursor.
// Usage: modify tables of tags at the start of file as you see fit.
// To add tags for other configurations: add new tables of tags and edit switch statement at the end.

// format: [string to insert before selection, string to insert after selection, optional menu label]
////////////////////////////////
HTML_TAGS = [
['<br>', '', ''],
['<p>', '</p>', ''],
[' ', '', 'space'],
['', '<hr>', ''],
['<!-- ', ' -->', 'comment'],
['', '', '-----------'], //menu separator
['<b>', '</b>', 'bold'],
['<i>', '</i>', 'italic'],
['<u>', '</u>', 'underline'],
['<pre>', '</pre>', ''],
['<blockquote>', '</blockquote>', 'blockquote'],
['<big>', '</big>', 'big'],
['<small>', '</small>', 'small'],
['<sup>', '</sup>', 'superscript'],
['<sub>', '</sub>', 'subscript'],
['<center>', '</center>', 'center'],
['', '', '-----------------'],
['<a href=#>', '</a>', 'Link'],
['<a name=>', '</a>', 'Mark'],
['<img src="" alt="" width="" height=>', '', 'Image'],
['', '', '--------------'],
['<table>', '</table>', 'table'],
['<tr>', '</tr>', ''],
['<td>', '</td>', ''],
['<ul>n', 'n</ul>', 'unorderd list'],
['<ol>n', 'n</ol>', 'orderd list'],
['<li>', '', ''],
['<dl>n', 'n<dl>', 'definition list'],
['<dt>', '', ''],
['<dd>', '', ''],
['', '', ''], //these are ignored
['', '', ''],
['', '', ''],
['', '', '']
];
////////////////////////////////
TEXT_TAGS = [
['Dear Collector:', '', ''],
['I would like to sell my kidney.', '', ''],
['Which way is to the soup kitchen?', '', ''],
['', '', ''],
['', '', '']
];
////////////////////////////////
UNIVERSAL_TAGS = [ //these should always be available
['', '', '--------------------'],
['/*', '*/', '/**/'],
['u03B2', '', 'beta'],
['', '', '']
];
/////////////////////////////////////////////////////////////////
function createMenu(tags) {
tags = tags.concat(UNIVERSAL_TAGS);
menu = CreatePopupMenu();
//populate menu
L = tags.length;
for (i=0; i<L; i++) {
if (tags[i].length!=3 || (tags[i][0]=="" && tags[i][1]=="" && tags[i][2]=="")) continue;
if (tags[i][2].slice(0,6)=="------")
menu.Add( '', 0, eeMenuSeparator );
else
menu.Add( tags[i][2] || tags[i][0] || tags[i][1], i+1 );
}
//display menu
result = menu.Track(0);
//insert tags
if (result!=0) insertTags(tags[result-1][0], tags[result-1][1]);
}

function insertTags(text_before, text_after) {
document.selection.Text = text_before + document.selection.Text + text_after;
// to do: restore selection
}

switch( document.ConfigName ) {
case("HTML"):
createMenu(HTML_TAGS);
break;
case("Text"):
createMenu(TEXT_TAGS);
break;
default:
createMenu(HTML_TAGS);
}