Skip to content

Commit

Permalink
Perf: add sourceStyle 3
Browse files Browse the repository at this point in the history
  • Loading branch information
VimWei committed Nov 25, 2021
1 parent d05c219 commit 4186125
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 25 deletions.
21 changes: 12 additions & 9 deletions MdxSourceBuilder.vim
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ let g:pageNumDigit = 4
" \[dictionaryPart, picNamePrefix, picFormat,
" \sourceStyle, navStyle, locationPercent, nearestKeyword],
let g:dictionaryParts = [
\["火星词典.Cover.txt", "MarsDictCover_", ".png", 0, 1, 0, 1],
\["火星词典.Prefix.txt", "MarsDictPrefix_", ".png", 0, 1, 0, 1],
\["火星词典.Cover.txt", "MarsDictCover_", ".png", 0, 2, 0, 1],
\["火星词典.Prefix.txt", "MarsDictPrefix_", ".png", 0, 2, 0, 1],
\["火星词典.Body.Part1.txt", "MarsDict_", ".png", 0, 2, 1, 1],
\["火星词典.Body.Part2.txt", "MarsDict_", ".png", 1, 2, 1, 1],
\["火星词典.Body.Part3.txt", "MarsDict_", ".png", 3, 2, 1, 1],
\["火星词典.Appendix.txt", "MarsDictAppendix_", ".png", 0, 1, 0, 1],
\["火星词典.Pinyin.txt", "MarsDict_", ".png", 2, 0, 0, 0],
\]
Expand All @@ -47,6 +48,7 @@ let g:dictionaryParts = [
" - 0:'一行页码 + 多行关键词(每行一个关键词)'的标准词条格式,跳转至页码
" - 1:'一个页码 + 多个中文单字符的关键词'的压缩词条格式,跳转至页码
" - 2:'页码 + 分隔符 + 单个中或英关键词'的啰嗦行格式,跳转至页码
" - 3:'单个中或英关键词 + 分隔符 + 页码'的啰嗦行格式,跳转至页码
" navStyle:定义个性化的词条导航样式(MdxSourceBuilderCore.Vim)
" - 0:自身没有页面和keywords导航,仅转LINK,适用于拼音之类的辅助检索
" - 1:仅有页面导航,无keywords导航,简洁,适用于封面/附录之类的Affix
Expand All @@ -62,25 +64,26 @@ let g:dictionaryParts = [
let s:anyMore = 1
" 格式:\[anyMorePart, sourceStyle, pagePrefix],
let g:anyMoreSources = [
\["火星词典.Link1.txt", 4, ""],
\["火星词典.Link2.txt", 5, "OPEU3_"],
\["火星词典.Link1.txt", 104, ""],
\["火星词典.Link2.txt", 105, "MarsDict_"],
\["火星词典.Link3.txt", 998, ""],
\["火星词典.Link4.txt", 7, ""],
\["火星词典.Link5.txt", 6, "OPEU3Pre_"],
\["火星词典.Link4.txt", 107, ""],
\["火星词典.Link5.txt", 106, "MarsDictPrefix_"],
\["火星词典.Link6.txt", 998, ""],
\["火星词典.Link7.txt", 0, "OPEU3_"],
\["火星词典.Link7.txt", 0, "MarsDict_"],
\["火星词典.Link888.txt", 888, ""],
\]
" anyMorePart:源文件的名称,包括后缀名
" sourceStyle:定义兼容的源文件或词条格式(MdxSourceBuilderLink.Vim)
" - 0:固定项目,'一行页码 + 多行关键词(每行一个关键词)'的标准词条格式
" - 1:固定项目,'一个页码 + 多个中文单字符的关键词'的压缩词条格式
" - 2:固定项目,'页码 + 分隔符 + 单个中或英关键词'的啰嗦行格式
" - 3:固定项目,'单个中或英关键词 + 分隔符 + 页码'的啰嗦行格式
" - 888: 固定项目,用于快速手工添加链接词条,"现有关键词\t链接词条"
" - 998: 固定项目,源文件为标准的mdx源格式,但欠缺CSS文件等必要元素
" - 999:固定项目,源文件为标准的mdx源格式,无需进一步处理,直接使用
" - 其他: 定制化项目,自定义词条样式及处理程序
" pagePrefix:可选;但当sourceStyle为0/1/2时,必须配置
" - 其他: 定制化项目,自定义词条样式及处理程序,建议用101-199以示区别
" pagePrefix:按需可选;但当sourceStyle为0/1/2/3时,必须配置

" 自定义固定链接的导航:\[链接名称, 链接目标],
let g:customNavList = [
Expand Down
2 changes: 2 additions & 0 deletions MdxSourceBuilderCSS.vim
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@
color: red!important;
}

/* 更多自定义CSS */

/* vim: set et sw=4 ts=4 sts=4 fdm=marker ff=unix ft=css fenc=utf8 nobomb: */
28 changes: 26 additions & 2 deletions MdxSourceBuilderCore.vim
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,33 @@ function! StandardizeStyle(sourceStyle)
" 0002 abandonee
" 0002 a bas
" 0003 abdominous
" 将所有Tab替换为空格
silent! set expandtab tabstop=4 | %retab
normal gg
let linenumber = printf(s:pageNumDigit, 0)
for line in getline(1,'$')
let words = split(line, '\s\{4,}')
if linenumber == words[0]
silent! s/^.*$/\= words[1]/e
else
let linenumber = words[0]
silent! s/^.*$/\= words[0] . "\n". get(words, 1, "")/e
endif
silent! normal j
endfor
elseif s:sourceStyle == 3
" 适合如下词条格式:行格式为"单个中或英关键词 + 分隔符 + 页码"
" 分隔符兼容:Tab键'\t', 4个及以上空格'\s\{4,}'
" abandon 0001
" abandoned 0001
" abandonee 0002
" a bas 0002
" abdominous 0003
" 将所有Tab替换为空格
silent! set expandtab tabstop=4 | %retab
" 将格式转为sourceStyle 2
silent! %s/^\(.\{-}\)\s\{4,}\(\d\{3,}\)$/\2 \1/
normal gg
let linenumber = printf(s:pageNumDigit, 0)
for line in getline(1,'$')
let words = split(line, '\s\{4,}')
Expand All @@ -61,7 +85,7 @@ function! StandardizeStyle(sourceStyle)
silent! normal j
endfor
else
" echomsg "未定义处理方案"
echomsg "警告!未定义 SourceStyle " . a:sourceStyle . " 的标准化方案!"
endif
" 清理并保存,以便后续代码可以正常运作
silent! normal! Go
Expand Down Expand Up @@ -304,7 +328,7 @@ function! KeywordsNav(currentPage, currentWord)
endfunction

" 根据sourceStyle和NavStyle输出标准的mdx源文件格式 ---------------------------------{{{1
if s:sourceStyle == 0 || s:sourceStyle == 1 || s:sourceStyle == 2
if index([0,1,2,3], s:sourceStyle) >= 0
" 运行初始化函数
silent! call StandardizeStyle(s:sourceStyle)
silent! call PageList()
Expand Down
37 changes: 30 additions & 7 deletions MdxSourceBuilderLink.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,33 @@ function! StandardizeStyle(sourceStyle)
" 0002 abandonee
" 0002 a bas
" 0003 abdominous
" 将所有Tab替换为空格
silent! set expandtab tabstop=4 | %retab
normal gg
let linenumber = printf(s:pageNumDigit, 0)
for line in getline(1,'$')
let words = split(line, '\s\{4,}')
if linenumber == words[0]
silent! s/^.*$/\= words[1]/e
else
let linenumber = words[0]
silent! s/^.*$/\= words[0] . "\n". get(words, 1, "")/e
endif
silent! normal j
endfor
elseif s:sourceStyle == 3
" 适合如下词条格式:行格式为"单个中或英关键词 + 分隔符 + 页码"
" 分隔符兼容:Tab键'\t', 4个及以上空格'\s\{4,}'
" abandon 0001
" abandoned 0001
" abandonee 0002
" a bas 0002
" abdominous 0003
" 将所有Tab替换为空格
silent! set expandtab tabstop=4 | %retab
" 将格式转为sourceStyle 2
silent! %s/^\(.\{-}\)\s\{4,}\(\d\{3,}\)$/\2 \1/
normal gg
let linenumber = printf(s:pageNumDigit, 0)
for line in getline(1,'$')
let words = split(line, '\s\{4,}')
Expand All @@ -56,7 +80,7 @@ function! StandardizeStyle(sourceStyle)
silent! normal j
endfor
else
echomsg "警告!未定义 SourceStyle " . a:sourceStyle . " 的标准化方案!"
echomsg "警告!未定义 SourceStyle " . a:sourceStyle . " 的标准化方案!"
endif
" 清理并保存,以便后续代码可以正常运作
silent! normal! Go
Expand Down Expand Up @@ -108,7 +132,7 @@ function! KeywordsDicts()
endfunction

" 根据SourceStyle输出标准的mdx源文件格式 ----------------------------------{{{1
if s:sourceStyle == 0 || s:sourceStyle == 1 || s:sourceStyle == 2
if index([0,1,2,3], s:sourceStyle) >= 0
" 运行初始化函数
silent! call StandardizeStyle(s:sourceStyle)
silent! call PageList()
Expand All @@ -125,11 +149,10 @@ if s:sourceStyle == 0 || s:sourceStyle == 1 || s:sourceStyle == 2
silent! $put k
endfor
endfor
elseif s:sourceStyle == 3
elseif s:sourceStyle == 4
elseif s:sourceStyle == 104
" 将带有编号的主词条改造为使用"s+编号"进行检索
silent! %s/^\(\d*\)\(\s.*\)$/s\1\r@@@LINK=\0\r<\/>/
elseif s:sourceStyle == 5
elseif s:sourceStyle == 105
" 运行初始化函数
silent! call StandardizeStyle(s:sourceStyle)
silent! call PageList()
Expand All @@ -150,7 +173,7 @@ elseif s:sourceStyle == 5
silent! $put k
endfor
endfor
elseif s:sourceStyle == 6
elseif s:sourceStyle == 106
" 1. “中英文”定位到页面
let lineDicts = {}
let lineNumber = 0
Expand Down Expand Up @@ -179,7 +202,7 @@ elseif s:sourceStyle == 6
\. '</>'
silent! $put k
endfor
elseif s:sourceStyle == 7
elseif s:sourceStyle == 107
" 添加编号链接
silent! %s/\(\d\+\)/<a href="entry:\/\/s\1">\1<\/a>/g
" 给每个词条添加CSS
Expand Down
15 changes: 15 additions & 0 deletions exchange.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
silent! set expandtab tabstop=4 | %retab
" 将格式转为sourceStyle 2
silent! %s/^\(.\{-}\)\s\{4,}\(\d\{3,}\)$/\2 \1/
normal gg
let linenumber = printf('%04d', 0)
for line in getline(1,'$')
let words = split(line, '\s\{4,}')
if linenumber == words[0]
silent! s/^.*$/\= words[1]/e
else
let linenumber = words[0]
silent! s/^.*$/\= words[0] . "\n". get(words, 1, "")/e
endif
silent! normal j
endfor
23 changes: 23 additions & 0 deletions 火星词典.Body.Part3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
这是keyword 0301
key word 可以有空格 0302
分隔符最好用4位及以上的空格 0303
虽可以使用tab但与vim配置有关 0303
尽量不用tab 避免兼容性 0399
0399
0399
同一页码可以出现多次 0399
0304
0305
可以只有页码 0306
0311
0312
也可以跳页码 0318
跳过页码的将不会出现在导航条上 0330
可以用于跳过不想要的页面 0330
页码可以乱序 0302
但你很难找出哪些页面遗漏了 0355
相比之下不如SourceStyle2 0323
排列整齐 0358
排查容易 0365
但Style3肯定是支持的 0358
请放心使用 0366
12 changes: 6 additions & 6 deletions 火星词典.info.description.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1>火星词典</h1>
<br />
<p>这是看懂火星语必备的词典</p>
<p>blabla</p>
<br />
<p>Mdx created by VimVim 2020/08/12</p>
<h1>火星词典</h1>
<br />
<p>这是看懂火星语必备的词典</p>
<p>blabla</p>
<br />
<p>Mdx created by VimVim 2020/08/12</p>
2 changes: 1 addition & 1 deletion 火星词典.info.title.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
火星词典 37th
火星词典 37th

0 comments on commit 4186125

Please sign in to comment.