narou2html.py

小説テキスト html コンバーター

Rev.1.6 (2026-10-11)
Generated by ChatGPT and Claude with Hikari NATSUZAWA
Supervised by Takayuki HOSODA (aka Lyuka)

概要

主に小説家になろうで使われるルビの表記と、会話や和歌を含むテキストを html に変換するツールです。 python2.7 用です。

narou2html.py

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>

一方、全角空白に続いて文字がある場合は、従来どおり本文として扱います。

つまり、行全体が全角空白だけの場合に限って構造情報として解釈されます。

class について

前後が空行で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

夏澤ひかり

まばらに桜が咲いている公園を抜けて展望台へ行く。

「わぁ、綺麗…」

対岸の嵐山に丸く、白く、ほのかに紅く、山桜が咲いている。途中にあった権中納言ごんちゅうなごん匡房まさふさの歌がまさにぴったりだ。

たかさこの尾上の桜咲きにけり 外山の霞立たすもあらなむ
(本当に綺麗…また一緒にこの景色見れるといいなぁ…)

車内販売のコーヒーと生八ツ橋、リアルで大好きだったのになぁ…寂しいなぁ…

奥山に紅葉踏み分け     なく鹿の声聞くときぞ             秋は悲しき

css

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