HOWTO Zencoding(Sparkup) in Geany

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
GustavoYz
Posts: 883
Joined: Wed 07 Jul 2010, 05:11
Location: .ar

HOWTO Zencoding(Sparkup) in Geany

#1 Post by GustavoYz »

If you use Geany to write HTML/CSS code, you should heard already of ZenCoding.
Zencoding is like a macro system, with his own sintax, to write repetitve parts of web languages without the pain.
For example, "html:xs" give this XHTML 1.0 header and skeleton as result:

Code: Select all

<!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">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <title></title>
</head>
<body>
    
</body>
</html>
A nice fork of this project called 'sparkup' is waiting on github; we will use that one because its just a script, really easy to handle. [Vim workaround is straightforward, so i'll ignore that part].
This will show more of the time saving part, this time just used as a cli tool:

Code: Select all

echo 'ul > li.item-$*5' | ./sparkup
<ul>
    <li class="item-1"></li>
    <li class="item-2"></li>
    <li class="item-3"></li>
    <li class="item-4"></li>
    <li class="item-5"></li>
</ul>
NOTE: There is a 'new' Geany plugin for Zen coding, as I've found it very buggy, I made this workaround which works well. Check the official site for the Geany plugin and also, if you plan to use it, grab the cool pdf chatsheet from there (all in the very first link on this post).

To make it work in Geany, I just set-up a custom command that send selected text trough sparkup and replace it by the result (CTRL+Z if something went wrong).

1-Just in case, I made a pet only with the python script which will be instaled in ~/my-applications/bin. Install it, or grab all from github and place the main sparkup.py script somewhere into your path.
2-In Geany, go to 'Edit->Format->Send Selection to' (I have it in Spanish, not sure if its exactly like that) and you'll see '1:, 2: , etc". Add this to a free number:

Code: Select all

sparkup 2> /dev/null
3-Now try it up, write some sparkup valid code -like previous examples-, select it and press CTRL+1 (actually, CRTL+x, where 'x' is the new command that you've just settled in numerical order in previous step).
*Same applies to other tools, like the magnificent perl tidy.

Hope you enjoy it as I do.
Regards.
Attachments
sparkup-0.1.3_cli.pet
Only the script.
(8.31 KiB) Downloaded 254 times

Post Reply