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

4 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.

fence.sub new {
my ($class, $api_token) = @;
my $self = ();
$self->{api
token} = $api_token;
$self->{link} = undef; bless($self, $class);
return $self; } fence..

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 and single-line text with some dating back to my Parula code that I created in 2005, which powers ToledoTalk.

  • q. and q..
  • tmpl. and tmpl..
  • hr.
  • br.
  • more.
  • code. and code..
  • fence. and fence..

Another think that I like about Textile is how it uses alpha characters to define some commands, which make more sense than punctuation marks. Textile commands use both punctuation and alpha-numeric commands, while Markdown uses only or mainly punctuation marks.

It seems that h2. is more intuitive than two pound signs. A bq. for a blockquote also makes more sense than a greater-than symbol. And so on.

Obivously over the years, I created my custom formatting commands to read more like Textile commands with the periods.

For block text, my opening and closing commands that use a single period and a double period respectively are easy to parse and substitute, regex-wise within my code.

And the words "code" and "fence" make more sense to me than three backticks or three tildes.

I guess that I'll continue on my own non-standard path of creating a markup language that works for me.

I like aspects of Textile, and I like aspects of Markdown, which is why I support both markups in my Junco and Grebe codebases. I also support Multimarkdown in both too. For Grebe, it's either Textile or Multimarkdown. For Junco, I

From JR's : articles
851 words - 5619 chars - 4 min read
created on
updated on - #
source - versions

Related articles
Testing fenced code block commands - Sep 23, 2014
Markdown and Multimarkdown testing and documentation - Jun 18, 2014
Test post using Markdown - Mar 10, 2014
Testing the new insta command - May 17, 2016
This is a test: with the colon punct in the title - Jul 16, 2014
more >>



A     A     A     A     A

© 2013-2017 JotHut - Online notebook

current date: May 18, 2024 - 1:45 a.m. EDT