小説テキスト html コンバーター
SYNOPSIS
narou2html.py [-i shift_jis|utf-8|euc]
[-e shift_jis|utf-8|euc]
[-br]
[-sdd | -sda]
[readfile.txt [writefile.html]]
DESCRIPTION
Convert Narou-style novel text to HTML.
Input and output are decoded/encoded according to the
specified character encodings. Internally, all processing
is performed as Unicode.
Input line endings are normalized to LF.
OPTIONS
-i ENCODING
Input encoding.
shift_jis
utf-8
euc
Default: shift_jis
-e ENCODING
Output encoding.
shift_jis
utf-8
euc
Default: utf-8
-br
In normal paragraphs, use ¥¥ as an explicit
line-break marker instead of actual line endings.
Without -br:
actual line endings ->
With -br:
¥¥ ->
Dialogue and monologue line endings are converted
to
regardless of this option.
-sdd
Convert a standalone line containing ◇◇ to a
dashed story divider.
-sda
Convert a standalone line containing ◇◇ to an
asterism story divider.
Without -sdd or -sda, ◇◇ is treated as normal text.
-h
Show this help.
SOURCE TEXT MARKUP
The following conventions are recognized inside the input
text itself. They are not command-line options.
【TITLE―SUBTITLE/AUTHOR】
A standalone line enclosed in 【】 is converted to
a title block, without requiring blank lines around it.
The subtitle (after ―) is optional. "/" and "/" are
both accepted as the author delimiter.
The author name is preserved as-is, except for
surrounding whitespace.
Continuation markers
A standalone line containing one full-width space ( )
makes the next block a continuation of the preceding
block.
A standalone line containing two full-width spaces
( ) makes the next block a continuation and inserts
one blank line between the blocks.
The markers themselves are not output.
EXAMPLES
# Standard input -> standard output
narou2html.py
# novel.txt -> standard output
narou2html.py novel.txt
# novel.txt -> novel.html
narou2html.py novel.txt novel.html
# Shift_JIS input -> UTF-8 output
narou2html.py -i shift_jis -e utf-8 novel.txt novel.html
# UTF-8 input -> Shift_JIS output
narou2html.py -i utf-8 -e shift_jis novel.txt novel.html
# EUC-JP input -> UTF-8 output
narou2html.py -i euc -e utf-8 novel.txt novel.html
# Use ¥¥ as explicit line-break markers
narou2html.py -br novel.txt novel.html
# Convert ◇◇ to a dashed story divider
narou2html.py -sdd novel.txt novel.html
# Convert ◇◇ to a ? story divider
narou2html.py -sda novel.txt novel.html
小説家になろうで使われているルビの表記
|漢字《かんじ》を、HTML の
<ruby> 要素に変換します。
タイトルは、【タイトル―サブタイトル/作者名】の形式で記述します。
たとえば、
【春は過ぐとも―regeneration/夏澤ひかり】
は、次のように変換されます。
<div class="title-block">
<h2>春は過ぐとも</h2>
<p class="subtitle">regeneration</p>
<div class="author">
夏澤ひかり
</div>
</div>
― がある場合は、それより前をタイトル、
それより後をサブタイトルとして扱います。
/ または / がある場合は、それより後を作者名として扱います。
空行がブロックやパラグラフの区切りになります。
本文中の、全角空白文字だけからなる行は、本文ではなく構造情報として扱います。
全角空白1個だけの行
「大丈夫大丈夫、隣もカップルだし」
(も…なんだ)
は、次のブロックを continuation として扱います。
全角空白そのものは出力されません。
<div class="dialogue">「大丈夫大丈夫、隣もカップルだし」</div>
<div class="monologue continuation">(も…なんだ)</div>
全角空白2個だけの行
「大丈夫大丈夫、隣もカップルだし」
(も…なんだ)
は、次のブロックを continuation とし、
さらにその間に空行を入れます。全角空白そのものは出力されません。
<div class="dialogue">「大丈夫大丈夫、隣もカップルだし」</div>
<br>
<div class="monologue continuation">(も…なんだ)</div>
一方、全角空白に続いて文字がある場合は、従来どおり本文として扱います。
和歌 → waka 通常の文章 → 通常のテキストつまり、行全体が全角空白だけの場合に限って構造情報として解釈されます。
前後が空行で2つの太横罫線 ━━ は
hr.story-divider になります。
前後が空行で2つの太縦罫線 ┃┃ は
div.story-divider になります。
前後が空行で2つの菱形 ◇◇ は、
オプション -sdd / -sda により、
hr.story-divider / div.story-divider になります。
オプションを指定しないときは、そのままになります。
全角カギ括弧「会話」は dialogue になります。
全角丸括弧(モノローグ)は monologue となります。
全角二重カギ括弧『メッセージ』は message となります。
先頭が全角スペース2つで始まる行
和歌 は waka となります。
また、分かち書きの和歌などは、2つずつ重ねた 波括弧で囲んだ箇所を
{{分かち書きの 和歌}}
の waka として扱います。
内部の空白文字は保持されます。
(夏澤ひかり「春は過ぐとも」より引用)
【春は過ぐとも―regeneration/夏澤ひかり】 ━━ まばらに桜が咲いている公園を抜けて展望台へ行く。 「わぁ、綺麗…」 対岸の嵐山に丸く、白く、ほのかに紅く、山桜が咲いている。途中にあった|権中納言《ごんちゅうなごん》|匡房《まさふさ》の歌がまさにぴったりだ。 たかさこの尾上の桜咲きにけり 外山の霞立たすもあらなむ (本当に綺麗…また一緒にこの景色見れるといいなぁ…) ┃┃ 車内販売のコーヒーと生八ツ橋、リアルで大好きだったのになぁ…寂しいなぁ… {{ 奥山に紅葉踏み分け なく鹿の声聞くときぞ 秋は悲しき }}
<div class="title-block">
<h2>春は過ぐとも</h2>
<p class="subtitle">regeneration</p>
<div class="author">
夏澤ひかり
</div>
</div>
<hr class="story-divider">
<p>まばらに桜が咲いている公園を抜けて展望台へ行く。</p>
<div class="dialogue">「わぁ、綺麗…」</div>
<p>対岸の嵐山に丸く、白く、ほのかに紅く、山桜が咲いている。途中にあった<ruby>権中納言<rt>ごんちゅうなごん</rt></ruby><ruby>匡房<rt>まさふさ</rt></ruby>の歌がまさにぴったりだ。</p>
<div class="waka">たかさこの尾上の桜咲きにけり 外山の霞立たすもあらなむ</div>
<div class="monologue">(本当に綺麗…また一緒にこの景色見れるといいなぁ…)</div>
<div class="story-divider" aria-hidden="true">⁂</div>
<p>車内販売のコーヒーと生八ツ橋、リアルで大好きだったのになぁ…寂しいなぁ…</p>
<div class="waka">奥山に紅葉踏み分け
なく鹿の声聞くときぞ
秋は悲しき</div>
regeneration
まばらに桜が咲いている公園を抜けて展望台へ行く。
対岸の嵐山に丸く、白く、ほのかに紅く、山桜が咲いている。途中にあった権中納言匡房の歌がまさにぴったりだ。
車内販売のコーヒーと生八ツ橋、リアルで大好きだったのになぁ…寂しいなぁ…
.story-divider {
margin-block: 1.5em;
}
hr.story-divider {
width: 50%;
border: none;
border-top: 1px dashed #888;
margin-inline-start: 1.5em;
}
div.story-divider {
text-align: center;
font-size: 0.8em;
}
.continuation {
margin: 0;
text-indent: 0;
}
.message,
.dialogue,
.monologue {
margin-left: 1em;
margin-top: 1em;
margin-bottom: 1em;
}
.waka {
white-space: pre-wrap;
margin: 1.5em 0 1.5em 3em;
font-family: "Yu Mincho", "Hiragino Mincho ProN", "YuMincho", serif;
font-size: 1.05em;
font-weight: bold;
line-height: 1.0;
color: #421;
}
.title-block h2 {
font-size: 1.7em;
font-weight: 600;
margin: 0.2em 0;
letter-spacing: 0.5px;
border-bottom: none !important;
}
.title-block .subtitle {
font-size: 1.2em;
font-weight: 400;
color: #555;
margin: 0.4em 0 1.2em;
font-style: italic;
}