Skip to content

Instantly share code, notes, and snippets.

const postcss = require("postcss");
module.exports = postcss.plugin("wrap-with-supports", () => css => {
const supports = postcss.parse("@supports(top:0){}");
css.each(n => {
supports.first.append(n);
});
css.append(supports);
});
/*!
* heading-break.js
* LICENSE: http://hail2u.mit-license.org/2018
*/
const addWordJoiner = (added, value, index) => {
if (index > 3) {
return `${value}${added}`;
}

見出しとテーマの区切りから自動セクショニング

ついにsectionタグを書くのが面倒になってきたので、自動でどうにかしようという試み。

  1. 現在のレベルが1で、見出しレベルも1
  2. 現在のレベルが1より上で、現在のレベルと見出しレベルが同じ
  3. 現在のレベルが1より上で、見出しレベルが現在のレベルより小さい
  4. 現在のレベルより見出しレベルが大きい

パターン1では見出しだけ出力する。パターン4ではsection開始タグだけを、パターン2ではsection終了タグと開始タグを、パターン3ではsection終了タグのみを、追加して出力すればよい。

indent
fence without language
<p>fence with language</p>

blockquote要素で引用元の表記がある場合、figure要素で括られるようにする

最後の行が(EMダッシュ)で始まっていた場合はfigure要素で括り、かつその最後の行を引用元の表記としてfigcaption要素に変換する。

引用元あり

> This is a quote.
>
> — <cite>[txt](href)</cite>

figure要素を書けるようにする

画像に必ずリンクを張ることを条件に、リンクと画像のみの段落をfigure要素になるようフックしてやる。figcaption要素はリンクに指定可能なtitle属性を流用する。

キャプションあり

[![alt](src.png)](href "caption")
@hail2u
hail2u / solarized.vim
Last active March 8, 2018 04:07
Solarizedの暗いやつと明るいやつを`set background`で切り替えられるVimカラースキーム
highlight clear
if exists("syntax_on")
syntax reset
endif
let g:colors_name = "solarized"
highlight Conceal gui=NONE guifg=#268bd2 guibg=NONE
highlight CursorIM gui=NONE guifg=#fdf6e3 guibg=#dc322f
@hail2u
hail2u / test.css
Created May 31, 2017 04:20
nested conditional rules
@supports (display: flex) {
.foo {
display: flex;
}
@media (min-width: 320px) {
@supports (text-decoration-style: wavy) {
.bar {
text-decoration-style: wavy;
}
@hail2u
hail2u / site-search-focus.js
Created May 6, 2017 10:44
検索フォームへフォーカスするために苦労するスクリプト
/*!
* site-search-focus.js
*
* LICENSE: http://hail2u.mit-license.org/2017
*/
"use strict";
function focusSiteSearch() {
document.getElementById("site_search").focus();
}
@hail2u
hail2u / hakone-motomiya.txt
Last active May 9, 2017 04:36
海老名⇔箱根神社元宮
海老名駅
||
小田急線
||
本厚木駅
||
小田急線ロマンスカー
||
御殿場駅
||