Difference between revisions of "Snippets syntax"

From Bluefish Wiki
Jump to: navigation, search
m (Created page with '{{Man2top |lang=en |rev=2.0.0 |st=u |Title=8. External programs, filters |prev=Man 2 ch07s07 |Subtitle=Snippets syntax |next=Man 2 ch08 }} {{toc}} == syntax example =…')
 
m (Insert snippets)
 
(15 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
|rev=2.0.0
 
|rev=2.0.0
 
|st=u
 
|st=u
|Title=8. External programs, filters
+
|Title=Snippets syntax
 
|prev=Man 2 ch07s07
 
|prev=Man 2 ch07s07
|Subtitle=Snippets syntax
+
|Subtitle=Chapter VII. More than a Text Editor
 
|next=Man 2 ch08
 
|next=Man 2 ch08
 
}}
 
}}
 +
{{toc}}
 +
The snippets are stored in <tt>~/.bluefish/snippets</tt>.
 +
It is an XML file, like import and export snippets files.
  
 +
'''Bluefish has an excellent editor snippets. So it is useless to read this page unless you intend to create a large number of snippets from some documentation, eg: SVG, DOM, etc.'''
  
{{toc}}
+
* The import file must have a valid XML syntax.
 +
* The document must include the header: <tt><nowiki><?xml version="1.0"?></nowiki></tt>.
 +
* The document must be included in the container: <tt><nowiki><snippets> <snippets></nowiki></tt>
 +
* Any snippet must be contained in a branch: <tt><nowiki><branch title="example"> </branch></nowiki></tt>
 +
* The branches may contain other branches.
 +
* Each snippet is described in a container: <tt><nowiki><leaf> </leaf></nowiki></tt>
  
== syntax example ==
+
== Syntax examples ==
 +
There are two types of snippets: '''insert''' and '''snr''', aka '''S'''earch '''N''' '''R'''eplace.
 +
=== Insert snippets ===
 
<ol>
 
<ol>
 
# <nowiki><?xml version="1.0"?></nowiki>
 
# <nowiki><?xml version="1.0"?></nowiki>
Line 18: Line 29:
 
# <nowiki><branch title="Facebook"></nowiki>
 
# <nowiki><branch title="Facebook"></nowiki>
 
# <nowiki><leaf type="insert" title="bold"><before></nowiki><span style="color:red">&amp;lt;</span><nowiki>b</nowiki><span style="color:red">&amp;gt;</span><nowiki></before><after></nowiki><span style="color:red">&amp;lt;</span><nowiki>/b</nowiki><span style="color:red">&amp;gt;</span><nowiki></after></leaf></nowiki>
 
# <nowiki><leaf type="insert" title="bold"><before></nowiki><span style="color:red">&amp;lt;</span><nowiki>b</nowiki><span style="color:red">&amp;gt;</span><nowiki></before><after></nowiki><span style="color:red">&amp;lt;</span><nowiki>/b</nowiki><span style="color:red">&amp;gt;</span><nowiki></after></leaf></nowiki>
# <nowiki><leaf type="insert" title="italic"><before></nowiki><span style="color:red">&amp;lt;</span><nowiki>i</nowiki><span style="color:red">&amp;gt;</span><nowiki></before><after></nowiki><span style="color:red">&amp;lt;</span><nowiki>/i</nowiki><span style="color:red">&amp;gt;</span><nowiki></after></leaf></nowiki>
+
# <nowiki><leaf type="insert" title="italic"</nowiki><span style="color:blue"> tooltip="insert an italic tag"</span><nowiki>><before></nowiki><span style="color:red">&amp;lt;</span><nowiki>i</nowiki><span style="color:red">&amp;gt;</span><nowiki></before><after></nowiki><span style="color:red">&amp;lt;</span><nowiki>/i</nowiki><span style="color:red">&amp;gt;</span><nowiki></after></leaf></nowiki>
# <nowiki><leaf type="insert" title="Hyperlink"><before></nowiki><span style="color:red">&amp;lt;</span><nowiki>a href="%0"</nowiki><span style="color:red">&amp;gt;</span><nowiki></before><after></nowiki><span style="color:red">&amp;lt;</span><nowiki>/a</nowiki><span style="color:red">&amp;gt;</span><nowiki></after></nowiki><span style="color:blue"><nowiki><param name="url"/></nowiki></span><nowiki></leaf></nowiki>
+
# <nowiki><leaf type="insert" title="Hyperlink"><before></nowiki><span style="color:red">&amp;lt;</span>a href="<span style="color:blue">%0</span>"<span style="color:red">&amp;gt;</span><nowiki></before><after></nowiki><span style="color:red">&amp;lt;</span><nowiki>/a</nowiki><span style="color:red">&amp;gt;</span><nowiki></after></nowiki><span style="color:blue"><nowiki><param name="url"/></nowiki></span><nowiki></leaf></nowiki>
 
