Post

GitHub マークダウン文法のまとめ

Markdownとは何かを理解し、GitHub Pagesブログホスティングのために、GitHub Flavored Markdownを基準に主要なMarkdown文法をまとめました。

GitHub Pagesを活用するためには、markdown文法について知る必要があります。 GitHub公式ドキュメントのMastering MarkdownBasic writing and formatting syntaxを参考に作成しました。

1. マークダウンとは

マークダウン(markdown)は、一般的なテキストベースの軽量マークアップ言語です。一般的なテキストで書式付きの文書を作成するのに使用され、一般的なマークアップ言語に比べて文法が簡単で簡潔なのが特徴です。HTMLやリッチテキスト(RTF)などの書式付き文書に簡単に変換できるため、アプリケーションソフトウェアと一緒に配布されるREADMEファイルやオンライン投稿などによく使用されます。

ジョン・グルーバーは2004年に、文法面でアーロン・スワーツとの重要な協力を通じてマークダウン言語を作成しました。人々が読みやすく書きやすいプレーンテキストフォーマットを使用して書くことができ、構造的に有効なXHTML(またはHTML)に選択的に変換できるようにすることが目標です。

-ウィキペディア、マークダウン

2. マークダウン文法

マークダウンは決まった標準がないため、細かい文法は使用場所によって少しずつ異なる場合があります。ここでまとめたマークダウン文法はGitHub Flavored Markdown基準です。

2.1. 改行、段落の区切り

マークダウンではエンターキー1回は改行として認識されません。

1
2
3
1つ目の文。
2つ目の文。
3つ目の文。

1つ目の文。 2つ目の文。 3つ目の文。

改行は空白を連続して2つ以上入力すると適用されます。

1
2
3
1つ目の文。  
2つ目の文。  
3つ目の文。

1つ目の文。
2つ目の文。
3つ目の文。

段落と段落の間は空行(エンターキー2回)で区切ります。

1
2
3
1つの段落。

別の段落。

1つの段落。

別の段落。

2.2. 見出し(Headers)

全部で6段階あります。

1
2
3
4
5
6
# This is an H1
## This is an H2
### This is an H3
#### This is an H4
##### This is an H5
###### This is an H6

This is an H1

This is an H2

This is an H3

This is an H4

This is an H5
This is an H6

2.3. 強調

1
2
3
4
5
6
7
8
9
10
11
*This text is italicized*
_This is italicized too_

**This is bold text**
__This is bold text too__

~~This was mistaken text~~

_You **can** combine them_

***All this text is important***

This text is italicized
This is italicized too

This is bold text
This is bold text too

This was mistaken text

You can combine them

All this text is important

2.4. テキストの引用

>を使用します。

1
2
3
> This is a first blockquote.
>> This is a second blockquote.
>>> This is a third blockquote.

This is a first blockquote.

This is a second blockquote.

This is a third blockquote.

2.5. コードの引用

```または~~~を使用します。

1
2
3
4
5
```
git status
git add
git commit
```
1
2
3
git status
git add
git commit

プログラミング言語を指定して構文強調表示を有効にすることもできます。

1
2
3
4
5
```ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
```
1
2
3
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html

2.6. リンク

1
2
[GitHub Pages](https://pages.github.com/)
<https://pages.github.com/>

GitHub Pages
https://pages.github.com/

リポジトリ内の他のファイルを指す相対パスリンクも使用できます。使用方法はターミナルでと同じです。

1
[README](../README.md)

2.7. 非順序リスト

-や*を使用します。

1
2
3
- George Washington
- John Adams
- Thomas Jefferson
  • George Washington
  • John Adams
  • Thomas Jefferson

2.8. 順序リスト

数字を使用します。

1
2
3
1. James Madison
2. James Monroe
3. John Quincy Adams
  1. James Madison
  2. James Monroe
  3. John Quincy Adams

2.9. ネストされたリスト

1
2
3
1. First list item
   - First nested list item
     - Second nested list item
  1. First list item
    • First nested list item
      • Second nested list item

2.10. タスクリスト

タスクリストを作成するには、各項目の前に[ ]を追加します。 完了したタスクを表示するには[x]を使用します。

1
2
3
- [x] Finish my changes
- [ ] Push my commits to GitHub
- [ ] Open a pull request
  • Finish my changes
  • Push my commits to GitHub
  • Open a pull request

2.11. 画像の添付

1
2
3
4
方法: ![(オプション)画像の説明](url){(オプション)追加オプション}
![GitHub Logo](/images/logo.png)
![GitHub Logo](/images/logo.png){: .align-center}
![GitHub Logo](/images/logo.png){: width="50%" height="50%"}

2.12. 表の作成

|と-を使用して表を作成できます。 表の前に1行空けておく必要があります。 少なくとも3つ以上の-を使用する必要があります。

1
2
3
4
5
| Left-aligned | Center-aligned | Right-aligned |
| :---         |     :---:      |          ---: |
| git status   | git status     | git status    |
| git diff     | git diff       | git diff      |
Left-alignedCenter-alignedRight-aligned
git statusgit statusgit status
git diffgit diffgit diff
This post is licensed under CC BY-NC 4.0 by the author.

Comments powered by Disqus.