news 2026/2/26 2:49:32

脚本工具 批量md转html

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
脚本工具 批量md转html

md转html,便于打包进APP

就算以后安卓不兼容,APP不能用,自己做个离线网页也能用一辈子

#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Termux 批量 md → 手机竖屏 html """ import os import pathlib import markdown from datetime import datetime # 1. 待遍历的 md 目录 SRC_DIR = "/storage/emulated/0/Android/LLS_2025/Xmind/测试/Linux内核文章" # 2. 输出 html 的根目录 DST_DIR = "/storage/emulated/0/Android/LLS_2025/Xmind/测试/linux内核文章转换" # 3. 极简手机竖屏 CSS CSS = """<style> body{margin:0;padding:1em;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif;line-height:1.6;font-size:15px;color:#222;background:#fff} h1,h2,h3,h4,h5,h6{margin-top:1.2em;margin-bottom:.6em;font-weight:600} pre{background:#f6f8fa;padding:.8em;border-radius:4px;overflow-x:auto} code{background:#f6f8fa;padding:.2em .4em;border-radius:3px;font-size:90%} blockquote{margin:0;padding-left:1em;border-left:4px solid #dfe2e5;color:#6a737d} img{max-width:100%;height:auto} table{border-collapse:collapse;width:100%} th,td{border:1px solid #ddd;padding:.4em} th{background:#f6f8fa} </style>""" def ensure_dir(p: pathlib.Path): p.mkdir(parents=True, exist_ok=True) def md_to_html(md_text: str) -> str: """md -> 完整 html 字符串""" md = markdown.Markdown(extensions=["extra", "codehilite", "toc"]) content = md.convert(md_text) title = md.Meta.get("title", [""])[0] if hasattr(md, "Meta") else "" if not title: # 取第一行#标题或文件名 title = content.splitlines()[0].replace("<h1>", "").replace("</h1>", "").strip() html = f"""<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>{title}</title> {CSS} </head> <body> {content} <hr> <small>Generated by 凉安 @ {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}</small> </body> </html>""" return html def main(): src_path = pathlib.Path(SRC_DIR).expanduser() dst_path = pathlib.Path(DST_DIR).expanduser() ensure_dir(dst_path) if not src_path.is_dir(): print("❌ 源目录不存在:", src_path) return md_files = list(src_path.rglob("*.md")) if not md_files: print("⚠️ 未找到任何 .md 文件") return for md_file in md_files: rel = md_file.relative_to(src_path).with_suffix(".html") out_file = dst_path / rel ensure_dir(out_file.parent) html = md_to_html(md_file.read_text(encoding="utf-8")) out_file.write_text(html, encoding="utf-8") print("✅", out_file) print(f"🎉 全部完成,共转换 {len(md_files)} 个文件 → {dst_path}") if __name__ == "__main__": main()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/2/24 18:42:51

21、进程监控与转储工具深度解析

进程监控与转储工具深度解析 在计算机系统的调试和性能优化过程中,进程监控和转储工具起着至关重要的作用。它们能够帮助开发者和系统管理员深入了解系统的运行状态,及时发现并解决潜在的问题。下面将详细介绍一些常用工具及其使用方法。 进程监控工具的使用 在进程监控工…

作者头像 李华
网站建设 2026/2/25 3:06:09

31、DebugView使用指南:全面解析与操作教程

DebugView使用指南:全面解析与操作教程 1. 全局Win32调试输出捕获 在Windows系统中,借助快速用户切换或远程桌面功能,Windows XP和Windows Server 2003的用户常常会登录到非全局会话。而从Windows Vista开始,会话0隔离机制保证了用户不会登录到服务运行的会话中。当Debug…

作者头像 李华
网站建设 2026/2/22 21:01:54

32、进程与诊断实用工具:DebugView 与 LiveKd 全解析

进程与诊断实用工具:DebugView 与 LiveKd 全解析 一、DebugView 代理使用说明 DebugView 是一款强大的工具,其代理的使用有多种方式可灵活配置。 1. 界面显示控制 任务栏图标显示 :在命令行添加 /t 可隐藏代理状态对话框,转而在任务栏通知区域显示图标。当代理未连接…

作者头像 李华
网站建设 2026/2/25 21:11:27

35、安全实用工具介绍

安全实用工具介绍 在当今数字化的时代,保障系统和数据的安全至关重要。本文将详细介绍两款实用的安全工具:SigCheck 和 AccessChk,帮助你更好地管理系统安全。 SigCheck 工具 SigCheck 是一款功能强大的工具,它不仅可以检查文件的数字签名和 VirusTotal 状态,还能列出安…

作者头像 李华
网站建设 2026/2/24 18:51:22

使用这个插件,fiddler抓包直接生成httprunner脚本

har2case可以将.har文件转化成yaml格式或者json格式的httprunner的脚本文件&#xff0c;生成.har格式文件可以借助 fiddler 或 Charles 抓包工具 友情提示&#xff1a; 录制脚本&#xff0c;只是一个过渡&#xff0c;从0到1的一个过渡&#xff0c;如果让你直接写脚本&#xf…

作者头像 李华
网站建设 2026/2/25 4:21:05

如何用Prometheus监控Anything-LLM服务状态?

如何用Prometheus监控Anything-LLM服务状态&#xff1f; 在企业纷纷将大语言模型&#xff08;LLM&#xff09;引入知识管理、客户服务和内部协作的今天&#xff0c;一个看似简单的问题却逐渐浮现&#xff1a;我们如何确保这些“聪明”的AI系统不仅功能正常&#xff0c;还能稳定…

作者头像 李华