Man 1 ch08s12

From Bluefish Wiki
Jump to navigation Jump to search


Please consider to upgrade to Bluefish 2!

Please consider to edit the Manual 2!

How To edit the Wiki Manual
{{#if:12. Modifying the highlighting patterns|
12. Modifying the highlighting patterns
}}
Prev }}
Chapter VIII. Customising Bluefish
}}
 Next
}}

12. Modifying the highlighting patterns

The highlight patterns are build from Perl compatible regular expressions. A pattern has options for coloring and styling the text it matches. Within a match other patterns can be used to color parts of that match. There are three types of patterns:

  1. Start pattern and end pattern: that is two distinct patterns, match from the start pattern to the end pattern
  2. Only start pattern: that is a unique pattern that matches from start to end
  3. Subpattern from parent: that is a subpattern from the parent pattern, specified by the range in the parent pattern.

One specific pattern can also be used within several other parent patterns. The parent-match option is a regular expression that defines all parents for a certain pattern. If empty it will default to ^top$, so basically it will be on the top level.

So how does it work? Lets take a look at a little example text, a piece of PHP code within some HTML code:

<p align="center">
<?php
// this is a comment ?>
?>

The first thing the highlighting engine does is finding the pattern that has the lowest match. Using the default patterns for PHP, the pattern named HTML:

Man1 highlighting pattern1.png

Figure VIII.12. The HTML Pattern

has a match at position 0:

<p align="center">

So now the highlighting engine searches for the lowest match in all subpatterns of HTML, in the region matched by a type 2 pattern. Again, the lowest match will count. The pattern named <html> Tags:

Man1 highlighting pattern2.png

Figure VIII.13. The <html> Tags Pattern

has a match at position 1. This pattern is a type 3 pattern, so it matches a subpattern of the parent:

p

The match from subpattern <html> Tags ends at position 2 and it does not have any child patterns, so the highlighting engine continues at position 2 with all subpatterns from HTML. A type 2 pattern named HTML Attributes:

Man1 highlighting pattern3.png

Figure VIII.14. The HTML Attributes Pattern

has the lowest match:

align="center"

This pattern does have a child pattern, again a type 3 pattern called HTML Attribute Contents:

Man1 highlighting pattern4.png

Figure VIII.15. The HTML Attribute Contents Pattern

matching:

"center"

The pattern HTML Attribute Contents does not have any child patterns, and subpatterns of HTML Attributes do not have any more matches, and also HTML subpatterns do not have any more matches. So we are back on the main level, the remaining code to highlight is:

<?php
// this is a comment ?>
?>

Now a pattern named PHP Block:

Man1 highlighting pattern5.png

Figure VIII.16. The PHP Block Pattern

has the lowest match. This is a type 1 pattern, so the highlight engine continues with all the remaining code, but it will not only search for the lowest match of the child patterns of PHP Block, but it will also ue it for the end pattern of PHP Block. The lowest match in this example is a pattern named Comment (C++/single line):

Man1 highlighting pattern6.png

Figure VIII.17. The Comment (C++/single line) Pattern

As you can see the ?> within the comment does not end the php pattern, because it lies within a subpattern of PHP Block:

// this is a comment ?>

The pattern Comment (C++/single line) does not have any child patterns, so the remaining code for the PHP subpatterns is:

?>

It is very obvious now, the lowest match will be the end pattern of the php pattern, so we're back on the main level, and we have matched all of the code!

Man1 syntax highlighting example.png

Figure VIII.18. Syntax Highlighting Example

The config file for highlighting is a colon separated array with the following content:

mode:
patternname:
case_sensitive(0-on/1-off):
start reg-ex:
end reg-ex:
start & end pattern(1), only start(2), subpattern(3):
parent-match:
foreground-color:
background-color:
don't change weight(0), non-bold(1), bold(2):
don't change style(0), non-italic(1), italic(2):

The same options are found in the syntax highlighting preferences.

As an exercise you may want to add the highlighting patterns for the xsl stylesheet file type created previously. They will be based on the xml patterns with just small changes.


Man1 note.png If you check the force bold weight check box, you should also check that the font you use has a bold variant in the Editor tab of the Preferences panel.


Prev }}
Up
}}
 Next
}}
11. Modifying the files filters}}
Home | ToC
 Chapter IX. Shortcuts available within Bluefish
}}