You're viewing old version number 3. - Current version
Testing fenced code blocks
I'm typing this page in Markdown.
Will try to add my own support for this.
Will make it available, regardless of what markup language that I'm using, similar to my other custom formatting commands.
My custom fenced code block command code. / code..
is available when I'm typing in Textile or Markdown/Multimarkdown. The feature limits the window size that displays the code. So if it's a large blob of code, a small read-only text window with vertical and horizontal scrollbars displays the code.
A fence-code block like what's used by the Github Flavored Markdown or specified at CommonMark would display the entire code blob on the web page.
But instead of indenting the entire code blob four spaces on each line like with Markdown, the fenced block only needs to be surrounded by three tildes or three backticks.
I also support a command called code=yes
but this turns the entire web page into a code page. Sometimes, that's fine, but most of the time, code text is mixed with normal text on the same web page.
Using my code. / code..
command to display my Perl module that uses the Yo API.
package Yo;
use strict;
use warnings;
use LWP::UserAgent;
my %URLS = (
'all' => 'http://api.justyo.co/yoall/',
'user' => 'http://api.justyo.co/yo/',
'subscribers' => 'http://api.justyo.co/subscribers_count/'
);
sub new {
my ($class, $api_token) = @_;
my $self = ();
$self->{api_token} = $api_token;
$self->{link} = undef;
bless($self, $class);
return $self;
}
sub set_link {
my ($self, $link) = @_;
$self->{link} = $link;
}
sub all {
my ($self) = @_;
my $ua = LWP::UserAgent->new();
my $response;
if ( defined($self->{link}) ) {
$response = $ua->post( $URLS{'all'}, { 'api_token' => $self->{api_token}, 'link' => $self->{link} } );
} else {
$response = $ua->post( $URLS{'all'}, { 'api_token' => $self->{api_token} } );
}
my $rc = $response->code;
return $rc;
}
sub user {
my ($self, $username) = @_;
my $ua = LWP::UserAgent->new();
my $response;
if ( defined($self->{link}) ) {
$response = $ua->post( $URLS{'user'}, { 'api_token' => $self->{api_token}, 'username' => $username, 'link' => $self->{link} } );
} else {
$response = $ua->post( $URLS{'user'}, { 'api_token' => $self->{api_token}, 'username' => $username } );
}
my $rc = $response->code;
return $rc;
}
sub subscribers {
my ($self) = @_;
my $ua = LWP::UserAgent->new();
my $url = $URLS{'subscribers'} . "?api_token=" . $self->{api_token};
my $response = $ua->get($url);
my $content = $response->decoded_content();
return $content; # return json. example {"result": 123}. let client decode json.
}
sub DESTROY {
my ($self) = @_;
$self->{api_token} = undef;
$self->{link} = undef;
}
1;
With Markdown, I could indent the code four spaces on each line, but that's time consuming for a decently-sized block of code.
Here's a snippet of the above code with each line indented four spaces:
use strict;
use warnings;
use LWP::UserAgent;
my %URLS = (
'all' => 'http://api.justyo.co/yoall/',
'user' => 'http://api.justyo.co/yo/',
'subscribers' => 'http://api.justyo.co/subscribers_count/'
);
sub new {
my ($class, $api_token) = @_;
my $self = ();
$self->{api_token} = $api_token;
$self->{link} = undef;
bless($self, $class);
return $self;
}
From JR's : articles
498 words - 3529 chars
- 2 min read
created on
updated on
- #
source
- versions
Related articles
Testing fenced code block commands - Sep 23, 2014
This is a test: with the colon punct in the title - Jul 16, 2014
Resolved - Add client-side Textile markup editor - Aug 21, 2013
Junco user actions - Nov 01, 2013
Resolved - Add Markdown support - Jul 02, 2013
more >>