Skip to content

Instantly share code, notes, and snippets.

@oppara
Created May 10, 2012 04:52
Show Gist options
  • Save oppara/2651090 to your computer and use it in GitHub Desktop.
Save oppara/2651090 to your computer and use it in GitHub Desktop.
markdown記法をtextile記法に適当に変換
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
#
# markdown記法をtextile記法に変換
# 超簡易版
#
# Usage:
# $0 markdown > textile
#
my @results;
my @codes;
my $is_code = 0;
# for my $line (<DATA>) {
for my $line (<>) {
chomp($line);
# headings
if ($line =~ /^(#+)(.+)$/) {
push(@results, sprintf('h%d.%s', length($1), $2));
next;
}
# list
if ($line =~ /^([-+*]+) (.+)$/) {
push(@results, sprintf('* %s', $2));
next;
}
# order list
if ($line =~ /^(\d+\.) (.+)$/) {
push(@results, sprintf('# %s', $2));
next;
}
# code
if ($line =~ /^(\s{4}|\t)(.+)$/) {
push(@codes, $2);
$is_code = 1;
next;
}
if ($is_code) {
unshift(@codes, '<pre>');
push(@codes, '</pre>');
push(@results, @codes);
@codes = ();
$is_code = 0;
}
push(@results, $line);
}
print join("\n", @results );
1;
__DATA__
# title1
hogehogehhoge
## title2
mogemogemoge
* list*
+ list*
- list*
> blockquot
> blockquot
> blockquot
> blockquot
### titl3
1. list order
1. list order
foo bar baz
foo bar baz
foo bar baz
array (
0 => 1,
1 => '1',
2 => '0',
3 => '30',
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment