蔵風人

If you try it, it will be somehow & Simple is Best!

[ HOME ]  [ About ]  [ Linux ]  [ CMS ]  [Python]  [ Blog ]


[ 最終更新日:2026-06-01(Mon) 12:52 ]

目次

Python Markdownを使って HTML を作成しよう

今回は Python Markdown を使います

この結果は、以下の拡張機能を有効にしています。

html = markdown.markdown(text,extensions=['tables','fenced_code', 'codehilite', 'toc',  'footnotes','markdown_checklist.extension'] 

ライン

二重線は機能せず


===

リスト

The syntax rules clearly state that when a list item consists of multiple paragraphs, “each subsequent paragraph in a list item must be indented by either 4 spaces or one tab” (emphasis added). However, many implementations do not enforce this rule and allow less than 4 spaces of indentation. The implementers of Python-Markdown consider it a bug to not enforce this rule..Indentation/Tab Length

  1. 番号付きリスト1
    1. 入れ子の番号リスト1-1
    2. 入れ子の番号リスト1-2
  2. 番号付きリスト2

コード

コードはOK

print('Hello World!') 
<?php
phpinfo();
?>
echo Hellow World!

リンク

リンクはOK

テーブル

テーブルもOK 枠線はCSSの役目

タイトル 価格 在庫 ホームページ
これから学ぶHTML/CSS \2,400(税抜き) 1 株式会社インプレス
3ステップでしっかり学ぶJavaScript \2,380(税抜き) 1 科学技術評論社

引用と脚注

引用はOK

This is a Python implementation of John Gruber’s Markdown. It is almost completely compliant with the reference implementation, though there are a few very minor differences. See John’s Syntax Documentation for the syntax rules.1

入れ子の引用

「月日は百代の過客にして、行きかふ年もまた旅人なり。舟の上に生涯を浮かべ、馬の口とらへて老を迎ふる者は、日々旅にして旅を栖(すみか)とす。古人も多く旅に死せるあり。我もまた旅人也。」2

チェックボックス

拡張機能でOK

表示

表示はOK 打ち消し線はだめ

斜体

強調

単語の一部を強調します。

イタリック体

~~打ち消し線~~


ここからは独自の拡張です。どのように格好良く見せるかは css 次第です。

Warning

こちらは警告用で、赤枠で囲み中の記事の一文字目だけ大文字の表現を行っております。

warning!
This is a pen
This is a pencil
That is a fork

Note

こちらはメモ用で、ブルー枠で囲み1行目だけをブルーで表示しております。

どちらが良いか?迷っています。が、最終的には上の方式(一字だけ大文字)を採用し、色はブルー枠としました。

note!
Let It Be!
When I find myself in times of trouble
Mother Mary comes to me
Speaking words of wisdom Let it be...
「Let it be(レットイットビー)」の正しい意味は?和訳歌詞もご紹介 より


  1. the project websiteより 

  2. 松尾芭蕉の紀行文『奥のほそ道』より