Skip to content

Instantly share code, notes, and snippets.

@masamunet
Last active October 14, 2016 05:16
Show Gist options
  • Save masamunet/ae36d69f6c35ce3029b5ff40b270061b to your computer and use it in GitHub Desktop.
Save masamunet/ae36d69f6c35ce3029b5ff40b270061b to your computer and use it in GitHub Desktop.
Scrivenerの出力ファイルを縦書きにして最強の小説エディタ化させるgulpfile ref: http://qiita.com/masamunet/items/ab9e9882a1e78772dd92
npm run replace
npm run gulp
var gulp = require('gulp'),
replace = require('gulp-replace');
const css = `
body{
font-family: "HiraMinProN-W3", "@MS 明朝", serif, sans-serif;
writing-mode: vertical-rl;
-webkit-writing-mode: vertical-rl;
-epub-writing-mode: vertical-rl;
line-height: 1.75em;
text-align: justify;
margin:0;
padding:0;
font-size:1em;
}
body.vertical {
writing-mode: vertical-rl;
-webkit-writing-mode: vertical-rl;
-epub-writing-mode: vertical-rl;
}
body.horizontal{
writing-mode:horizontal-tb;
-epub-writing-mode:horizontal-tb;
-webkit-writing-mode:horizontal-tb;
}
/*
縦中横
縦書きに混じる!?や平成25年、ABCなどの半角英数字や記号などを正立
*/
.tcy {
font-size:0.9em;
letter-spacing:-0.1ex;
text-combine: horizontal;
-webkit-text-combine: horizontal;
-epub-text-combine: horizontal;
}
/*
傍点
*/
span.sesami {
text-emphasis-style : sesame;
text-emphasis-color : #000;
-epub-text-emphasis-style : sesame;
-epub-text-emphasis-color : #000;
-webkit-text-emphasis-style : sesame;
-webkit-text-emphasis-color : #000;
}
/*
かぎかっこ開始行で字下げを行わない場合
*/
p.escape{
text-indent:0;
}
`;
const styleTag = `<style>${css}</style>`;
gulp.task('replace', () =>{
return gulp
.src('*.html')
.pipe(replace('</head>', `${styleTag}</head>`))
.pipe(replace('《《', '<span class="sesami">')).pipe(replace('》》', '</span>'))
.pipe(replace(/|?([々?一-龠]+)《(.+?)》/g, '<ruby>$1<rt>$2</rt></ruby>'))
.pipe(replace(/<p class="(.+?)">「/g, '<p class="$1 escape">「'))
.pipe(gulp.dest('./convert'));
});
gulp.task('watch', ()=>{
return gulp
.watch('*.html', ['replace']);
});
gulp.task('default', ['watch']);
{
"scripts": {
"gulp": "gulp",
"replace": "gulp replace"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-replace": "^0.5.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment