Skip to content

Commit

Permalink
Merge pull request #30 from obgnail/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
obgnail authored Jul 27, 2023
2 parents 5b9ef88 + db425b1 commit 9594fdc
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 5 deletions.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
| 9 | file_counter | 显示目录下的文件数 ||
| 10 | resize_table | 调整表格行高列宽 ||
| 11 | resize_image | 调整图片显示大小 ||
| 12 | go_top | 一键到文章顶部 ||
| 13 | truncate_text | 暂时隐藏内容,提高大文件渲染性能 ||
| 14 | right_click_menu | 右键菜单统一管理、调用插件 ||
| 15 | mermaid_replace | 替换 mermaid 组件 | × |
| 16 | old_window_tab | 标签页管理(已废弃) | × |
| 12 | auto_number | 章节、大纲、表格、图片自动编号 ||
| 13 | go_top | 一键到文章顶部 ||
| 14 | truncate_text | 暂时隐藏内容,提高大文件渲染性能 ||
| 15 | right_click_menu | 右键菜单统一管理、调用插件 ||
| 16 | mermaid_replace | 替换 mermaid 组件 | × |
| 17 | old_window_tab | 标签页管理(已废弃) | × |

1. 每个功能都对应源码的 plugin 文件夹下的一个同名文件(index.js 除外),**如若不需要某些功能,按需删除文件即可**
2. 每个功能都有对应的配置,且每个配置选项都有注释说明。可以按需修改对应 JS 文件里的 config。
Expand Down Expand Up @@ -241,6 +242,22 @@ const BUILTIN = [



### auto_number:自动编号

![auto_number](assets/auto_number.png)

支持编号(皆可单独打开/关闭):

- 章节
- 大纲
- TOC
- 表格
- 图片

> 注意:通过注入 CSS 实现功能,有可能会与你使用的 theme 冲突。


### right_click_menu:右键菜单统一管理插件

![right_click_menu](assets/right_click_menu.png)
Expand Down
Binary file added assets/auto_number.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
175 changes: 175 additions & 0 deletions plugin/auto_number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
(() => {
const config = {
// 侧边栏自动编号
ENABLE_SIDE_BAR: true,
// 正文自动编号
ENABLE_CONTENT: true,
// TOC自动编号
ENABLE_TOC: true,
// 表格自动编号
ENABLE_TABLE: true,
// 图片自动编号
ENABLE_IMAGE: true,
}

const content_css = `
#write { counter-reset: write-h2 Figures Tables; }
h1 { counter-reset: write-h2 Figures Tables; }
h2 { counter-reset: write-h3; }
h3 { counter-reset: write-h4; }
h4 { counter-reset: write-h5; }
h5 { counter-reset: write-h6; }
#write h2:before {
counter-increment: write-h2;
content: counter(write-h2) ". ";
}
#write h3:before,
h3.md-focus.md-heading:before {
counter-increment: write-h3;
content: counter(write-h2) "." counter(write-h3) " ";
}
#write h4:before,
h4.md-focus.md-heading:before {
counter-increment: write-h4;
content: counter(write-h2) "." counter(write-h3) "." counter(write-h4) " ";
}
#write h5:before,
h5.md-focus.md-heading:before {
counter-increment: write-h5;
content: counter(write-h2) "." counter(write-h3) "." counter(write-h4) "." counter(write-h5) " "
}
#write h6:before,
h6.md-focus.md-heading:before {
counter-increment: write-h6;
content: counter(write-h2) "." counter(write-h3) "." counter(write-h4) "." counter(write-h5) "." counter(write-h6) " "
}
#write > h3.md-focus:before,
#write > h4.md-focus:before,
#write > h5.md-focus:before,
#write > h6.md-focus:before,
h3.md-focus:before,
h4.md-focus:before,
h5.md-focus:before,
h6.md-focus:before {
color: inherit;
border: inherit;
border-radius: inherit;
position: inherit;
left: initial;
float: none;
top: initial;
font-size: inherit;
padding-left: inherit;
padding-right: inherit;
vertical-align: inherit;
font-weight: inherit;
line-height: inherit;
}`

const side_bar_css = `
.outline-content { counter-reset: outline-h2; }
.outline-h1 { counter-reset: outline-h2; }
.outline-h2 { counter-reset: outline-h3; }
.outline-h3 { counter-reset: outline-h4; }
.outline-h4 { counter-reset: outline-h5; }
.outline-h5 { counter-reset: outline-h6; }
.outline-content .outline-h2 .outline-label:before {
counter-increment: outline-h2;
content: counter(outline-h2) ". ";
}
.outline-content .outline-h3 .outline-label:before {
counter-increment: outline-h3;
content: counter(outline-h2) "." counter(outline-h3) " ";
}
.outline-content .outline-h4 .outline-label:before {
counter-increment: outline-h4;
content: counter(outline-h2) "." counter(outline-h3) "." counter(outline-h4) " ";
}
.outline-content .outline-h5 .outline-label:before {
counter-increment: outline-h5;
content: counter(outline-h2) "." counter(outline-h3) "." counter(outline-h4) "." counter(outline-h5) " ";
}
.outline-content .outline-h6 .outline-label:before {
counter-increment: outline-h6;
content: counter(outline-h2) "." counter(outline-h3) "." counter(outline-h4) "." counter(outline-h5) "." counter(outline-h6) " ";
}`

const toc_css = `
.md-toc-content { counter-reset: toc-h2; }
.md-toc-h1 { counter-reset: toc-h2; }
.md-toc-h2 { counter-reset: toc-h3; }
.md-toc-h3 { counter-reset: toc-h4; }
.md-toc-h4 { counter-reset: toc-h5; }
.md-toc-h5 { counter-reset: toc-h6; }
.md-toc-content .md-toc-h2 a:before {
counter-increment: toc-h2;
content: counter(toc-h2) ". ";
}
.md-toc-content .md-toc-h3 a:before {
counter-increment: toc-h3;
content: counter(toc-h2) "." counter(toc-h3) " ";
}
.md-toc-content .md-toc-h4 a:before {
counter-increment: toc-h4;
content: counter(toc-h2) "." counter(toc-h3) "." counter(toc-h4) " ";
}
.md-toc-content .md-toc-h5 a:before {
counter-increment: toc-h5;
content: counter(toc-h2) "." counter(toc-h3) "." counter(toc-h4) "." counter(toc-h5) " ";
}
.md-toc-content .md-toc-h6 a:before {
counter-increment: toc-h6;
content: counter(toc-h2) "." counter(toc-h3) "." counter(toc-h4) "." counter(toc-h5) "." counter(toc-h6) " ";
}`

const image_css = `
#write p span.md-image.md-img-loaded::after {
counter-increment: Figures;
content: "Figure " counter(write-h2) "-" counter(Figures);
font-family: monospace;
display: block;
text-align: center;
margin: 4px 0;
}`

const table_css = `
#write figure.table-figure::after {
counter-increment: Tables;
content: "Table " counter(write-h2) "-" counter(Tables);
font-family: monospace;
display: block;
text-align: center;
margin: 4px 0;
}`

const css = [
(config.ENABLE_CONTENT) ? content_css : "",
(config.ENABLE_SIDE_BAR) ? side_bar_css : "",
(config.ENABLE_TOC) ? toc_css : "",
(config.ENABLE_IMAGE) ? image_css : "",
(config.ENABLE_TABLE) ? table_css : "",
].join("\n")

const style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
document.getElementsByTagName("head")[0].appendChild(style);

console.log("auto_number.js had been injected");
})()
8 changes: 8 additions & 0 deletions plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ window.onload = () => {
call: null,
call_args: null,
},
{
name: "自动编号",
src: "./plugin/auto_number.js",
enable: true,
clickable: false,
call: null,
call_args: null,
},
{
name: "右键菜单",
src: "./plugin/right_click_menu.js",
Expand Down

0 comments on commit 9594fdc

Please sign in to comment.