jEdit Community - Resources for users of the jEdit Text Editor
Expand the Span
Submitted by RaeVanMorlock on Wednesday, 8 September, 2004 - 16:53
I just found out about jEdit last night and I like it more than my previous editor; however, it's HTML syntax highlighting is lacking. So I endeavored to improve upon it. I got lists of all the elements and tags according to the HTML 4.01 specs and entered them as keywords, but problems occur distinguishing the two. For instance, "style" can be both a tag and an element.

I decided that the best approach would be to use regexp to highlight things according to their positions within a tag.

Element -- </({0,1}\w+?)
Attribute -- <\w+?(\s+?(\w+)=".+?")*>

[Note: I'm not sure that the question marks should be there, I just read in the Help Docs that "if a repeating operator is immediately followed by a ?, the repeating operator will stop at the smallest number of repetitions that can complete the rest of the match" so I hope I'm understanding that correctly.]

So the problem currently is that this doesn't really work for two reasons.

1) The SPAN_REGEXPs are set to highlight everything that matches them, but we need to specify stuff that needs to come before and after the attribute in order to be sure that we have an attribute. A solution could be to only highlight what is matched by the innermost parentheses when they exist. An option to toggle this behavior may also be needed in case someone needs to specify a repeating pattern but still highlight the entire regex.

2) Using regex under the main rules will include searching of things outside of the HTML tags. By making a ruleset to apply only to things inside HTML tags, you can get better results. But then, the 'greater than' and 'less than' signs cannot be used in the matching. So what I'm trying to suggest here is that the BEGIN and END sequences are included.

For a simple demonstration of what I'm trying to say, Consider this abbreivated mode file:

<SPAN TYPE="MARKUP" DELEGATE="TAGS">
    <BEGIN>&lt;</BEGIN>
    <END>&gt;</END>
</SPAN>

<RULES SET="TAGS" DEFAULT="MARKUP" ESCAPE="\">
    <KEYWORDS>
        <KEYWORD1>xxx</KEYWORD1>
    </KEYWORDS>
</RULES>

And this source code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
</html>

Now if xxx were replaced with "<html" to ensure that only the HTML tag (and not the instance of "html" within the !DOCTYPE tag) is highlighted--it wouldn't work because in ignores the BEGIN and END marks. Of course, if this did work properly then the < sign would also be highlighted, which is not the enteded behavior. That's why this is just a simplified example of the behavior that I'm talking about and why using regex and highlighting the inner-most parenthesis would be a better way to handle this.

So with the way it currently behaves, you would have to replace xxx with "html" to see any type of result. In this case, the instance of "html" within the !DOCTYPE tag is also highlighted. This may not seem like terribly bad behavior, but it is when applied to "style" because you can have:

<STYLE type="text/css">
H1{ font-size: 10pt; }
</STYLE>

and:

<span style="font-size: 10pt">

Which clearly shows that "style" can be both a tag and an element, but it will have the same format applied regardless.



I hope I explained everything clearly here. I'll try to check back frequently to answer any questions.
User login
Browse archives
« September 2024  
MoTuWeThFrSaSu
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   97766
Context Free Art (*.cfdg)   0.31   46062
BBEdit scheme   1.0   18601
JBuilder scheme   .001   18502
ColdFusion scheme   1.0   18031
R Edit Mode - extensive version   0.1   17480
Advanced HTML edit mode   1.0   16212
Matlab Edit Mode   1.0   16075
jEdit XP icons   1.0   15236
XP icons for jEdit   1.1   14299