Skip to content

Commit

Permalink
Update: TOC Style (cfug#1419)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmosHuKe authored Mar 10, 2024
1 parent 8f5d9ca commit 78048a8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tool/translator/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
const gulp = require('gulp');
const replace = require('gulp-replace');

// 去掉中文标点与中文间的空格
gulp.task('remove-space', () => {
return gulp.src(['../../_site/**/*.html'])
.pipe(replace(/([\u3000-\u303F\u4e00-\u9fa5\uF900-\uFFEF])\s+(?=[\u3000-\u303F\u4e00-\u9fa5\uF900-\uFFEF])/gs, '$1'))
.pipe(gulp.dest('../../_site'));
.pipe(replace(/([\u3000-\u303F\u4e00-\u9fa5\uF900-\uFFEF])\s+(?=[\u3000-\u303F\u4e00-\u9fa5\uF900-\uFFEF])/gs, '$1'))
.pipe(gulp.dest('../../_site'));
});

// 匹配替换目录相关格式
gulp.task('mark-side-toc', () => {
const tocRegexp = /<li class="toc-entry (nav-item )?toc-h(\d)"><a (class="nav-link" )?href="#(.*?)">(?!.*[\u4e00-\u9fa5])(.*?)<\/a><\/li>\n.*>(?=.*[\u4e00-\u9fa5])(.*?)<\/a>/g;
return gulp.src(['../../_site/**/*.html'])
.pipe(replace(/<li class="toc-entry (nav-item )?toc-h(\d)"><a (class="nav-link" )?href="#(.*?)">(?!.*[\u4e00-\u9fa5])(.*?)<\/a><\/li>\n.*>(?=.*[\u4e00-\u9fa5])(.*?)<\/a>/g, '<li class="toc-entry $1toc-h$2"><a $3href="#$4"><p>$5</p><p>$6</p></a>'))
.pipe(gulp.dest('../../_site'));
.pipe(replace(tocRegexp, `<li class="toc-entry $1toc-h$2"><a $3href="#$4"><t>$5</t><t>$6</t></a>`))
.pipe(gulp.dest('../../_site'));
});

0 comments on commit 78048a8

Please sign in to comment.