You're viewing old version number 7. - Current version

3 min

Testing fenced code blocks

I'm typing this page in Markdown.

#junco - #testing - #markup

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;
}

Now trying a fenced code block by surrounding the code text with three tildes at the start of the code block and three tildes at the end of the code block. For now, I'm using my new fence. / fence.. command that works like my code command except fence will display all the text within the page and not in a limited textarea box.

I don't understand why CommonMark's spec initiative supports two ways to define a fenced code block. One positive for Textile is that it limits the ways to create headings, bullet points, etc.

Here are my custom formatting commands for block text with some dating back to my Parula code that I created in 2005, which powers ToledoTalk.

q. / q.. tmpl. / tmpl.. code. / code..


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
651 words - 4439 chars - 3 min read
created on
updated on - #
source - versions

Related articles
Testing fenced code block commands - Sep 23, 2014
Resolved - Add Markdown support - Jul 02, 2013
Markdown and Multimarkdown testing and documentation - Jun 18, 2014
Test post using Markdown - Mar 10, 2014
Testing the new insta command - May 17, 2016
more >>



A     A     A     A     A

© 2013-2017 JotHut - Online notebook

current date: Dec 24, 2024 - 11:50 a.m. EST