在EmEditor中插入UBB代码

   记不清自己是从什么时候起用EmEditor了,现在都更新到了7.0。
   EmEdtior方便、简单、易用,可以说是记事本的加强版,可惜这款日本开发却是付费软件,不过在网上可以找到XXOO版。
   众多的插件也扩展了EmEditor的使用功能。

   经常用EmEdtior写点东西然后发到论坛上,可是EmEdtior不支持WYSWYG,而且我也不是太常用WYSWYG,UBB就是我最佳的选择。
   不过呢,EmEditor没有UBB的插件,只有插入HTML的插件,于是想自己照着这些插件写。想拿源码却没得下载,作者也没开源。
   在官方网站上搜到论坛中的一帖,讨论的就是HTML的这个插件,而有一朋友回复,说可以不使用插件,就用EmEdtior自带的宏功能,就可以完成,然后贴了一大段宏代码:
下载: Tagger.jsee
  1. // TAGGER.JSEE -- tagger and clip library, inserts strings around selected text or at the cursor.
  2.  // Usage: modify tables of tags at the start of file as you see fit.
  3.  // To add tags for other configurations: add new tables of tags and edit switch statement at the end.
  4.  
  5.  // format: [string to insert before selection, string to insert after selection, optional menu label]
  6.  ////////////////////////////////
  7.  HTML_TAGS = [
  8.  ['<br>', '', ''],
  9.  ['<p>', '</p>', ''],
  10.  [' ', '', 'space'],
  11.  ['', '<hr>', ''],
  12.  ['<!-- ', ' -->', 'comment'],
  13.  ['', '', '-----------'], //menu separator
  14.  ['<b>', '</b>', 'bold'],
  15.  ['<i>', '</i>', 'italic'],
  16.  ['<u>', '</u>', 'underline'],
  17.  ['<pre>', '</pre>', ''],
  18.  ['<blockquote>', '</blockquote>', 'blockquote'],
  19.  ['<big>', '</big>', 'big'],
  20.  ['<small>', '</small>', 'small'],
  21.  ['<sup>', '</sup>', 'superscript'],
  22.  ['<sub>', '</sub>', 'subscript'],
  23.  ['<center>', '</center>', 'center'],
  24.  ['', '', '-----------------'],
  25.  ['<a href="#">', '</a>', 'Link'],
  26.  ['<a name="">', '</a>', 'Mark'],
  27.  ['<img src="" alt="" width="" height="">', '', 'Image'],
  28.  ['', '', '--------------'],
  29.  ['<table>', '</table>', 'table'],
  30.  ['<tr>', '</tr>', ''],
  31.  ['<td>', '</td>', ''],
  32.  ['<ul>n', 'n</ul>', 'unorderd list'],
  33.  ['<ol>n', 'n</ol>', 'orderd list'],
  34.  ['<li>', '', ''],
  35.  ['<dl>n', 'n<dl>', 'definition list'],
  36.  ['<dt>', '', ''],
  37.  ['<dd>', '', ''],
  38.  ['', '', ''], //these are ignored
  39.  ['', '', ''],
  40.  ['', '', ''],
  41.  ['', '', '']
  42.  ];
  43.  ////////////////////////////////
  44.  TEXT_TAGS = [
  45.  ['Dear Collector:', '', ''],
  46.  ['I would like to sell my kidney.', '', ''],
  47.  ['Which way is to the soup kitchen?', '', ''],
  48.  ['', '', ''],
  49.  ['', '', '']
  50.  ];
  51.  ////////////////////////////////
  52.  UNIVERSAL_TAGS  = [ //these should always be available
  53.  ['', '', '--------------------'],
  54.  ['/*', '*/', '/**/'],
  55.  ['u03B2', '', 'beta'],
  56.  ['', '', '']
  57.  ];
  58.  /////////////////////////////////////////////////////////////////
  59.  function createMenu(tags) {
  60.  tags = tags.concat(UNIVERSAL_TAGS);
  61.  menu = CreatePopupMenu();
  62.  //populate menu
  63.  L = tags.length;
  64.  for (i=0; i<L; i++) {
  65.  if (tags<i>.length!=3 || (tags[i][0]=="" && tags[i][1]=="" && tags[i][2]=="")) continue;
  66.  if (tags[i][2].slice(0,6)=="------")
  67.  menu.Add( '', 0, eeMenuSeparator );
  68.  else
  69.  menu.Add( tags[i][2] || tags[i][0] || tags[i][1], i+1 );
  70.  }
  71.  //display menu
  72.  result = menu.Track(0);
  73.  //insert tags
  74.  if (result!=0) insertTags(tags[result-1][0], tags[result-1][1]);
  75.  }
  76.  
  77.  function insertTags(text_before, text_after) {
  78.  document.selection.Text = text_before + document.selection.Text + text_after;
  79.  // to do: restore selection
  80.  }
  81.  
  82.  switch( document.ConfigName ) {
  83.  case("HTML"):
  84.  createMenu(HTML_TAGS);
  85.  break;
  86.  case("Text"):
  87.  createMenu(TEXT_TAGS);
  88.  break;
  89.  default:
  90.  createMenu(HTML_TAGS);
  91.  }

   这段宏的意思就是,选定一段文字或不选定,点击宏→功能项,就完成插入代码、文字功能。功能项在下说明。
   如1:我是。选定字,然后点击宏→功能项(内容为['实验小白','','']),就变成了:我是实验小白鼠。
   如2:我是小白,选定小白两字,然后点击宏→功能项(内容为['实验','鼠',''],就变成了:我是实验小白鼠。
   就这么简单。

   TAGS有三个部分:HTML_TAGS、TXT_TAGS、UNIVERSAL_TAGS。
   HTML_TAGS是HTML语言标识符,只有文件扩展名为HTML时,才会显示。
   TXT_TAGS是文本标题符,只有文本文件时,才会显示。
   UNIVERSAL_TAGS是通用标题符,不管扩展名,都会显示。

   代码的格式为:[左标识符,右标识符,菜单文字]
   上面也举例说明了这段代码的使用,在此不具体说了。

   明白代码格式后,照葫芦画瓢,把UBB代码写出来:
下载: ubb.txt
  1. ['<b>', '</b>', '粗体'],
  2.      ['[I]', '</i>', '斜体'],
  3.      ['<u>', '</u>', '下划线'],
  4.      ['[color=]', '[/color]', '颜色'],
  5.      ['[backcolor=]', '[/backcolor]', '背景'],
  6.      ['<div align=left>', '</div>', '左对齐'],
  7.      ['<div align=center>', '</div>', '居中'],
  8.      ['<div align=right>', '</div>', '右对齐'],
  9.      ['<img src=', '>', '图片'],
  10.      ['[url]', '[/url]', '链接'],
  11.      ['[url=]', '[/url]', '自定义链接'],
  12.      ['[code ]', '[/code]', '代码'],
  13.      ['[quote ]', '[/quote]', '引用'],

   PS:请删掉[code[quote后的空格。
   按个人需要,把这段代码加到*_TAGS内就行了。注明最后的,
   当然,这段代码只是部分的UBB代码,更多的按个人需要自行添加。

   使用时,最好把宏工具栏显示出来,然后,自定义宏,选择TAGGER.JSEE这个文件。
attachments/200804/4944775520.gif

   搞定后就显示在工具栏上了
attachments/200804/4317151011.gif

   测试一下
attachments/200804/4038882653.gif

   Oh yeah!一直想让EmEditor支持UBB的,终于实现了。
   不过呢,就光用这个宏还不能完全实现全部的UBB功能,比如颜色,这个就需要取色器插件了。
   网上有EmEditor的插件汉化包下载,里面就有,或到官方网站下载

2008-4-20 21:8:46
引用通告地址: 点击获取引用地址
标签: 软件 UBB EmEditor
评论: 0 | 引用: 0 | 阅读: 698
 加入网摘
发表评论
昵 称(*): 密 码:
网 址: 邮 箱:
选 项:    
内 容(*):