BBCode Syntax?

Syntax highlighting, code folding, brace matching, code indenting, and function list

BBCode Syntax?

Postby Mulsiphix » Wed Nov 29, 2006 9:23 am

Any chance anybody has created their own syntax highlighting code for BBCode?
User avatar
Mulsiphix
Newbie
 
Posts: 2
Joined: Mon Dec 20, 2004 12:00 am

Re: BBCode Syntax?

Postby Mofi » Wed Nov 29, 2006 11:00 am

While writing on the Taglist file for BBCode I tried also to write a wordfile for BBCode. But I was forced to give it up because BBCode needs a mechanism which UltraEdit only supports for HTML.

In HTML (HTML_LANG) < and </ and > are word delimiters but can be additionally also part of a word specification. This special handling would be also needed for [ and [/ and [ but is currently (UE v12.20a+4) not supported by UE/UES.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4056
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: BBCode Syntax?

Postby Mulsiphix » Wed Nov 29, 2006 11:41 am

I hate to hear such news but I appreciate the information. Many thanks.
User avatar
Mulsiphix
Newbie
 
Posts: 2
Joined: Mon Dec 20, 2004 12:00 am

BBCode Language Definition

Postby AEon » Fri Sep 26, 2008 8:50 am

Last time I checked (UltraEdit v10.20c) it was not really possible (and it's still problematic) to create a language entry for the meta-HTML language many modern forums use, including this one, called BBcode. For those folks interested in syntax highlighting while editing offline in UE here is the entry wordfile.txt code:

Code: Select all
/L20"BBCode" EnableSpellasYouType Nocase String Chars = ` File Extensions = UBB
/Delimiters = ~!@$%^&()_+=|\{}[]:;"'<> ,   .?
/Indent Strings = ""
/Unindent Strings = ""
/Open Fold Strings = "[CODE]" "[INDENT]" "[LIST]" "[QUOTE]"
/Close Fold Strings = "[/CODE]" "[/INDENT]" "[/LIST]" "[/QUOTE]"
/C1"Tags code indent list quote"
// /CODE /INDENT /LIST /QUOTE
CODE
INDENT
LIST
QUOTE
[
]
/C2"Tags color img size url"
*
// /COLOR /IMG /SIZE /URL
COLOR
IMG
SIZE
URL
/C3"Operators and colors"
=
black
blue
green
orange
red
/C4"Tags B I U"
// /B /I /U
B
I
U

Info:
  • Be sure to update the extension part (i.e. File Extensions = UBB) in the above /L definition. I name BBCode files .UBB for some historical reason (maybe "Ultra Bulletin Board", or something).

  • I spread out the color coding so that tags for indentation (code, indent, list, quote) have one color, special tags that should stand out (color, img, size, url) another color, and finally your standard text styles (bold, italics, underline) a third.

  • The block oriented tags (code, indent, list, quote) support folding.

  • In the /C3"Operators and colors" section you can explicitly name colors for highlighting if you like.

  • If you want you could auto-indent/outdent the block tags by replacing:

    Code: Select all
    /Indent Strings = ""
    /Unindent Strings = ""

    with

    Code: Select all
    /Indent Strings = "[CODE]" "[INDENT]" "[LIST]" "[QUOTE]"
    /Unindent Strings = "[/CODE]" "[/INDENT]" "[/LIST]" "[/QUOTE]"

    Issue: The *indentation* will work, but not the outdenting of e.g. [/code]. I have no idea why that is.

    I personally do not use such indentation because the forums often force you to manually delete empty lines or indentations to actually properly space the content. And each forum seems to have its own set of inconsistent rules.

  • Alas convenient code like
    Code: Select all
    /Marker Characters = "[]"

    simply highlighting everything between any [ and ], i.e. the meta-HTML tabs, is not allowed and does not work. But anyway I prefer to color code the specific tags by function (indentation, special, style).

  • To properly implement BBCode, UE would need to have a special language tag treating tags in [] specially, i.e. like this is the case for HTML and <> using HTML_LANG.

  • There is another issue with String Chars = `. If you do not define a string delimiter (i.e. String Chars = ), the whole above highlighting will mess up. If you simply delete the parameter from the /L line, the default delimiters " and ' will be used.

    Is there actually a way to completely turn off String Chars =?

If you want to do your own local testing, here is my test.ubb file:

Code: Select all
ladida [code]ladida[/code]
LADIDA [CODE]LADIDA[/CODE] LADIDA
ladida [quote]ladida[/quote]
LADIDA [QUOTE]LADIDA[/QUOTE] LADIDA
ladida [indent]ladida[/indent]
ladida [INDENT]LADIDA[/INDENT] LADIDA

[list]
[*] blah moo
[/list]

[LIST]
[*] BLAH MOO
[/LIST]

going [b]bold[/b], [i]italics[/i], [u]underline[/u]
going [B]BOLD[/B], [I]ITALICS[/I], [U]UNDERLINE[/U]

[color=green]coloring[/color]
[color=red]coloring[/color]
[IMG]http://www.blah.com/image.png[/IMG]
[SIZE=1]http://www.blah.com/image.png[/SIZE]
[URL]http://www.blah.com/image.php[/URL]
[URL=http://www.blah.com/image.php]To the Image Page[/URL]


If you spot any mistakes in the code don't hesitate to point out corrections.

Hope this is of some use.

AEon
User avatar
AEon
Newbie
 
Posts: 9
Joined: Wed Sep 24, 2008 1:12 pm
Location: Bavarian Forest

Re: BBCode Language Definition

Postby Mofi » Sun Sep 28, 2008 4:21 am

Here are my suggestions:

  1. Use Noquote instead of String Chars = ` to turn off syntax highlighting for strings.
  2. Add to color group 2 the string /* as shown below:
    // /* /COLOR /IMG /SIZE /URL
    because forums using phpBB v3.0 and later like this one use [/*] in lists for the closing </li> element.
  3. At color group 3 add the color names for all 16 VGA standard colors + orange specified in CSS 2.1:
    aqua
    black blue
    fuchsia
    gray green
    lime
    maroon
    navy
    olive orange
    purple
    red
    silver
    teal
    white
    yellow
  4. I don't have problems with
    /Indent Strings = "[CODE]" "[INDENT]" "[LIST]" "[QUOTE]"
    /Unindent Strings = "[/CODE]" "[/INDENT]" "[/LIST]" "[/QUOTE]"

    Indenting and unidenting works perfect.
  5. Do you know the BBCode tag list file I have written and sent to IDM and therefore is on the Extra Downloads page?
    If you look into this file you will find some more common BBCode tags which should be highlighted too like [hr][/hr].
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4056
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: BBCode Language Definition

Postby AEon » Sun Sep 28, 2008 7:06 am

Mofi,

I integrated all your suggestions. Even though I have written several extensive forum FAQs (KotOR, KotOR II, Two Worlds etc.) your BBCode Tag List contained quite a few tags I have never seen in modern forums. But I integrated them, just to be complete.

BTW: And I have figured out why the "out-denting" did not work for me. It has to do with the way I type: 1. [ ] 2. LEFT ARROW, 3. /INDENT, 4. RIGHT ARROW, 5. RETURN... but this way the out-denting does not catch the definition.

Here is v2.0 of the BBCode Language for the wordlfile.txt file:

Code: Select all
/L20"BBCode" EnableSpellasYouType Noquote Nocase File Extensions = UBB
/Delimiters = ~!@$%^&()_+=|\{}[]:;"'<> ,   .?
/Indent Strings = "[ALIGN]" "[CODE]" "[INDENT]" "[LIST]" "[PHP]" "[PRE]" "[QUOTE]"
/Unindent Strings = "[/ALIGN]" "[/CODE]" "[/INDENT]" "[/LIST]"  "[/PHP]" "[/PRE]" "[/QUOTE]"
/Open Fold Strings = "[ALIGN]" "[CODE]" "[INDENT]" "[LIST]" "[PHP]" "[PRE]" "[QUOTE]"
/Close Fold Strings = "[/ALIGN]" "[/CODE]" "[/INDENT]" "[/LIST]"  "[/PHP]" "[/PRE]" "[/QUOTE]"
/C1"Blocks: code indent ..."
// /ALIGN /CODE /INDENT /LIST /PHP /PRE /QUOTE
ALIGN
CODE
INDENT
LIST
PHP
PRE
QUOTE
[
]
/C2"Special: color img ..."
*
// /* /COLOR /EMAIL /FLASH /FONT /HR /IMG /MARQ /SIZE /URL /VIDEO
COLOR
EMAIL
FLASH
FONT
HR
IMG
MARQ
SIZE
URL
VIDEO
/C3"Operators: ="
=
/C4"Styles: b i sub sup u"
// /B /I /SUB /SUP /U
B
I
SUB
SUP
U
/C5"Colors"
aqua
black blue brown
cyan
darkblue
fuchsia
gray green
indigo
lime
maroon
navy
olive orange
purple
red
silver
teal
violet
white
yellow
/C6"Font Names"
Arial
Courier New
Lucida Console
System
Tahoma
Verdana
/C7"Alignment: left ..."
center
down
justify
left
right
up
/C8"Parameters: width ..."
height
width


Notes:
  • I added a few more color (/C) sections: Colors, Font Names, Alignment.

  • The only thing that does not properly work is the highlighting of the font names with a space in them, i.e. "Courier New" and "Lucida Console". The first word is highlighted the second is not. One could probably *hack* this problem by adding two more lines with "New" and "Console".

    Test code:
    Code: Select all
    [font=Courier New] ... [/font]
    [font=Lucida Console] ... [/font]
    [font=Verdana] ... [/font]

    But is there a better way?

Anyway thanks for the feedback it really helped a lot. The BBCode language should then almost be ready for upload to IDM.
User avatar
AEon
Newbie
 
Posts: 9
Joined: Wed Sep 24, 2008 1:12 pm
Location: Bavarian Forest

Re: BBCode Language Definition

Postby Mofi » Mon Sep 29, 2008 2:17 am

Well, if you run my macro SortLanguage from my SyntaxTools package you will see /C6 resorted to

/C6"Font Names"
Arial
Console Courier
Lucida
New
System
Tahoma
Verdana


This is what you have already indicated and what is definitely not the best solution, but the only one.

The whole language definition for BBCode is not really good which is not your fault. As you have written in your first post and I have written also in my first post above a mechanism like HTML_LANG for elements starting with < or </ and ending with > would be required for BBCode tags starting with [ or [/ and ending with ]. Your current language definition works for the BBCode tags, but highlights also keywords outside []. You know that and I too, but this was the reason why I did not publish the language definition I had created once and later deleted. For those which often write BBCode in UltraEdit it is maybe better to have a syntax highlighting for the tags with the disadvantage of some wrong highlighted words than no highlighting. But I publish only syntax highlighting definitions which do not highlight many words wrong.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4056
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: BBCode Language Definition

Postby AEon » Mon Sep 29, 2008 5:35 am

Sometimes I really wish there was a "dummy" mode for the syntax highlighting that would let you define words, e.g. in quotes like "Courier New", without having delimiters or other distractions mess into things, i.e. simply highlight those words as they are. Sigh.

I have the same problem in the language definition for D. There I'd like to "simply" have the library calls highlighted, e.g. "tango.core.", but since "." is a delimiter this does not work. Removing the delimiter "." on the other hand would no longer let the code recognize other key words delimited by "." e.g. ".length".

Strange that such a "verbatim highlight mode" has not been integrated.
User avatar
AEon
Newbie
 
Posts: 9
Joined: Wed Sep 24, 2008 1:12 pm
Location: Bavarian Forest

Re: BBCode Syntax?

Postby pietzcker » Mon Sep 29, 2008 7:49 am

As already discussed elsewhere, there is a tradeoff between performance, comprehensiveness and correctness of syntax highlighting. UE's developers chose a way that allows for fast and thorough highlighting in most cases - with several shortcomings in special circumstances like you describe. Other editors that favor a regex-based approach are much more flexible and can (theoretically) deliver near-perfect highlighting, but at a performance price.

As you probably know, you can define ".core" as well as "tango", so both will be highlighted. You could even still detect typos like tanggo.core - but you'd miss methods bound to wrong (but otherwise legal) objects. That doesn't look like so much of a problem.
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: BBCode Syntax?

Postby AEon » Mon Sep 29, 2008 8:46 am

pietzcker wrote:As you probably know, you can define ".core" as well as "tango", so both will be highlighted. You could even still detect typos like tanggo.core - but you'd miss methods bound to wrong (but otherwise legal) objects. That doesn't look like so much of a problem.


I was doing that. And in the above case it would work well enough, it gets ugly when you have something like "std.c.something", the "c" would then be too "vague".

Oh well, I'm happy we have syntax highlighting at all. :)
User avatar
AEon
Newbie
 
Posts: 9
Joined: Wed Sep 24, 2008 1:12 pm
Location: Bavarian Forest


Return to Syntax Highlighting