Home / 駄文 / 覚書 / PHP Markdown Extra 解説
PHP Markdown Extra 解説
ブロック要素内でのMarkdown
一部のブロック要素内ではMarkdownによる変換を行わないが、ブロック要素にattributeとしてmarkdownを追加し、valueに1とすることにより可能となる。
生成前:
<div markdown="1">
This is *true* markdown text.
</div>
生成後:
<div>
<p>This is <em>true</em> markdown text.</p>
</div>
このようにmarkdown=”1″を挿入すれば以下のように生成される。
<table>
<tr>
<td markdown="block">This is *true* markdown text.</td>
</tr>
</table>
tdはブロック要素を入れられるので、valueにblockと入れることで、td内でも段落付きにしたりとかも可能。
ヘッダー属性
ヘッダ名を記述した行の最後に、スペース1文字以上を空けて{}で囲むようにid名を指定するとattributeをつけることが出来る。
生成前:
#Header 1 {#header1}
生成後:
<h1 id="header1">Header 1</h1>
あとはこんな感じでリンクを作成するといいだろう。
[Link back to header 1](#header1)
テーブル
シンプルに入力すればテーブルとして生成してくれる。ハイフンで区切ると上がthead、下がtbodyの中に格納される。ちなみにその区別はハイフン一つ以上とパイプ一つがあれば十分らしい。
生成前:
First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell
生成後:
<table>
<thead>
<tr>
<th>First Header</th>
<th>Second Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>Content Cell</td>
<td>Content Cell</td>
</tr>
<tr>
<td>Content Cell</td>
<td>Content Cell</td>
</tr>
</tbody>
</table>
ハイフンのあとにコロンを入れることで列全体を寄せることができる。上記なら右に寄る。左端に入れれば左に。両方に入れれば中央寄せとなる。
Item | Value
--------- | -----:
Computer | $1600
Phone | $12
Pipe | $1
テーブル内でのMarkdown記法も可能。両側のパイプはあってもなくてもOK。
| Function name | Description |
| ------------- | ------------------------------ |
| `help()` | Display the help window. |
| `destroy()` | **Destroy your computer!** |
定義リスト
タイトルの次の行にコロンと一つ以上の空白を付けることで定義リストになる。
生成前:
Apple
: Pomaceous fruit of plants of the genus Malus in
the family Rosaceae.
Orange
: The fruit of an evergreen tree of the genus Citrus.
生成後:
<dl>
<dt>Apple</dt>
<dd>Pomaceous fruit of plants of the genus Malus in
the family Rosaceae.</dd>
<dt>Orange</dt>
<dd>The fruit of an evergreen tree of the genus Citrus.</dd>
</dl>
空行を挟むと、dd内がpで囲まれるようになる。
生成前:
Apple
: Pomaceous fruit of plants of the genus Malus in
the family Rosaceae.
Orange
: The fruit of an evergreen tree of the genus Citrus.
生成後:
<dl>
<dt>Apple</dt>
<dd>
<p>Pomaceous fruit of plants of the genus Malus in
the family Rosaceae.</p>
</dd>
<dt>Orange</dt>
<dd>
<p>The fruit of an evergreen tree of the genus Citrus.</p>
</dd>
</dl>
強調
I like it when you say _you love me_.
Please open the folder "secret_magic_box".
今までは上の行のようにアンダーバーで囲んだ部分はemで囲むようにしていたが、下の行のようにリテラルっぽくしとけば変換することは無い。
回避
コロンとパイプを直接表示したいならバックスラッシュでよろしく。
Info
Comment
投稿したコメントは公開されません。サイトオーナーのみが閲覧できます。
返信等を希望する場合は、コメント内に連絡先のメールアドレスかサイトのURLを入力してください。