/ Published in: Perl
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/perl -w use strict; use Frontier::Client; # # Post a snippet (add-on for Smultron) # perl smultron snipperl rpc # # (paste the script as a New Command in Tools menu, for example: Post it) # (then select lines of code and run the script, Tools -> Commands -> Post it) # # post title grabbed from first non-empty comment, if any # tags grabbed from second non-empty comment, if any # language set to first tag, if many of them, else set to bash # my $key = ''; # (your API key) my $tempfile = '%%s'; my $title='no title yet'; my $code = ''; my $tags = ''; my $language = 'bash'; my $flag = 0; while (<FC>) { if (/^\#[^!]\s*(.+)/ && $flag == 0) { $title = $1; $flag++; } elsif (/^\#[^!]\s*(.+)/ && $flag == 1) { $tags = $1; $flag++; if (/(\w+) (.+)/) { $language = $1; $tags = $2; } } $code = $code . $_; } my $session = Frontier::Client->new( url => 'http://snipplr.com/xml-rpc.php', debug => 0,); my @args = ($key, $title, $code, $tags, $language); my $result = $session->call('snippet.post', @args);