コードブロック記法の拡張子を指定する記法
code:A(B)と記述することで、コードブロック記法のタイトルをAとしたままBの言語のsyntax highlightを適用できるらしい
つまり、こういうこと
code:TypeScript(sh)
if 1 -gt 0; then
echo "I'm TypeScript!"
fi
code:TypeScript(sh)と記述しているので、タイトルはTypeScriptなのにsyntax highlightはshが適用されている
実装
assets/index.jsを読むと、だいたいこんな感じ
code:detectCodeBlockStart.js
export const detectCodeBlockStart = (text) => {
const matches = text.match(/^\s*code:(.+)\((^()+)\)$/)
?? text.match(/^\s*code:(.+)$/);
if (!matches) return {};
const filename, lang = matches;
return {
filename: filename.trim(),
lang: lang || filename.split(".").pop() ?? "",
};
};
参考元とまともな実用例
/forum-jp/code:sh が bash にされてしまう#612c724d6e28f90000f1e4d3
正式名称が分からなかったtakker.icon
他の表現
/takker/code:filename(language)
/programming-notes/コードブロック記法の拡張子を明示的に指定