// http://stackoverflow.com/questions/14480345/how-to-get-the-nth-occurrence-in-a-string functiongetPosition(str, m, i) { return str.split(m, i).join(m).length; }
var version = String(hexo.version).split('.'); hexo.extend.filter.register('after_post_render', function(data){ var config = hexo.config; if(config.post_asset_folder){ var link = data.permalink; if(version.length > 0 && Number(version[0]) == 3) var beginPos = getPosition(link, '/', 1) + 1; else var beginPos = getPosition(link, '/', 3) + 1; // In hexo 3.1.1, the permalink of "about" page is like ".../about/index.html". var endPos = link.lastIndexOf('/') + 1; link = link.substring(beginPos, endPos);
var toprocess = ['excerpt', 'more', 'content']; for(var i = 0; i < toprocess.length; i++){ var key = toprocess[i]; var $ = cheerio.load(data[key], { ignoreWhitespace: false, xmlMode: false, lowerCaseTags: false, decodeEntities: false });
$('img').each(function(){ if ($(this).attr('src')){ // For windows style path, we replace '\' to '/'. var src = $(this).attr('src').replace('\\', '/'); if(!/http[s]*.*|\/\/.*/.test(src) && !/^\s*\//.test(src)) { // For "about" page, the first part of "src" can't be removed. // In addition, to support multi-level local directory. var linkArray = link.split('/').filter(function(elem){ return elem != ''; }); var srcArray = src.split('/').filter(function(elem){ return elem != '' && elem != '.'; }); if(srcArray.length > 1) srcArray.shift(); src = srcArray.join('/'); $(this).attr('src', config.root + link + src); console.info&&console.info("update link as:-->"+config.root + link + src); } }else{ console.info&&console.info("no src attr, skipped..."); console.info&&console.info($(this)); } }); data[key] = $.html(); } } });
defreplace_symbols_in_formula(file_path): withopen(file_path, 'r', encoding='utf-8') as f: content = f.read()
defreplacer(match): formula = match.group(0) formula = formula.replace(r'\R', r'\mathbb{R}') formula = formula.replace(r'\N', r'\mathbb{N}') return formula
if new_content != content: withopen(file_path, 'w', encoding='utf-8') as f: f.write(new_content) print(f'Updated: {file_path}')
defscan_and_replace(dir_path): for root, dirs, files in os.walk(dir_path): for file in files: if file.endswith('.md'): file_path = os.path.join(root, file) replace_symbols_in_formula(file_path)
if __name__ == '__main__': hexo_source_dir = './source/_posts'# 修改成你的文章目录 scan_and_replace(hexo_source_dir)
折叠块
使用折叠块需要用 pandoc 渲染器渲染
效果如下:
点此处展开
重点1 \[
\sum_{i=3}^4 a_i = b
\]
重点2 \(a + b = c^3\)
下面是一段代码
1
#include<cstdio>
重点4 > 定义4: > > abcd \(a+b\) a definition
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<details> <summary> 点此处展开 </summary>
- 重点1 $$ \sum_{i=3}^4 a_i = b $$ - 重点2 $a + b = c^3$ - 下面是一段代码 - 重点4 > 定义4: > > abcd $a+b$ a definition