Open3
Prettier 小ネタ
メンテしてて「そんな機能あったんだ...」ってなった機能や、自分で追加した「誰も気づかないだろうなーこの機能」っていうものを見つけたら貼る場所
/* HTML */
みたいなコメントでテンプレートリテラルをその言語としてフォーマットできる。
Prettier 2.4.1
Playground link
--parser babel
Input:
const foo = /* HTML */ `<div><p>hogehoge</p><span>happy</span></div>`
Output:
const foo = /* HTML */ `<div>
<p>hogehoge</p>
<span>happy</span>
</div>`;
lang
属性をつけると Vue の custom block をフォーマットできる。詳細わすれたけど実装がすげーだるかった記憶がある。
Prettier 2.4.1
Playground link
--parser vue
Input:
<custom-block lang="json">
[{ "one": 1, "two": 2, "three": 3},{ "one": 1, "two": 2, "three": 3},{ "one": 1, "two": 2, "three": 3}]
</custom-block>
Output:
<custom-block lang="json">
[
{ "one": 1, "two": 2, "three": 3 },
{ "one": 1, "two": 2, "three": 3 },
{ "one": 1, "two": 2, "three": 3 }
]
</custom-block>