LoginSignup
11
6

More than 1 year has passed since last update.

Markdownの真実—俺たちが慣れ親しんだ「バッククォートのコードブロック」は実は拡張記法だったんだぜ

Last updated at Posted at 2018-08-10

拡張記法

バッククォートは拡張記法。
「行頭スペース四個」でのコードブロックが基本記法らしい。

The basic Markdown syntax allows you to create code blocks by indenting lines by four spaces or one tab. If you find that inconvenient, try using fenced code blocks. Depending on your Markdown processor or editor, you’ll use three tick marks (```) or three tildes (~~~) on the lines before and after the code block.

Extended Syntax | Markdown Guide

その他には、例えばテーブル記法も拡張のようだ。

学習

Markdownにも基本記法とか、拡張記法とかがあることをはじめて知った。

たとえばQiitaではコードブロックにファイル名まで書けたり、Markdownの解釈にもバリエーションがあることは薄々意識していたが、慣れ親しんだコードブロック記法自体が拡張記法だったんだな。

image.png

Githubでも普通に拡張記法のコードブロックを消化してるけど、まあ各サービスのヘルプで「これこれが実は拡張記法で」なんてわざわざ説明しないのは当たり前だよね。

image.png

そういえばStackoverflowでは、コードブロックを書くために毎行毎行4個の空白を入れさせられて「なんだこの冗長な記法は!」と思っていたけど、これがMarkdownの基本だったんだな。

チルダでコードブロック

これも初耳だった!
Qiitaもちゃんと対応している。

image.png

echo Mark down 

経緯

Ruby gem の redcarpet がうまくコードブロックをパースしてくれないことに気付いた。
gemのバグかと思い Issue を出したら robin850 (Robin Dupret) さんが教えてくれた。

バッククォートでのコードブロックは「オリジナルのマークダウン記法ではサポートしてないよ!」って。

Actually you need to enable the fenced_code_blocks option; this syntax is not supported by original Markdown, so you should rather write:

Can not parse well Markdown syntax in code block · Issue #659 · vmg/redcarpet

後で読んだら、思い切りREADMEに書いてあった。すいません。

:fenced_code_blocks: parse fenced code blocks, PHP-Markdown style. Blocks delimited with 3 or more ~ or backticks will be considered as code, without the need to be indented. An optional language name may be added at the end of the opening fence for the code block.

ただ大本の原因は、Markdownの超基本だと思いこんでいた「バッククォートでのコードブロック」が拡張だという前提理解がなかったせいだ。

私の意見

空白4個でのコードブロックとか書く方にとっては苦痛でしかないし、明らかにバッククォートのほうが優れているし流通していると思うのだけど、もう基本表現に昇格させてあげても良いんじゃないだろうか。

HTMLの世界でも独自拡張のタグが標準仕様に取り入れられたりするように。

追記

CommonMark という標準仕様策定の動きもある様子。
( この記事の @scivola さんのコメントを参照 … Thanks! )

リンク

Gist

あわせて読みたい?

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

11
6
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
6