Revisions
-
inao revised this gist
Jan 21, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,12 +20,12 @@ # リストの文字数上限 # WEB+DB PRESSの場合、リストは、1行63桁(文字)まで # 書籍の場合、リストは1行69桁(文字)まで use constant MAX_LIST_LENGTH => 63; # 本文埋め込みリストの文字数上限 # WEB+DB PRESSの場合、本文リストは1行55桁(文字)まで # 書籍の場合、本文リストは1行73桁(文字)まで use constant MAX_INLINE_LIST_LENGTH => 55; # 本文中に(◯1)や(1)など、リストを参照するときの形式に変換する -
inao revised this gist
Jan 9, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ ■■見出し2(中見出し、項) ■■■見出し3(小見出し、目) 段落冒頭の字下げは、このように手動でお願いします。改行は、(改行)このように自動で取り除かれます。 通常の本文◆b/◆強調(ボールド)◆/b◆通常の本文◆i/◆斜体(イタリック)◆/i◆通常の本文◆cmd/◆インラインのコード◆/cmd◆通常の本文◆注/◆注釈ですよ。◆i/◆イタリック◆/i◆◆/注◆通常の本文Enter▲(←キーボードフォント)◆red/◆赤文字◆/red◆通常の本文◆ルビ/◆外村◆ほかむら◆/ルビ◆(←ルビ)。 ◆quote/◆ ◆i-j/◆引用◆/i-j◆です◆b/◆引用◆/b◆です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です ◆/quote◆ @@ -49,7 +49,7 @@ [2]fugafugaと[1]の結果を足し合わせます リスト1.1(○1)ではアラートを出しています。(○2)でもアラートを出しています。(a1)エスケープできます。 ◆list/◆ ●リスト1.1 キャプション(コードのタイトル) function hoge() { alert(foo); … (○1) alert(bar); … (○2) -
inao revised this gist
Sep 10, 2012 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,4 +4,10 @@ PDFにすると、以下のような仕上がりになります。 https://docs.google.com/open?id=0BzbGMS73rIkDUXpyUVlrSUxURXlmMXhQRV9Ua2JCUQ ・WEB+DB PRESS版 https://docs.google.com/open?id=0BzbGMS73rIkDZjdCTnBkMDFUaGF2UDJIdTNfaVJUUQ 導入方法です。 ・はじめる!markdown2inao « blog.udzura.jp http://blog.udzura.jp/2012/09/10/install-markdown2inao/ -
inao revised this gist
Jun 28, 2012 . 2 changed files with 3 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -203,13 +203,13 @@ sub to_inao { } # コード内コメント $text =~ s!\(注:(.+?)\)!◆$comment_label/◆$1◆/$comment_label◆!g; # コード内強調 $text =~ s!\*\*(.+?)\*\*!◆cmd-b/◆$1◆/cmd-b◆!g; # コード内イタリック $text =~ s!\___(.+?)\___!◆i-j/◆$1◆/i-j◆!g; $inao .= "◆$list_label/◆\n"; $inao .= $text; This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ # 見出し1(大見出し、節) ## 見出し2(中見出し、項) -
inao revised this gist
Jun 21, 2012 . 3 changed files with 122 additions and 91 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -65,15 +65,93 @@ sub visual_length { return $ret; } sub parse_inline { my $elem = shift; my $is_special_italic = shift; my $ret = ''; for my $inline ($elem->content_list) { if (ref $inline eq '') { # (注:)は脚注としてあつかう $inline =~ s!\(注:(.+?)\)!◆注/◆$1◆/注◆!gs; # 改行を取り除く $inline =~ s/(\n|\r)//g; # キャプション if ($inline =~ s!^●(.+?)::(.+)!●$1\t$2!) { $inline =~ s!\[(.+)\]$!\n$1!; } # リストスタイル文字の変換 $inline = to_list_style($inline); $ret .= $inline; } elsif ($inline->tag eq 'code') { $ret .= '◆cmd/◆'; $ret .= $inline->as_trimmed_text; $ret .= '◆/cmd◆'; } elsif ($inline->tag eq 'strong') { $ret .= '◆b/◆'; $ret .= $inline->as_trimmed_text; $ret .= '◆/b◆'; } elsif ($inline->tag eq 'em') { $ret .= $is_special_italic ? '◆i-j/◆' : '◆i/◆'; $ret .= $inline->as_trimmed_text; $ret .= $is_special_italic ? '◆/i-j◆' : '◆/i◆'; } elsif ($inline->tag eq 'kbd') { $ret .= $inline->as_trimmed_text; $ret .= '▲'; } elsif ($inline->tag eq 'span') { my $class = $inline->attr('class'); # 赤字 # <span class='red'>赤字</span> if ($class eq 'red') { $ret .= '◆red/◆'; $ret .= $inline->as_trimmed_text; $ret .= '◆/red◆'; } # ruby # <span class='ruby'>漢字(かんじ)</span> elsif ($class eq 'ruby') { my $ruby = $inline->as_trimmed_text; $ruby =~ s!(.+)\((.+)\)!◆ルビ/◆$1◆$2◆/ルビ◆!; $ret .= $ruby; } # その他の記号 # <span class='symbol'>=></span> elsif ($class eq 'symbol') { $ret .= '◆'; $ret .= $inline->as_trimmed_text; $ret .= '◆'; } } } return $ret; } sub to_html_tree { my $text = shift; my $html = markdown($text); my $tree = HTML::TreeBuilder->new; $tree->no_space_compacting(1); $tree->parse_content(\$html); } sub to_inao { my $text = shift; my $is_column = shift; my $tree = to_html_tree($text); my $inao = q[]; my $body = $tree->find('body'); @@ -86,72 +164,7 @@ sub to_inao { $inao .= "\n"; } elsif ($elem->tag eq 'p') { my $p = parse_inline($elem, $is_column); if ($p !~ /^[\s ]+$/) { $inao .= "$p\n"; @@ -195,22 +208,26 @@ sub to_inao { # コード内強調 $text =~ s!\*\*(.+?)\*\*!◆cmd-b/◆$1◆/cmd-b◆!gs; # コード内イタリック $text =~ s!\___(.+?)\___!◆i-j/◆$1◆/i-j◆!gs; $inao .= "◆$list_label/◆\n"; $inao .= $text; $inao .= "◆/$list_label◆\n"; } elsif ($elem->tag eq 'ul') { for my $list ($elem->find('li')) { $inao .= '・' . parse_inline($list, 1) . "\n"; } } elsif ($elem->tag eq 'ol') { my $list_style = $elem->attr('class') || DEFAULT_LIST; my $s = substr $list_style, 0, 1; my $i = 0; for my $list ($elem->find('li')) { $inao .= to_list_style((sprintf('(%s%d)', $s, ++$i)) . parse_inline($list, 1)) . "\n"; } } elsif ($elem->tag eq 'table') { @@ -234,12 +251,20 @@ sub to_inao { $inao .= "◆/table◆\n"; } elsif ($elem->tag eq 'div' and $elem->attr('class') eq 'column') { # HTMLとして取得してcolumn自信のdivタグを削除 my $html = $elem->as_HTML(''); $html =~ s/^<div.+?>//; $html =~ s/<\/div>$//; $inao .= "◆column/◆\n"; $inao .= to_inao($html, 1); $inao .= "◆/column◆\n"; } elsif ($elem->tag eq 'blockquote') { my $blockquote = ''; for my $p ($elem->content_list) { $blockquote = parse_inline($p, 1); } $blockquote =~ s/(\s)//g; $inao .= "◆quote/◆\n"; $inao .= $blockquote; This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ # 見出し1(大見出し、節) ## 見出し2(中見出し、項) @@ -8,17 +9,17 @@ 改行は、(改行) このように自動で取り除かれます。 通常の本文**強調(ボールド)**通常の本文_斜体(イタリック)_通常の本文`インラインのコード`通常の本文(注:注釈ですよ。_イタリック_)通常の本文<kbd>Enter</kbd>(←キーボードフォント)<span class='red'>赤文字</span>通常の本文<span class='ruby'>外村(ほかむら)</span>(←ルビ)。 > _引用_です**引用**です引用です引用です引用です引用です引用です引用です > 引用です引用です引用です引用です引用です引用です引用です引用です > 引用です引用です引用です引用です引用です引用です引用です引用です > 引用です引用です引用です引用です引用です引用です引用です引用です <div class='column'> #### コラム見出し **コラム**本文_コラム_本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム。 ##### コラム小見出し @@ -29,8 +30,8 @@ ### 通常の箇条書き * 通常の**箇条書き** * 通常の_箇条書き_ * 通常の箇条書き * 通常の箇条書き * 通常の箇条書き @@ -127,6 +128,9 @@ alert(a); (注:こんな風にコメントがつけられます) } ___foo('bar');___ // コード内___イタリック___ ___foo('baz');___ // コード内**強調** (注:見出し的にも使えます) function bar(b) { alert(b); @@ -138,7 +142,7 @@ ただし、呼称が「リスト」ではなく「図」となります。また、コマンド行の行頭にはプロンプトを付けてください。 ### 本文埋め込みコマンド(本文埋め込み版はWEB+DB PRESSでは未使用) !!! cmd $ command **foo** // コマンド内強調 @@ -165,7 +169,7 @@ スクリーンショットなど、別ファイルを参照する図です。 ●図1.1::キャプション(_図の_タイトル)[figure/sample.png] ## 表★要キャプション★ This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,20 +2,20 @@ ■■見出し2(中見出し、項) ■■■見出し3(小見出し、目) 段落冒頭の字下げは、このように手動でお願いします。改行は、(改行)このように自動で取り除かれます。 通常の本文◆b/◆強調(ボールド)◆/b◆通常の本文◆i/◆斜体(イタリック)◆/i◆通常の本文◆cmd/◆インラインのコード◆/cmd◆通常の本文(注:注釈ですよ。◆i/◆イタリック◆/i◆)通常の本文Enter▲(←キーボードフォント)◆red/◆赤文字◆/red◆通常の本文◆ルビ/◆外村◆ほかむら◆/ルビ◆(←ルビ)。 ◆quote/◆ ◆i-j/◆引用◆/i-j◆です◆b/◆引用◆/b◆です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です ◆/quote◆ ◆column/◆ ■■■■コラム見出し ◆b/◆コラム◆/b◆本文◆i-j/◆コラム◆/i-j◆本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム。 ■■■■■コラム小見出し コラム内でも◆b/◆強調◆/b◆などが使えます。 ◆/column◆ ■■箇条書き(リスト)いろいろ ■■■通常の箇条書き ・通常の◆b/◆箇条書き◆/b◆ ・通常の◆i-j/◆箇条書き◆/i-j◆ ・通常の箇条書き ・通常の箇条書き ・通常の箇条書き @@ -75,15 +75,18 @@ function bar(b) { リストは、本文とは別ボックス(別なパーツ)として紙面の端に寄せてレイアウトしますので、コードがページをまたぐことはございません(1ページを超えるコードはまたぎますけど)。 以下、このリストや後述する図や表など、別ボックスものの場合のご注意点です。 ・キャプション(タイトル)が必須です ・「◆b/◆リスト1.1◆/b◆をご覧ください」「○○のコードを示します(◆b/◆リスト1.1◆/b◆)」「○○を◆b/◆表1.1◆/b◆にまとめました」みたいな感じで、本文から番号で参照してください ・初出時のみ◆b/◆リスト1.1◆/b◆のように太字にします(2度目以降は通常の本文です) (このドキュメントでは、別ボックスものは見出しに★要キャプション★と書いています) ◆list/◆ ●リスト1.1 キャプション(コードのタイトル) function ◆cmd-b/◆foo◆/cmd-b◆(a) { // コード内強調 alert(a); ◆comment/◆こんな風にコメントがつけられます◆/comment◆ } ◆i-j/◆foo('bar');◆/i-j◆ // コード内◆i-j/◆イタリック◆/i-j◆ ◆i-j/◆foo('baz');◆/i-j◆ // コード内◆cmd-b/◆強調◆/cmd-b◆ ◆comment/◆見出し的にも使えます◆/comment◆ function bar(b) { alert(b); @@ -92,7 +95,7 @@ function bar(b) { ■■コマンドの実行結果 コマンドは、「!!! cmd」と付けていただく必要があるだけで、基本的には上記ソースコードと同じです。 ただし、呼称が「リスト」ではなく「図」となります。また、コマンド行の行頭にはプロンプトを付けてください。 ■■■本文埋め込みコマンド(本文埋め込み版はWEB+DB PRESSでは未使用) ◆list-white/◆ $ command ◆cmd-b/◆foo◆/cmd-b◆ // コマンド内強調 bar ◆comment-white/◆こんな風にコメントがつけられます◆/comment-white◆ @@ -115,8 +118,7 @@ function bar(b) { ◆/list-white◆ ■■図★要キャプション★ スクリーンショットなど、別ファイルを参照する図です。 ●図1.1 キャプション(◆i/◆図の◆/i◆タイトル)[figure/sample.png] ■■表★要キャプション★ ◆table/◆ ●表1.1 キャプション(表のタイトル) @@ -173,4 +175,4 @@ $▲ _▲ @▲ `▲ "▲ -
inao revised this gist
Apr 27, 2012 . 2 changed files with 3 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -84,7 +84,7 @@ リスト1.1(c1)ではアラートを出しています。(c2)でもアラートを出しています。(\a1)エスケープできます。 ●リスト1.1::キャプション(コードのタイトル) function hoge() { alert(foo); … (c1) alert(bar); … (c2) This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -49,7 +49,7 @@ [2]fugafugaと[1]の結果を足し合わせます リスト1.1(○1)ではアラートを出しています。(○2)でもアラートを出しています。(a1)エスケープできます。 ◆list/◆ ●リスト1.1 キャプション(コードのタイトル) function hoge() { alert(foo); … (○1) alert(bar); … (○2) @@ -173,4 +173,4 @@ $▲ _▲ @▲ `▲ "▲ -
inao revised this gist
Apr 5, 2012 . 1 changed file with 21 additions and 21 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,8 @@ use Text::Markdown 'markdown'; use HTML::TreeBuilder; use List::Util 'max'; use Encode; use Unicode::EastAsianWidth; # デフォルトのリストスタイル # disc: 黒丸 @@ -54,6 +56,15 @@ sub to_list_style { return $text; } # 文字幅計算 # http://d.hatena.ne.jp/tokuhirom/20070514/1179108961 sub visual_length { local $_ = Encode::decode_utf8(shift); my $ret = 0; while (/(?:(\p{InFullwidth}+)|(\p{InHalfwidth}+))/g) { $ret += ($1 ? length($1)*2 : length($2)) } return $ret; } sub to_inao { my $text = shift; @@ -148,10 +159,7 @@ sub to_inao { } elsif ($elem->tag eq 'pre') { my $code = $elem->find('code'); my $text = $code ? $code->as_text : ''; my $list_label = 'list'; my $comment_label = 'comment'; @@ -168,25 +176,17 @@ sub to_inao { # リストスタイル $text = to_list_style($text); # 文字数カウント my $max = max(map { visual_length($_) } split /\r?\n/, $text); if ($text =~ /^●/) { if ($max > MAX_LIST_LENGTH) { warn "リストは" . MAX_LIST_LENGTH . "文字まで!(現在${max}使用):\n$text\n\n"; } } else { if ($max > MAX_INLINE_LIST_LENGTH) { warn "本文埋め込みリストは" . MAX_INLINE_LIST_LENGTH . "文字まで!(現在${max}使用):\n$text\n\n"; } } # コード内コメント -
inao revised this gist
Apr 4, 2012 . 3 changed files with 19 additions and 9 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,15 +35,15 @@ * 通常の箇条書き * 通常の箇条書き ### 連番箇条書き(黒丸数字、連番の場合のデフォルト) 1. 連番箇条書き(黒丸数字) 2. 連番箇条書き(黒丸数字) 3. 連番箇条書き(黒丸数字) 4. 連番箇条書き(黒丸数字) 5. 連番箇条書き(黒丸数字) ### 連番箇条書き(白丸数字、重複などの事情で黒丸では不都合なとき) <ol class='circle'> <li>連番箇条書き(白丸数字)</li> @@ -73,22 +73,24 @@ <li>連番箇条書き(アルファベット)</li> </ol> ### 本文やリスト中での番号 箇条書き以外の本文やリスト中で番号を書きたいときは、(d1)、(d2)、(c1)、(c2)、(s1)、(s2)、(a1)、(a2)のように書いてください。 <ol class='square'> <li>hogehogeをします</li> <li>fugafugaと(s1)の結果を足し合わせます</li> </ol> リスト1.1(c1)ではアラートを出しています。(c2)でもアラートを出しています。(\a1)エスケープできます。 ●リスト1.1 キャプション(コードのタイトル) function hoge() { alert(foo); … (c1) alert(bar); … (c2) alert(\c1); // \でエスケープできます } ## ソースコード ### 本文埋め込みコード This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,13 +19,13 @@ ・通常の箇条書き ・通常の箇条書き ・通常の箇条書き ■■■連番箇条書き(黒丸数字、連番の場合のデフォルト) (1)連番箇条書き(黒丸数字) (2)連番箇条書き(黒丸数字) (3)連番箇条書き(黒丸数字) (4)連番箇条書き(黒丸数字) (5)連番箇条書き(黒丸数字) ■■■連番箇条書き(白丸数字、重複などの事情で黒丸では不都合なとき) (○1)連番箇条書き(白丸数字) (○2)連番箇条書き(白丸数字) (○3)連番箇条書き(白丸数字) @@ -43,9 +43,11 @@ (c)連番箇条書き(アルファベット) (d)連番箇条書き(アルファベット) (e)連番箇条書き(アルファベット) ■■■本文やリスト中での番号 箇条書き以外の本文やリスト中で番号を書きたいときは、(1)、(2)、(○1)、(○2)、[1]、[2]、(a)、(b)のように書いてください。 [1]hogehogeをします [2]fugafugaと[1]の結果を足し合わせます リスト1.1(○1)ではアラートを出しています。(○2)でもアラートを出しています。(a1)エスケープできます。 ◆list/◆ ●リスト1.1 キャプション(コードのタイトル) function hoge() { @@ -54,7 +56,6 @@ function hoge() { alert(c1); // \でエスケープできます } ◆/list◆ ■■ソースコード ■■■本文埋め込みコード 本文中で流れでコードを掲載するときに使用します。 This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ PDFにすると、以下のような仕上がりになります。 ・書籍版 https://docs.google.com/open?id=0BzbGMS73rIkDUXpyUVlrSUxURXlmMXhQRV9Ua2JCUQ ・WEB+DB PRESS版 https://docs.google.com/open?id=0BzbGMS73rIkDZjdCTnBkMDFUaGF2UDJIdTNfaVJUUQ -
suzuki revised this gist
Mar 29, 2012 . 2 changed files with 19 additions and 9 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -148,7 +148,10 @@ sub to_inao { } elsif ($elem->tag eq 'pre') { my $code = $elem->find('code'); my $text = ''; if (defined($code)) { $text = $code->as_text; } my $list_label = 'list'; my $comment_label = 'comment'; @@ -167,15 +170,23 @@ sub to_inao { # asciiのみカウント。日本語は目視でがんばる my $max = max map { length } grep /^[\x00-\x7f]*$/, split /\r?\n/, $text; if (defined($max)) { if ($text =~ /^●/) { if ($max > MAX_LIST_LENGTH) { warn "リストは" . MAX_LIST_LENGTH . "文字まで!(現在$max使用):\n$text\n\n"; } } else { if ($max > MAX_INLINE_LIST_LENGTH) { warn "本文埋め込みリストは" . MAX_INLINE_LIST_LENGTH . "文字まで!(現在$max使用):\n$text\n\n"; } } } else { warn 'リスト中の文字列に日本語が入っており、最大文字数を正しく計算できませんでした。 See: ' .$0. ':'. $= . "\n"; warn '-' x 72 . "\n"; warn $text; warn '-' x 72 . "\n"; warn "\n"; } # コード内コメント This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ # 見出し1(大見出し、節) ## 見出し2(中見出し、項) -
inao revised this gist
Mar 29, 2012 . 3 changed files with 296 additions and 209 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,35 @@ # 書籍の場合、本文リストは1行73桁(文字)まで use constant MAX_INLINE_LIST_LENGTH => 73; # 本文中に(◯1)や(1)など、リストを参照するときの形式に変換する # 「リスト1.1(c1)を見てください」 # -> # 「リスト1.1(◯1)を見てください」となる # # (d1) -> (1) # desc # (c1) -> (◯1) # circle # (s1) -> [1] # square # (a1) -> (a) # alpha # # エスケープも可能 # (\d1) -> (d1) # (\c1) -> (c1) sub to_list_style { my $text = shift; # convert $text =~ s/\(d(\d+)\)/($1)/g; $text =~ s/\(c(\d+)\)/(○$1)/g; $text =~ s/\(s(\d+)\)/[$1]/g; $text =~ s/\(a(\d+)\)/'(' . chr($1 + 96) . ')'/ge; # escape $text =~ s/\(\\([dcsa]?\d+)\)/($1)/g; return $text; } sub to_inao { my $text = shift; @@ -56,7 +85,12 @@ sub to_inao { $inline =~ s/(\n|\r)//g; # キャプション if ($inline =~ s!^●(.+?)::(.+)!●$1\t$2!) { $inline =~ s!\[(.+)\]$!\n$1!; } # リストスタイル文字の変換 $inline = to_list_style($inline); $p .= $inline; } @@ -114,15 +148,12 @@ sub to_inao { } elsif ($elem->tag eq 'pre') { my $code = $elem->find('code'); my $text = $code->as_text; my $list_label = 'list'; my $comment_label = 'comment'; # キャプション $text =~ s!●(.+?)::(.+)!●$1\t$2!g; # 「!!! cmd」で始まるコードブロックはコマンドライン(黒背景) if ($text =~ /!!!(\s+)?cmd/) { @@ -131,25 +162,20 @@ sub to_inao { $comment_label .= '-white'; } # リストスタイル $text = to_list_style($text); # asciiのみカウント。日本語は目視でがんばる my $max = max map { length } grep /^[\x00-\x7f]*$/, split /\r?\n/, $text; if ($text =~ /^●/) { if ($max > MAX_LIST_LENGTH) { warn "リストは" . MAX_LIST_LENGTH . "文字まで!(現在$max使用):\n$text\n\n"; } } else { if ($max && $max > MAX_INLINE_LIST_LENGTH) { warn "本文埋め込みリストは" . MAX_INLINE_LIST_LENGTH . "文字まで!(現在$max使用):\n$text\n\n"; } } # コード内コメント @@ -164,20 +190,16 @@ sub to_inao { } elsif ($elem->tag eq 'ul') { for my $list ($elem->find('li')) { $inao .= '・' . to_list_style($list->as_trimmed_text) . "\n"; } } elsif ($elem->tag eq 'ol') { my $list_style = $elem->attr('class') || DEFAULT_LIST; my $s = substr $list_style, 0, 1; my $i = 0; for my $list ($elem->find('li')) { $inao .= to_list_style( sprintf('(%s%d)%s', $s, ++$i, $list->as_trimmed_text)) . "\n"; } } elsif ($elem->tag eq 'table') { @@ -236,4 +258,4 @@ =head1 SYNOPSIS markdown2inao.pl input.markdown.txt =cut This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,15 @@ # 見出し1(大見出し、節) ## 見出し2(中見出し、項) ### 見出し3(小見出し、目) 段落冒頭の字下げは、このように手動でお願いします。 改行は、(改行) このように自動で取り除かれます。 通常の本文**強調(ボールド)**通常の本文_斜体(イタリック)_通常の本文`インラインのコード`通常の本文(注:注釈ですよ。)通常の本文<kbd>Enter</kbd>(←キーボードフォント)<span class='red'>赤文字</span>通常の本文<span class='ruby'>外村(ほかむら)</span>(←ルビ)。 > 引用です引用です引用です引用です引用です引用です引用です引用です > 引用です引用です引用です引用です引用です引用です引用です引用です @@ -14,91 +19,157 @@ <div class='column'> #### コラム見出し コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム。 ##### コラム小見出し コラム内でも**強調**などが使えます。 </div> ## 箇条書き(リスト)いろいろ ### 通常の箇条書き * 通常の箇条書き * 通常の箇条書き * 通常の箇条書き * 通常の箇条書き * 通常の箇条書き ### 連番箇条書き(黒丸数字) 1. 連番箇条書き(黒丸数字) 2. 連番箇条書き(黒丸数字) 3. 連番箇条書き(黒丸数字) 4. 連番箇条書き(黒丸数字) 5. 連番箇条書き(黒丸数字) ### 連番箇条書き(白丸数字) <ol class='circle'> <li>連番箇条書き(白丸数字)</li> <li>連番箇条書き(白丸数字)</li> <li>連番箇条書き(白丸数字)</li> <li>連番箇条書き(白丸数字)</li> <li>連番箇条書き(白丸数字)</li> </ol> ### 連番箇条書き(黒四角数字) <ol class='square'> <li>連番箇条書き(黒四角数字)</li> <li>連番箇条書き(黒四角数字)</li> <li>連番箇条書き(黒四角数字)</li> <li>連番箇条書き(黒四角数字)</li> <li>連番箇条書き(黒四角数字)</li> </ol> ### 連番箇条書き(アルファベット) <ol class='alpha'> <li>連番箇条書き(アルファベット)</li> <li>連番箇条書き(アルファベット)</li> <li>連番箇条書き(アルファベット)</li> <li>連番箇条書き(アルファベット)</li> <li>連番箇条書き(アルファベット)</li> </ol> 本文から参照するときは(d1)、(d2)、(c1)、(c2)、(s1)、(s2)、(a1)、(a2)のようにします。 <ol class='square'> <li>hogehogeをします</li> <li>fugafugaと(s1)の結果を足し合わせます</li> </ol> ●リスト1.1 キャプション(コードのタイトル) function hoge() { alert(foo); … (c1) alert(bar); … (c2) alert(\c1); // \でエスケープできます } リスト1.1(c1)ではアラートを出しています。(c2)でもアラートを出しています。(\a1)エスケープできます。 ## ソースコード ### 本文埋め込みコード 本文中で流れでコードを掲載するときに使用します。 function **foo**(a) { // コード内強調 alert(a); (注:こんな風にコメントがつけられます) } (注:見出し的にも使えます) function bar(b) { alert(b); } このように、上下に本文が入ります。 本文から一連の流れで読んでもらうことができますが、コードがページをまたぐ可能性がございます。 ### リスト(名前付きのコード)★要キャプション★ リストは、本文とは別ボックス(別なパーツ)として紙面の端に寄せてレイアウトしますので、コードがページをまたぐことはございません(1ページを超えるコードはまたぎますけど)。 以下、このリストや後述する図や表など、別ボックスものの場合のご注意点です。 * キャプション(タイトル)が必須です * 「**リスト1.1**をご覧ください」「○○のコードを示します(**リスト1.1**)」「○○を**表1.1**にまとめました」みたいな感じで、本文から番号で参照してください * 初出時のみ**リスト1.1**のように太字にします(2度目以降は通常の本文です) (このドキュメントでは、別ボックスものは見出しに★要キャプション★と書いています) ●リスト1.1::キャプション(コードのタイトル) function **foo**(a) { // コード内強調 alert(a); (注:こんな風にコメントがつけられます) } (注:見出し的にも使えます) function bar(b) { alert(b); } ## コマンドの実行結果 コマンドは、「!!! cmd」と付けていただく必要があるだけで、基本的には上記ソースコードと同じです。 ただし、呼称が「リスト」ではなく「図」となります。また、コマンド行の行頭にはプロンプトを付けてください。 ### 本文埋め込みコマンド !!! cmd $ command **foo** // コマンド内強調 bar (注:こんな風にコメントがつけられます) (注:見出し的にも使えます) function bar(b) { alert(b); } ### 図(名前付きのコマンド)★要キャプション★ !!! cmd ●図1.1::キャプション(コマンドのタイトル) $ command **foo** // コマンド内強調 bar (注:こんな風にコメントがつけられます) (注:見出し的にも使えます) function bar(b) { alert(b); } ## 図★要キャプション★ スクリーンショットなど、別ファイルを参照する図です。 ●図1.1::キャプション(図のタイトル)[figure/sample.png] ## 表★要キャプション★ <table summary='表1.1::キャプション(表のタイトル)'> <tr> <th>表タイトル1</th> <th>表タイトル2</th> @@ -113,21 +184,31 @@ figure/sample.png </tr> </table> ## その他の記号 <span class='symbol'>→</span><span class='symbol'>←</span><span class='symbol'>↑</span><span class='symbol'>↓</span> <span class='symbol'>←→</span> <span class='symbol'>>=</span><span class='symbol'>=></span> ## キーボードフォント <kbd>A</kbd>~<kbd>Z</kbd> <kbd>a</kbd>~<kbd>z</kbd> <kbd>0</kbd>~<kbd>9</kbd> <kbd>F1</kbd>~<kbd>F12</kbd> <kbd>→</kbd><kbd>↓</kbd><kbd>↑</kbd><kbd>←</kbd> <kbd>End</kbd> <kbd>Alt</kbd> <kbd>Ctrl</kbd><kbd>Control</kbd> <kbd>Shift</kbd> @@ -147,39 +228,11 @@ figure/sample.png <kbd>Back Space</kbd> <kbd>Space</kbd> <kbd>Pgup</kbd><kbd>Pgdn</kbd> <kbd>Enter</kbd> <kbd>!</kbd> @@ -193,9 +246,9 @@ figure/sample.png <kbd>'</kbd> <kbd>(</kbd><kbd>)</kbd> <kbd>[</kbd><kbd>]</kbd> <kbd>=</kbd> @@ -207,10 +260,6 @@ figure/sample.png <kbd>|</kbd> <kbd>+</kbd> <kbd>*</kbd> @@ -234,19 +283,3 @@ figure/sample.png <kbd>`</kbd> <kbd>"</kbd> This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,85 +1,141 @@ ■見出し1(大見出し、節) ■■見出し2(中見出し、項) ■■■見出し3(小見出し、目) 段落冒頭の字下げは、このように手動でお願いします。改行は、(改行)このように自動で取り除かれます。 通常の本文◆b/◆強調(ボールド)◆/b◆通常の本文◆i/◆斜体(イタリック)◆/i◆通常の本文◆cmd/◆インラインのコード◆/cmd◆通常の本文◆注/◆注釈ですよ。◆/注◆通常の本文Enter▲(←キーボードフォント)◆red/◆赤文字◆/red◆通常の本文◆ルビ/◆外村◆ほかむら◆/ルビ◆(←ルビ)。 ◆quote/◆ 引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です ◆/quote◆ ◆column/◆ ■■■■コラム見出し コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム本文コラム。 ■■■■■コラム小見出し コラム内でも◆b/◆強調◆/b◆などが使えます。 ◆/column◆ ■■箇条書き(リスト)いろいろ ■■■通常の箇条書き ・通常の箇条書き ・通常の箇条書き ・通常の箇条書き ・通常の箇条書き ・通常の箇条書き ■■■連番箇条書き(黒丸数字) (1)連番箇条書き(黒丸数字) (2)連番箇条書き(黒丸数字) (3)連番箇条書き(黒丸数字) (4)連番箇条書き(黒丸数字) (5)連番箇条書き(黒丸数字) ■■■連番箇条書き(白丸数字) (○1)連番箇条書き(白丸数字) (○2)連番箇条書き(白丸数字) (○3)連番箇条書き(白丸数字) (○4)連番箇条書き(白丸数字) (○5)連番箇条書き(白丸数字) ■■■連番箇条書き(黒四角数字) [1]連番箇条書き(黒四角数字) [2]連番箇条書き(黒四角数字) [3]連番箇条書き(黒四角数字) [4]連番箇条書き(黒四角数字) [5]連番箇条書き(黒四角数字) ■■■連番箇条書き(アルファベット) (a)連番箇条書き(アルファベット) (b)連番箇条書き(アルファベット) (c)連番箇条書き(アルファベット) (d)連番箇条書き(アルファベット) (e)連番箇条書き(アルファベット) 本文から参照するときは(1)、(2)、(○1)、(○2)、[1]、[2]、(a)、(b)のようにします。 [1]hogehogeをします [2]fugafugaと[1]の結果を足し合わせます ◆list/◆ ●リスト1.1 キャプション(コードのタイトル) function hoge() { alert(foo); … (○1) alert(bar); … (○2) alert(c1); // \でエスケープできます } ◆/list◆ リスト1.1(○1)ではアラートを出しています。(○2)でもアラートを出しています。(a1)エスケープできます。 ■■ソースコード ■■■本文埋め込みコード 本文中で流れでコードを掲載するときに使用します。 ◆list/◆ function ◆cmd-b/◆foo◆/cmd-b◆(a) { // コード内強調 alert(a); ◆comment/◆こんな風にコメントがつけられます◆/comment◆ } ◆comment/◆見出し的にも使えます◆/comment◆ function bar(b) { alert(b); } ◆/list◆ このように、上下に本文が入ります。 本文から一連の流れで読んでもらうことができますが、コードがページをまたぐ可能性がございます。 ■■■リスト(名前付きのコード)★要キャプション★ リストは、本文とは別ボックス(別なパーツ)として紙面の端に寄せてレイアウトしますので、コードがページをまたぐことはございません(1ページを超えるコードはまたぎますけど)。 以下、このリストや後述する図や表など、別ボックスものの場合のご注意点です。 ・キャプション(タイトル)が必須です ・「リスト1.1をご覧ください」「○○のコードを示します(リスト1.1)」「○○を表1.1にまとめました」みたいな感じで、本文から番号で参照してください ・初出時のみリスト1.1のように太字にします(2度目以降は通常の本文です) (このドキュメントでは、別ボックスものは見出しに★要キャプション★と書いています) ◆list/◆ ●リスト1.1 キャプション(コードのタイトル) function ◆cmd-b/◆foo◆/cmd-b◆(a) { // コード内強調 alert(a); ◆comment/◆こんな風にコメントがつけられます◆/comment◆ } ◆comment/◆見出し的にも使えます◆/comment◆ function bar(b) { alert(b); } ◆/list◆ ■■コマンドの実行結果 コマンドは、「!!! cmd」と付けていただく必要があるだけで、基本的には上記ソースコードと同じです。 ただし、呼称が「リスト」ではなく「図」となります。また、コマンド行の行頭にはプロンプトを付けてください。 ■■■本文埋め込みコマンド ◆list-white/◆ $ command ◆cmd-b/◆foo◆/cmd-b◆ // コマンド内強調 bar ◆comment-white/◆こんな風にコメントがつけられます◆/comment-white◆ ◆comment-white/◆見出し的にも使えます◆/comment-white◆ function bar(b) { alert(b); } ◆/list-white◆ ■■■図(名前付きのコマンド)★要キャプション★ ◆list-white/◆ ●図1.1 キャプション(コマンドのタイトル) $ command ◆cmd-b/◆foo◆/cmd-b◆ // コマンド内強調 bar ◆comment-white/◆こんな風にコメントがつけられます◆/comment-white◆ ◆comment-white/◆見出し的にも使えます◆/comment-white◆ function bar(b) { alert(b); } ◆/list-white◆ ■■図★要キャプション★ スクリーンショットなど、別ファイルを参照する図です。 ●図1.1 キャプション(図のタイトル) figure/sample.png ■■表★要キャプション★ ◆table/◆ ●表1.1 キャプション(表のタイトル) ◆table-title◆表タイトル1 表タイトル2 内容1 内容2 内容1 内容2 ◆/table◆ ■■その他の記号 ◆→◆◆←◆◆↑◆◆↓◆ ◆←→◆ ◆>=◆◆=>◆ ■■キーボードフォント A▲~Z▲ a▲~z▲ 0▲~9▲ F1▲~F12▲ →▲↓▲↑▲←▲ End▲ Alt▲ Ctrl▲Control▲ Shift▲ Tab▲ Esc▲ @@ -89,38 +145,22 @@ Pause▲ Break▲ Home▲ Back Space▲ Space▲ Pgup▲Pgdn▲ Enter▲ !▲ #▲ $▲ %▲ &▲ '▲ (▲)▲ [▲]▲ =▲ -▲ ^▲ ~▲ |▲ +▲ *▲ ;▲ @@ -133,11 +173,3 @@ _▲ @▲ `▲ "▲ -
suzuki revised this gist
Mar 27, 2012 . 1 changed file with 20 additions and 9 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -114,7 +114,10 @@ sub to_inao { } elsif ($elem->tag eq 'pre') { my $code = $elem->find('code'); my $text = ''; if (defined($code)) { $text = $code->as_text; } my $list_label = 'list'; my $comment_label = 'comment'; @@ -130,15 +133,23 @@ sub to_inao { # asciiのみカウント。日本語は目視でがんばる my $max = max map { length } grep /^[\x00-\x7f]*$/, split /\r?\n/, $text; if (defined($max)) { if ($text =~ /^●/) { if ($max > MAX_LIST_LENGTH) { warn "リストは" . MAX_LIST_LENGTH . "文字まで!(現在$max使用):\n$text\n\n"; } } else { if ($max > MAX_INLINE_LIST_LENGTH) { warn "本文埋め込みリストは" . MAX_INLINE_LIST_LENGTH . "文字まで!(現在$max使用):\n$text\n\n"; } } } else { warn 'リスト中の文字列に日本語が入っており、最大文字数を正しく計算できませんでした。 See: ' .$0. ':'. $= . "\n"; warn '-' x 72 . "\n"; warn $text; warn '-' x 72 . "\n"; warn "\n"; } # コード内コメント @@ -225,4 +236,4 @@ =head1 SYNOPSIS markdown2inao.pl input.markdown.txt =cut -
hokaccha revised this gist
Dec 8, 2011 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -145,7 +145,7 @@ figure/sample.png <kbd>Home</kbd> <kbd>Back Space</kbd> <kbd>Enter</kbd> This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -88,7 +88,7 @@ Insert▲ Pause▲ Break▲ Home▲ Back Space▲ Enter▲ F10▲ F11▲ -
hokaccha revised this gist
Dec 8, 2011 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
hokaccha revised this gist
Dec 8, 2011 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
hokaccha revised this gist
Dec 8, 2011 . 3 changed files with 421 additions and 17 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,252 @@ # 見出し1 段落冒頭の字下げは、このように手動でお願いします。 改行は自動で取り除かれます。 このように。 _斜体(イタリック)_通常のところ**強調**通常のことろ`インラインのコード`通常のところ(注:注釈ですよ。)通常のところ<kbd>Enter</kbd>←キーボードになる?<span class='red'>これは赤文字</span>通常のところ<span class='ruby'>外村(ほかむら)</span> > 引用です引用です引用です引用です引用です引用です引用です引用です > 引用です引用です引用です引用です引用です引用です引用です引用です > 引用です引用です引用です引用です引用です引用です引用です引用です > 引用です引用です引用です引用です引用です引用です引用です引用です <div class='column'> #### コラム見出し 本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文 ##### コラム小見出し コラム内での**強調**なんかも可能? </div> ## 見出し2 ●リスト1.1::テストリスト1 * リスト1 * リスト2 * リスト3 * リスト4 * リスト5 ●リスト1.2::テストリスト2 1. リスト1 2. リスト2 3. リスト3 4. リスト4 5. リスト5 ●リスト1.3::テストリスト3 <ol class='circle'> <li>リスト1</li> <li>リスト2</li> <li>リスト3</li> <li>リスト4</li> <li>リスト5</li> </ol> ●リスト1.4::テストリスト4 <ol class='square'> <li>リスト1</li> <li>リスト2</li> <li>リスト3</li> <li>リスト4</li> <li>リスト5</li> </ol> ●リスト1.5::テストリスト5 <ol class='alpha'> <li>リスト1</li> <li>リスト2</li> <li>リスト3</li> <li>リスト4</li> <li>リスト5</li> </ol> ### 見出し3 本文埋め込みブロックの例 function **foo**(a) { // コード内強調 alert(a); (注:こんな風にコメントがつけられます) } 名前つきのコードブロックの例 ●コード1.1::テストコード1 (注:見出し的にも使えます) function bar(b) { alert(b); } コマンドラインのコードブロック !!! cmd ●コード1.2::テストコード2 (注:見出し的にも使えます) function bar(b) { alert(b); } ●画像1.1::テスト画像1 figure/sample.png <table summary='表2::テストの表です'> <tr> <th>表タイトル1</th> <th>表タイトル2</th> </tr> <tr> <td>内容1</td> <td>内容2</td> </tr> <tr> <td>内容1</td> <td>内容2</td> </tr> </table> ### キーボード <kbd>A</kbd>~<kbd>Z</kbd> <kbd>a</kbd>~<kbd>z</kbd> <kbd>0</kbd>~<kbd>9</kbd> <kbd>End</kbd> <kbd>Alt</kbd> <kbd>Ctrl</kbd> <kbd>Control</kbd> <kbd>Shift</kbd> <kbd>Tab</kbd> <kbd>Esc</kbd> <kbd>Delete</kbd> <kbd>Insert</kbd> <kbd>Pause</kbd> <kbd>Break</kbd> <kbd>Home</kbd> <kbd>Back</kbd> <kbd>Enter</kbd> <kbd>F10</kbd> <kbd>F11</kbd> <kbd>F12</kbd> <kbd>F1</kbd> <kbd>F2</kbd> <kbd>F3</kbd> <kbd>F4</kbd> <kbd>F5</kbd> <kbd>F6</kbd> <kbd>F7</kbd> <kbd>F8</kbd> <kbd>F9</kbd> <kbd>→</kbd> <kbd>↓</kbd> <kbd>↑</kbd> <kbd>←</kbd> <kbd>!</kbd> <kbd>#</kbd> <kbd>$</kbd> <kbd>%</kbd> <kbd>&</kbd> <kbd>'</kbd> <kbd>(</kbd> <kbd>)</kbd> <kbd>=</kbd> <kbd>-</kbd> <kbd>^</kbd> <kbd>~</kbd> <kbd>|</kbd> <kbd>[</kbd> <kbd>]</kbd> <kbd>+</kbd> <kbd>*</kbd> <kbd>;</kbd> <kbd>:</kbd> <kbd>,</kbd> <kbd>.</kbd> <kbd>/</kbd> <kbd>?</kbd> <kbd>_</kbd> <kbd>@</kbd> <kbd>`</kbd> <kbd>"</kbd> ### そのほか記号 <span class='symbol'>→</span> <span class='symbol'>←</span> <span class='symbol'>↑</span> <span class='symbol'>↓</span> <span class='symbol'>←→</span> <span class='symbol'>>=</span> <span class='symbol'>=></span> This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -54,6 +54,10 @@ sub to_inao { # 改行を取り除く $inline =~ s/(\n|\r)//g; # キャプション $inline =~ s!^●(.+?)::(.+)!●$1\t$2!; $p .= $inline; } elsif ($inline->tag eq 'code') { @@ -114,6 +118,9 @@ sub to_inao { my $list_label = 'list'; my $comment_label = 'comment'; # キャプション $text =~ s!●(.+?)::(.+)!●$1\t$2!s; # 「!!! cmd」で始まるコードブロックはコマンドライン(黒背景) if ($text =~ /!!!(\s+)?cmd/) { $text =~ s/.+?\n//; @@ -163,22 +170,24 @@ sub to_inao { } } elsif ($elem->tag eq 'table') { my $summary = $elem->attr('summary') || ''; $summary =~ s!(.+?)::(.+)!●$1\t$2\n!; $inao .= "◆table/◆\n"; $inao .= $summary; $inao .= "◆table-title◆"; for my $table ($elem->find('tr')) { for my $item ($table->find('th')){ $inao .= $item->as_trimmed_text; $inao .= "\t"; } for my $item ($table->find('td')){ $inao .= $item->as_trimmed_text; $inao .= "\t"; } chop($inao); $inao .= "\n" } $inao .= "◆/table◆\n"; } elsif ($elem->tag eq 'div' and $elem->attr('class') eq 'column') { $inao .= "◆column/◆\n"; @@ -216,4 +225,4 @@ =head1 SYNOPSIS markdown2inao.pl input.markdown.txt =cut This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,143 @@ ■見出し1 段落冒頭の字下げは、このように手動でお願いします。改行は自動で取り除かれます。このように。 ◆i/◆斜体(イタリック)◆/i◆通常のところ◆b/◆強調◆/b◆通常のことろ◆cmd/◆インラインのコード◆/cmd◆通常のところ◆注/◆注釈ですよ。◆/注◆通常のところEnter▲←キーボードになる?◆red/◆これは赤文字◆/red◆通常のところ◆ルビ/◆外村◆ほかむら◆/ルビ◆ ◆quote/◆ 引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です引用です ◆/quote◆ ◆column/◆ ■■■■コラム見出し 本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文 ■■■■■コラム小見出し コラム内での◆b/◆強調◆/b◆なんかも可能? ◆/column◆ ■■見出し2 ●リスト1.1 テストリスト1 ・リスト1 ・リスト2 ・リスト3 ・リスト4 ・リスト5 ●リスト1.2 テストリスト2 1●リスト1 2●リスト2 3●リスト3 4●リスト4 5●リスト5 ●リスト1.3 テストリスト3 1○リスト1 2○リスト2 3○リスト3 4○リスト4 5○リスト5 ●リスト1.4 テストリスト4 1■リスト1 2■リスト2 3■リスト3 4■リスト4 5■リスト5 ●リスト1.5 テストリスト5 a●リスト1 b●リスト2 c●リスト3 d●リスト4 e●リスト5 ■■■見出し3 本文埋め込みブロックの例 ◆list/◆ function ◆cmd-b/◆foo◆/cmd-b◆(a) { // コード内強調 alert(a); ◆comment/◆こんな風にコメントがつけられます◆/comment◆ } ◆/list◆ 名前つきのコードブロックの例 ◆list/◆ ●コード1.1 テストコード1 ◆comment/◆見出し的にも使えます◆/comment◆ function bar(b) { alert(b); } ◆/list◆ コマンドラインのコードブロック ◆list-white/◆ ●コード1.2 テストコード2 ◆comment-white/◆見出し的にも使えます◆/comment-white◆ function bar(b) { alert(b); } ◆/list-white◆ ●画像1.1 テスト画像1 figure/sample.png ◆table/◆ ●表2 テストの表です ◆table-title◆表タイトル1 表タイトル2 内容1 内容2 内容1 内容2 ◆/table◆ ■■■キーボード A▲~Z▲ a▲~z▲ 0▲~9▲ End▲ Alt▲ Ctrl▲ Control▲ Shift▲ Tab▲ Esc▲ Delete▲ Insert▲ Pause▲ Break▲ Home▲ Back▲ Enter▲ F10▲ F11▲ F12▲ F1▲ F2▲ F3▲ F4▲ F5▲ F6▲ F7▲ F8▲ F9▲ →▲ ↓▲ ↑▲ ←▲ !▲ #▲ $▲ %▲ &▲ '▲ (▲ )▲ =▲ -▲ ^▲ ~▲ |▲ [▲ ]▲ +▲ *▲ ;▲ :▲ ,▲ .▲ /▲ ?▲ _▲ @▲ `▲ "▲ ■■■そのほか記号 ◆→◆ ◆←◆ ◆↑◆ ◆↓◆ ◆←→◆ ◆>=◆ ◆=>◆ -
hokaccha revised this gist
Dec 8, 2011 . 1 changed file with 182 additions and 91 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,111 +8,203 @@ use HTML::TreeBuilder; use List::Util 'max'; # デフォルトのリストスタイル # disc: 黒丸 # square: 四角 # circle: 白丸 # alpha: アルファベット use constant DEFAULT_LIST => 'disc'; # リストの文字数上限 # WEB+DB PRESSの場合、リストは、1行63桁(文字)まで # 書籍の場合、リストは1行69桁(文字)まで use constant MAX_LIST_LENGTH => 69; # 本文埋め込みリストの文字数上限 # WEB+DB PRESSの場合、本文リストは1行55桁(文字)まで # 書籍の場合、本文リストは1行73桁(文字)まで use constant MAX_INLINE_LIST_LENGTH => 73; sub to_inao { my $text = shift; my $html = markdown($text); my $tree = HTML::TreeBuilder->new; $tree->no_space_compacting(1); $tree->parse_content(\$html); my $inao = q[]; my $body = $tree->find('body'); for my $elem ($body->content_list) { if ($elem->tag =~ /^h(\d+)/) { my $level = $1; $inao .= '■' x $level; $inao .= $elem->as_trimmed_text; $inao .= "\n"; } elsif ($elem->tag eq 'p') { my $p = q[]; for my $inline ($elem->content_list) { if (ref $inline eq '') { # (注:)は脚注としてあつかう $inline =~ s!\(注:(.+?)\)!◆注/◆$1◆/注◆!gs; # 改行を取り除く $inline =~ s/(\n|\r)//g; $p .= $inline; } elsif ($inline->tag eq 'code') { $p .= '◆cmd/◆'; $p .= $inline->as_trimmed_text; $p .= '◆/cmd◆'; } elsif ($inline->tag eq 'strong') { $p .= '◆b/◆'; $p .= $inline->as_trimmed_text; $p .= '◆/b◆'; } elsif ($inline->tag eq 'em') { $p .= '◆i/◆'; $p .= $inline->as_trimmed_text; $p .= '◆/i◆'; } elsif ($inline->tag eq 'kbd') { $p .= $inline->as_trimmed_text; $p .= '▲'; } elsif ($inline->tag eq 'span') { my $class = $inline->attr('class'); # 赤字 # <span class='red'>赤字</span> if ($class eq 'red') { $p .= '◆red/◆'; $p .= $inline->as_trimmed_text; $p .= '◆/red◆'; } # ruby # <span class='ruby'>漢字(かんじ)</span> elsif ($class eq 'ruby') { my $ruby = $inline->as_trimmed_text; $ruby =~ s!(.+)\((.+)\)!◆ルビ/◆$1◆$2◆/ルビ◆!; $p .= $ruby; } # その他の記号 # <span class='symbol'>=></span> elsif ($class eq 'symbol') { $p .= '◆'; $p .= $inline->as_trimmed_text; $p .= '◆'; } } } if ($p !~ /^[\s ]+$/) { $inao .= "$p\n"; } } elsif ($elem->tag eq 'pre') { my $code = $elem->find('code'); my $text = $code->as_text; my $list_label = 'list'; my $comment_label = 'comment'; # 「!!! cmd」で始まるコードブロックはコマンドライン(黒背景) if ($text =~ /!!!(\s+)?cmd/) { $text =~ s/.+?\n//; $list_label .= '-white'; $comment_label .= '-white'; } # asciiのみカウント。日本語は目視でがんばる my $max = max map { length } grep /^[\x00-\x7f]*$/, split /\r?\n/, $text; if ($text =~ /^●/) { if ($max > MAX_LIST_LENGTH) { warn "リストは" . MAX_LIST_LENGTH . "文字まで!(現在$max使用):\n$text\n\n"; } } else { if ($max > MAX_INLINE_LIST_LENGTH) { warn "本文埋め込みリストは" . MAX_INLINE_LIST_LENGTH . "文字まで!(現在$max使用):\n$text\n\n"; } } # コード内コメント $text =~ s!\(注:(.+?)\)!◆$comment_label/◆$1◆/$comment_label◆!gs; # コード内強調 $text =~ s!\*\*(.+?)\*\*!◆cmd-b/◆$1◆/cmd-b◆!gs; $inao .= "◆$list_label/◆\n"; $inao .= $text; $inao .= "◆/$list_label◆\n"; } elsif ($elem->tag eq 'ul') { for my $list ($elem->find('li')) { $inao .= '・' . $list->as_trimmed_text . "\n"; } } elsif ($elem->tag eq 'ol') { my $list_style = $elem->attr('class') || DEFAULT_LIST; my $s = { disc => '●', circle => '○', square => '■', alpha => '●', }->{$list_style}; my $i = $list_style eq 'alpha' ? 'a' : 1; for my $list ($elem->find('li')) { $inao .= $i++ . $s . $list->as_trimmed_text . "\n"; } } elsif ($elem->tag eq 'table') { $inao .= "◆table/◆\n"; $inao .= "●" . $elem->attr('summary') . "\n"; $inao .= "◆table-title◆"; for my $table ($elem->find('tr')) { for my $item ($table->find('th')){ $inao .= $item->as_trimmed_text; $inao .= "\t"; } for my $item ($table->find('td')){ $inao .= $item->as_trimmed_text; $inao .= "\t"; } chop($inao); $inao .= "\n" } $inao .= "◆/table◆\n"; } elsif ($elem->tag eq 'div' and $elem->attr('class') eq 'column') { $inao .= "◆column/◆\n"; $inao .= to_inao($elem->as_text); $inao .= "◆/column◆\n"; } elsif ($elem->tag eq 'blockquote') { my $blockquote = $elem->as_trimmed_text; $blockquote =~ s/(\s)//g; $inao .= "◆quote/◆\n"; $inao .= $blockquote; $inao .= "\n◆/quote◆\n"; } } return $inao; } my $infile = $ARGV[0] or pod2usage(-1); open my $fh, '<', $infile or die $!; my $text = do { local $/; <$fh> }; close $fh; print to_inao($text); __END__ @@ -124,5 +216,4 @@ =head1 SYNOPSIS markdown2inao.pl input.markdown.txt =cut -
inao revised this gist
Jan 17, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,7 +72,7 @@ } } else { # 本文埋め込みは、特集の場合55文字まで、連載の場合58文字まで if ($max > 55) { warn "本文埋め込みリストは55文字まで!(現在$max使用):\n$text\n\n"; } -
hsbt revised this gist
Jan 14, 2011 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -105,6 +105,7 @@ $inao .= $item->as_trimmed_text; $inao .= "\t"; } chop($inao); $inao .= "\n" } $inao .= "◆/table◆\n"; -
hsbt revised this gist
Jan 14, 2011 . 1 changed file with 19 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,9 +72,9 @@ } } else { # 本文埋め込みは55文字まで if ($max > 55) { warn "本文埋め込みリストは55文字まで!(現在$max使用):\n$text\n\n"; } } @@ -93,6 +93,22 @@ $inao .= '(' . ++$i .')' . $list->as_trimmed_text . "\n"; } } elsif ($elem->tag eq 'table') { $inao .= "◆table/◆\n"; $inao .= "◆table-title◆"; for my $table ($elem->find('tr')) { for my $item ($table->find('th')){ $inao .= $item->as_trimmed_text; $inao .= "\t"; } for my $item ($table->find('td')){ $inao .= $item->as_trimmed_text; $inao .= "\t"; } $inao .= "\n" } $inao .= "◆/table◆\n"; } } print $inao; @@ -109,4 +125,3 @@ =head1 SYNOPSIS =cut -
typester revised this gist
May 13, 2010 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,6 +34,8 @@ my $p = q[]; for my $inline ($elem->content_list) { if (ref $inline eq '') { # (注:)は脚注としてあつかう $inline =~ s!\(注:(.+?)\)!◆注/◆$1◆/注◆!gs; $p .= $inline; } elsif ($inline->tag eq 'code') { -
typester revised this gist
May 13, 2010 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -65,14 +65,14 @@ my $max = max map { length } grep /^[\x00-\x7f]*$/, split /\r?\n/, $text; if ($text =~ /^●/) { # キャプション付きリスト63文字まで if ($max > 63) { warn "リストは63文字まで!(現在$max使用):\n$text\n\n"; } } else { # 本文埋め込みは58文字まで if ($max > 58) { warn "本文埋め込みリストは58文字まで!(現在$max使用):\n$text\n\n"; } } -
typester revised this gist
May 11, 2010 . 1 changed file with 19 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use Text::Markdown 'markdown'; use HTML::TreeBuilder; use List::Util 'max'; my $infile = $ARGV[0] or pod2usage(-1); @@ -58,8 +59,25 @@ } elsif ($elem->tag eq 'pre') { my $code = $elem->find('code'); my $text = $code->as_text; # asciiのみカウント。日本語は目視でがんばる my $max = max map { length } grep /^[\x00-\x7f]*$/, split /\r?\n/, $text; if ($text =~ /^●/) { # キャプション付きリスト63文字まで if ($text !~ /図/ and $max > 63) { die "リストは63文字まで!(現在$max使用):\n$text\n"; } } else { # 本文埋め込みは58文字まで if ($max > 58) { die "本文埋め込みリストは58文字まで!(現在$max使用):\n$text\n"; } } $inao .= "◆list/◆\n"; $inao .= $text; $inao .= "◆/list◆\n"; } elsif ($elem->tag eq 'ul') { -
typester revised this gist
May 10, 2010 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -73,8 +73,6 @@ $inao .= '(' . ++$i .')' . $list->as_trimmed_text . "\n"; } } } print $inao; -
typester revised this gist
May 10, 2010 . 1 changed file with 15 additions and 11 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,27 +30,31 @@ $inao .= "\n"; } elsif ($elem->tag eq 'p') { my $p = q[]; for my $inline ($elem->content_list) { if (ref $inline eq '') { $p .= $inline; } elsif ($inline->tag eq 'code') { $p .= '◆cmd/◆'; $p .= $inline->as_trimmed_text; $p .= '◆/cmd◆'; } elsif ($inline->tag eq 'strong') { $p .= '◆b/◆'; $p .= $inline->as_trimmed_text; $p .= '◆/b◆'; } elsif ($inline->tag eq 'em') { $p .= '◆i/◆'; $p .= $inline->as_trimmed_text; $p .= '◆/i◆'; } } if ($p !~ /^[\s ]+$/) { $inao .= "$p\n"; } } elsif ($elem->tag eq 'pre') { my $code = $elem->find('code'); -
typester revised this gist
Apr 27, 2010 . 1 changed file with 10 additions and 10 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ if ($elem->tag =~ /^h(\d+)/) { my $level = $1; $inao .= '■' x $level; $inao .= $elem->as_trimmed_text; $inao .= "\n"; } @@ -35,32 +35,32 @@ $inao .= $inline; } elsif ($inline->tag eq 'code') { $inao .= '◆cmd/◆'; $inao .= $inline->as_trimmed_text; $inao .= '◆/cmd◆'; } elsif ($inline->tag eq 'strong') { $inao .= '◆b/◆'; $inao .= $inline->as_trimmed_text; $inao .= '◆/b◆'; } elsif ($inline->tag eq 'em') { $inao .= '◆i/◆'; $inao .= $inline->as_trimmed_text; $inao .= '◆/i◆'; } } $inao .= "\n"; } elsif ($elem->tag eq 'pre') { my $code = $elem->find('code'); $inao .= "◆list/◆\n"; $inao .= $code->as_text; $inao .= "◆/list◆\n"; } elsif ($elem->tag eq 'ul') { for my $list ($elem->find('li')) { $inao .= '・' . $list->as_trimmed_text . "\n"; } } elsif ($elem->tag eq 'ol') { -
typester created this gist
Apr 27, 2010 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,90 @@ #!/usr/bin/env perl use strict; use warnings; use Pod::Usage; use Text::Markdown 'markdown'; use HTML::TreeBuilder; my $infile = $ARGV[0] or pod2usage(-1); open my $fh, '<', $infile or die $!; my $text = do { local $/; <$fh> }; close $fh; my $html = markdown($text); my $tree = HTML::TreeBuilder->new; $tree->parse_content(\$html); my $inao = q[]; my $body = $tree->find('body'); for my $elem ($body->content_list) { if ($elem->tag =~ /^h(\d+)/) { my $level = $1; $inao .= 'â ' x $level; $inao .= $elem->as_trimmed_text; $inao .= "\n"; } elsif ($elem->tag eq 'p') { for my $inline ($elem->content_list) { if (ref $inline eq '') { $inao .= $inline; } elsif ($inline->tag eq 'code') { $inao .= 'âcmd/â'; $inao .= $inline->as_trimmed_text; $inao .= 'â/cmdâ'; } elsif ($inline->tag eq 'strong') { $inao .= 'âb/â'; $inao .= $inline->as_trimmed_text; $inao .= 'â/bâ'; } elsif ($inline->tag eq 'em') { $inao .= 'âi/â'; $inao .= $inline->as_trimmed_text; $inao .= 'â/iâ'; } } $inao .= "\n"; } elsif ($elem->tag eq 'pre') { my $code = $elem->find('code'); $inao .= "âlist/â\n"; $inao .= $code->as_text; $inao .= "â/listâ\n"; } elsif ($elem->tag eq 'ul') { for my $list ($elem->find('li')) { $inao .= 'ã»' . $list->as_trimmed_text . "\n"; } } elsif ($elem->tag eq 'ol') { my $i = 0; for my $list ($elem->find('li')) { $inao .= '(' . ++$i .')' . $list->as_trimmed_text . "\n"; } } $inao .= "\n"; } print $inao; __END__ =head1 NAME markdown2inao.pl - markdown to inao converter =head1 SYNOPSIS markdown2inao.pl input.markdown.txt =cut