# <nowiki><leaf type="insert" title="em-dash"><before></nowiki><span style="color:red">&</span><span style="color:red">amp;</span><nowiki>mdash;</before></nowiki><span style="color:blue"><nowiki><after></after></nowiki></span><nowiki></leaf></nowiki>
 
# <nowiki><leaf type="insert" title="em-dash"><before></nowiki><span style="color:red">&</span><span style="color:red">amp;</span><nowiki>mdash;</before></nowiki><span style="color:blue"><nowiki><after></after></nowiki></span><nowiki></leaf></nowiki>
 
# <nowiki></branch></nowiki>
 
# <nowiki></branch></nowiki>
 
# <nowiki></snippets></nowiki>
 
# <nowiki></snippets></nowiki>
 +
</ol>
 +
 +
;First and important, : if you want to insert any XML reserved characters ie: '''&lt; &gt; &amp;''' you have to escape them (red highlighted in example).
 +
* A leaf tag must have type and title attributes,
 +
* it also may have a tooltip attribute (line 5 of example).
 +
** multiline tooltip, Line Feed <tt>&amp;#10;</tt>, Carriage return <tt>&amp;#13;</tt>, Tab <tt>&amp;#9;</tt>
 +
* Before tag is used for text to insert before, and after tag for text inserted after.
 +
* You have to add one or more param tags (with name attibute) if you want tu use parameters (line 6 of example).
 +
 +
*<param <span style="color:blue">num="1"</span> name="image"/> The num attribute of param is not used, only the order of params declaration is used, first param for %0 etc.
 +
* <param name="source" <span style="color:blue">is_file="1"</span>/> If is_file is set, a Browse button is added in dialog.
 +
 +
=== Search and replace snippets ===
 +
SnR snippets are a little more complex:
  
 +
<nowiki><leaf type="snr" title="replace 1" tooltip="introduce events" region="b" matchtype="normal" casesens="0" escapechars="0"></nowiki><br />
 +
&nbsp;<nowiki><searchpat>jpg</searchpat></nowiki><br />
 +
&nbsp;<nowiki><replacepat>jpg" alt="" onmouseout="out(this);" onmouseover="popup(this,'th/</replacepat></nowiki><br />
 +
<nowiki></leaf></nowiki>
 +
 +
;searchpat and replacepat tags,
 +
: are replacing before and after tags.
 +
;leaf tag have new attibutes,:
 +
:;region :''values'': <tt>b</tt> (Entire document), <tt>c</tt> (forword from cursor position), <tt>s</tt> (Selection), or <tt>a</tt> (All open files).
 +
:;matchtype :''values'': <tt>normal</tt>, <tt>word</tt>, <tt>posix</tt> or <tt>perl</tt>.
 +
:;casesens :''values'':  <tt>1</tt> (set) or <tt>0</tt> (unset).
 +
:;escapechars :''values'':  <tt>1</tt> (set) or <tt>0</tt> (unset).
 +
 +
;Shorthand character classes:
 +
:you can use  <tt>\w \W \s \S</tt> and <tt>.</tt> but not <tt>\d \D</tt> (use <tt>[0-9]</tt> and <tt>[^0-9]</tt> instead)
 +
 +
== My stylesheet to snippets ==
 +
;todo: see in [[:Category:Snippets repository]] Bluefish css2snippets snippets
  
</ol>
 
  
 
{{Man2bottom
 
{{Man2bottom
Line 31: Line 73:
 
|up=Man 2 ch07
 
|up=Man 2 ch07
 
|next=Man 2 ch08
 
|next=Man 2 ch08
|prevname= 7.&amp;nbsp;Snippets plugin
+
|prevname= 7.Snippets plugin
|nextname= Chapter&amp;nbsp;VIII.&amp;nbsp;Customising Bluefish
+
|nextname= Chapter VIII. Customising Bluefish
 
}}
 
}}

Latest revision as of 15:59, 16 November 2010

this page is updated for Manual 2. It needs to be verified! once you have verified this page (and corrected if necessary) please modify the status to v (verified), i.e. st=v (see Guidelines for Writing this Manual)

Man2 icon 48.png
Chapter VII. More than a Text Editor
Prev 
Snippets syntax
 Next
 

The snippets are stored in ~/.bluefish/snippets. It is an XML file, like import and export snippets files.

Bluefish has an excellent editor snippets. So it is useless to read this page unless you intend to create a large number of snippets from some documentation, eg: SVG, DOM, etc.

  • The import file must have a valid XML syntax.
  • The document must include the header: <?xml version="1.0"?>.
  • The document must be included in the container: <snippets> <snippets>
  • Any snippet must be contained in a branch: <branch title="example"> </branch>
  • The branches may contain other branches.
  • Each snippet is described in a container: <leaf> </leaf>

Syntax examples

There are two types of snippets: insert and snr, aka Search N Replace.

Insert snippets

    1. <?xml version="1.0"?>
    2. <snippets>
    3. <branch title="Facebook">
    4. <leaf type="insert" title="bold"><before>&lt;b&gt;</before><after>&lt;/b&gt;</after></leaf>
    5. <leaf type="insert" title="italic" tooltip="insert an italic tag"><before>&lt;i&gt;</before><after>&lt;/i&gt;</after></leaf>
    6. <leaf type="insert" title="Hyperlink"><before>&lt;a href="%0"&gt;</before><after>&lt;/a&gt;</after><param name="url"/></leaf>
    7. <leaf type="insert" title="em-dash"><before>&amp;mdash;</before><after></after></leaf>
    8. </branch>
    9. </snippets>
First and important, 
if you want to insert any XML reserved characters ie: < > & you have to escape them (red highlighted in example).
  • A leaf tag must have type and title attributes,
  • it also may have a tooltip attribute (line 5 of example).
    • multiline tooltip, Line Feed &#10;, Carriage return &#13;, Tab &#9;
  • Before tag is used for text to insert before, and after tag for text inserted after.
  • You have to add one or more param tags (with name attibute) if you want tu use parameters (line 6 of example).
  • <param num="1" name="image"/> The num attribute of param is not used, only the order of params declaration is used, first param for %0 etc.
  • <param name="source" is_file="1"/> If is_file is set, a Browse button is added in dialog.

Search and replace snippets

SnR snippets are a little more complex:

<leaf type="snr" title="replace 1" tooltip="introduce events" region="b" matchtype="normal" casesens="0" escapechars="0">
 <searchpat>jpg</searchpat>
 <replacepat>jpg" alt="" onmouseout="out(this);" onmouseover="popup(this,'th/</replacepat>
</leaf>

searchpat and replacepat tags,
are replacing before and after tags.
leaf tag have new attibutes,
region 
values: b (Entire document), c (forword from cursor position), s (Selection), or a (All open files).
matchtype 
values: normal, word, posix or perl.
casesens 
values: 1 (set) or 0 (unset).
escapechars 
values: 1 (set) or 0 (unset).
Shorthand character classes
you can use \w \W \s \S and . but not \d \D (use [0-9] and [^0-9] instead)

My stylesheet to snippets

todo
see in Category:Snippets repository Bluefish css2snippets snippets


Prev 
Up
 Next
7.Snippets plugin
Home | ToC
 Chapter VIII. Customising Bluefish