Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
feat: implement CSS minification and build script for MinerU HTML rendering
myhloliad3dbb168884
diff --git a/docs/next/middle-json/rendering.md b/docs/next/middle-json/rendering.mdindex 4c19019d..4a6864a0 100644--- a/docs/next/middle-json/rendering.md+++ b/docs/next/middle-json/rendering.md@@ -107,7 +107,7 @@ HTML table 使用 occupancy grid 生成原生 Word table,支持 `rowspan/colsp`MarkdownRenderMode` 是 `RenderMode` 的既有公共别名。DOCX 是语义化可编辑输出,不承诺复刻源 PDF/Office 的字体、分栏、断行和页数;CLI、doclib 与 v1 API 不在本契约范围。-## MPE/Crossnote 风格 HTML+## MinerU 独立 HTML```pythonfrom mineru.render import RenderMode, render_html@@ -123,9 +123,10 @@ html_document = render_html(`render_html()` 只接受严格 `MiddleJson`,返回字符串且不写文件、不读取图片 sidecar、不访问网络。`standalone=True` 输出完整 HTML5 文档;`False` 输出单根-`article.crossnote.markdown-preview.mineru-document` fragment,不包含 CSS、脚本或+`article.mineru-document` fragment,不包含 CSS、脚本或`head`。显式标题缺失时,HTML title 使用首个非空 `doc_title` 的纯文本,再回退为-`MinerU Document`。+`MinerU Document`。完整文档使用 `body.mineru-html-body` 提供居中和响应式页面布局;+fragment 调用方可以自行决定外围容器尺寸。HTML 与 DOCX/Markdown 共用 `RenderMode` 和续段/续表 planner。DEFAULT 输出无页面 wrapper的连续阅读内容;FULL 为每个 `PageInfo` 输出一个 `section.mineru-page`,包括空页,并在@@ -133,22 +134,17 @@ HTML 与 DOCX/Markdown 共用 `RenderMode` 和续段/续表 planner。DEFAULT元数据。行内内容直接消费共享 AST:普通文本始终 HTML escape,未知标签保持可见;公式只在 `mineru-math` carrier 内使用 `\(...\)` 或 `\[...\]`,不扫描普通正文中的美元符号。-完整文档按原字节内联 Crossnote 0.9.31 的 `github-light.css`、`github.css` Prism theme 和-`style-template.css`,并在 style 开头保留完整 NCSA notice;许可证与来源说明也随资源打包。-MinerU 自有补充 CSS 只覆盖新增结构。+完整文档只内联压缩后的 `mineru.min.css`。其可读源码为 `mineru.css`,所有文档规则均+限定在 `.mineru-document` 内,standalone 外围布局规则限定在 `.mineru-html-body`,+不会修改 fragment 宿主页的全局标签样式。样式使用系统字体,不加载外部字体。有公式时按需加载固定 MathJax 4.1.2 `tex-chtml.js`,启用 `ui/safe`、禁用 `require`,并关闭菜单和 enrichment。有可高亮代码时按需加载固定 Prism 1.30.0 core 和 Autoloader,语言组件根固定到同版本 jsDelivr。入口脚本携带 SRI;动态 MathJax 扩展、字体和 Prism语言组件没有逐文件 SRI。renderer 不注入 CSP,HTTP 宿主需要自行允许相应 jsDelivrscript/font/style,并评估 CDN 供应链策略。-为保持与 MPE 导出 DOM/CSS 选择器完全兼容,standalone 保留其非标准-`body[for="html-export"]` 属性;字节不变的上游 `style-template.css` 也包含 Nu validator-会报告的既有 CSS `calc()` 表达式。这两项是已知兼容偏差,MinerU 自有 HTML 结构和补充-CSS 仍按 HTML5/CSS 语义生成。--fragment 调用方必须自行加载同版本 CSS、MathJax 和 Prism;三份 Crossnote CSS 未重新-scope,会影响宿主页全局样式。MathJax 必须在初始化前复用 standalone 的 delimiter、+fragment 调用方需要加载随包提供的 `mineru.min.css`,并按实际内容加载同版本 MathJax+和 Prism。MathJax 必须在初始化前复用 standalone 的 delimiter、`ignoreHtmlClass/processHtmlClass`、`ui/safe`、禁用 `require` 及 safeOptions 配置。动态插入后调用`MathJax.typesetPromise([root])` 与 `Prism.highlightAllUnder(root)`;替换已有公式前先调用`MathJax.typesetClear([root])`。fragment 内的相对图片以宿主页 URL 为基准,不能通过diff --git a/mineru/render/html.py b/mineru/render/html.pyindex 129d327d..fa552674 100644--- a/mineru/render/html.py+++ b/mineru/render/html.py@@ -1,5 +1,5 @@# Copyright (c) Opendatalab. All rights reserved.-"""严格 MiddleJson 到 MPE/Crossnote 风格 HTML 的公共渲染实现。"""+"""严格 MiddleJson 到 MinerU 风格 HTML 的公共渲染实现。"""from __future__ import annotations@@ -58,12 +58,7 @@ from mineru.types import (TitleBlockBase,)-_STYLE_RESOURCE_PATHS = (- ("crossnote", "github.css"),- ("crossnote", "github-light.css"),- ("crossnote", "style-template.css"),- ("mineru.css",),-)+_STYLE_RESOURCE_NAME = "mineru.min.css"_MATHJAX_URL = "https://cdn.jsdelivr.net/npm/[email protected]/tex-chtml.js"_MATHJAX_INTEGRITY = "sha384-zAhQQhdaMeHsMProNntGGg6nOUVcfuF9F22C3d1qJ9NZAVzCplXk1X85D2O5iufn"_PRISM_CORE_URL = "https://cdn.jsdelivr.net/npm/[email protected]/components/prism-core.min.js"@@ -120,10 +115,7 @@ class _HtmlRenderer:body = self._render_full_pages(planned_pages)else:body = self._render_default_pages(planned_pages)- article = (- f'<article class="crossnote markdown-preview mineru-document '- f'mineru-document--{self.mode.value}">\n{body}\n</article>'- )+ article = f'<article class="mineru-document mineru-document--{self.mode.value}">\n{body}\n</article>'if not self.standalone:return article# 最终依赖以真实 DOM 为准,避免回退分支或普通文本中的 class 字样误触发。@@ -595,10 +587,10 @@ class _HtmlRenderer:'<meta charset="utf-8">\n''<meta name="viewport" content="width=device-width, initial-scale=1.0">\n'f"<title>{title}</title>\n"- f"<style>\n{styles}\n</style>\n"+ f"<style>{styles}</style>\n"f"{dependency_html}\n""</head>\n"- '<body for="html-export">\n'+ '<body class="mineru-html-body">\n'f"{article}\n""</body>\n""</html>"@@ -770,12 +762,9 @@ def _replace_html_controls(content: str) -> str:@lru_cache(maxsize=1)def _load_html_styles() -> str:- """从包资源读取并缓存固定 Crossnote CSS 与 MinerU 补充样式。"""+ """从包资源读取并缓存压缩后的 MinerU 独立样式。"""root = resources.files("mineru").joinpath("resources", "html")- license_text = root.joinpath("crossnote", "LICENSE.md").read_text(encoding="utf-8")- notice = f"/*\nCrossnote 0.9.31 CSS license notice:\n{license_text}\n*/"- styles = [root.joinpath(*path).read_text(encoding="utf-8") for path in _STYLE_RESOURCE_PATHS]- return "\n".join([notice, *styles])+ return root.joinpath(_STYLE_RESOURCE_NAME).read_text(encoding="utf-8")def _mathjax_head() -> str:diff --git a/mineru/resources/html/crossnote/LICENSE.md b/mineru/resources/html/crossnote/LICENSE.mddeleted file mode 100644index 807b6547..00000000--- a/mineru/resources/html/crossnote/LICENSE.md+++ /dev/null@@ -1,17 +0,0 @@-University of Illinois/NCSA-Open Source License--```-Copyright (c) 2017 ~ 2023 Yiyi Wang-All rights reserved.--Developed by: Yiyi Wang- https://github.com/shd101wyy/crossnote-```--Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:--Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.-Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution.-Neither the names of Yiyi Wang, nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission.-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.diff --git a/mineru/resources/html/crossnote/SOURCE.md b/mineru/resources/html/crossnote/SOURCE.mddeleted file mode 100644index 826d0f2c..00000000--- a/mineru/resources/html/crossnote/SOURCE.md+++ /dev/null@@ -1,28 +0,0 @@-# Crossnote HTML styles--These files are unmodified compiled CSS resources bundled with Markdown Preview-Enhanced (MPE) 0.8.30, which declares Crossnote 0.9.31 as an exact dependency.-They are redistributed under the University of Illinois/NCSA Open Source-License in [LICENSE.md](./LICENSE.md).--The byte-for-byte source was the installed MPE 0.8.30 extension. Paths below-are relative to the extension installation root:--| Vendored file | MPE/Crossnote distribution path | SHA-256 |-| --- | --- | --- |-| `github-light.css` | `crossnote/styles/preview_theme/github-light.css` | `020bb992e41828c9ef14f687f2a71e99e2bf6f69e32de9d1ee1e292604f0d779` |-| `style-template.css` | `crossnote/styles/style-template.css` | `054061cb501481af702df4adf8d2c224d666b6fe78a84a1c3a362e6a92cfdcdf` |-| `github.css` | `crossnote/styles/prism_theme/github.css` | `885fa37a859ef386c471e7dee272e882d09c1c600b853b6f518daf40bbd1ba02` |--The upstream CSS artifacts are minified single-line files without a trailing-newline. Keep them byte-identical so the checksums remain useful.--Upstream references:--- Crossnote release: <https://github.com/shd101wyy/crossnote/releases/tag/0.9.31>-- MPE release: <https://github.com/shd101wyy/vscode-markdown-preview-enhanced/releases/tag/0.8.30>-- MPE Marketplace package: <https://marketplace.visualstudio.com/items?itemName=shd101wyy.markdown-preview-enhanced>-- `github-light` source: <https://github.com/shd101wyy/crossnote/blob/0.9.31/styles/preview_theme/github-light.less>-- `style-template` source: <https://github.com/shd101wyy/crossnote/blob/0.9.31/styles/style-template.less>-- Prism GitHub theme source: <https://github.com/shd101wyy/crossnote/blob/0.9.31/styles/prism_theme/github.css>-- Crossnote license: <https://github.com/shd101wyy/crossnote/blob/0.9.31/LICENSE.md>diff --git a/mineru/resources/html/crossnote/github-light.css b/mineru/resources/html/crossnote/github-light.cssdeleted file mode 100644index b6829470..00000000--- a/mineru/resources/html/crossnote/github-light.css+++ /dev/null@@ -1 +0,0 @@-html body{font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:16px;line-height:1.6;color:#333;background-color:#fff;overflow:initial;box-sizing:border-box;word-wrap:break-word}html body>:first-child{margin-top:0}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{line-height:1.2;margin-top:1em;margin-bottom:16px;color:#000}html body h1{font-size:2.25em;font-weight:300;padding-bottom:.3em}html body h2{font-size:1.75em;font-weight:400;padding-bottom:.3em}html body h3{font-size:1.5em;font-weight:500}html body h4{font-size:1.25em;font-weight:600}html body h5{font-size:1.1em;font-weight:600}html body h6{font-size:1em;font-weight:600}html body h1,html body h2,html body h3,html body h4,html body h5{font-weight:600}html body h5{font-size:1em}html body h6{color:#5c5c5c}html body strong{color:#000}html body del{color:#5c5c5c}html body a:not([href]){color:inherit;text-decoration:none}html body a{color:#08c;text-decoration:none}html body a:hover{color:#00a3f5;text-decoration:none}html body img{max-width:100%}html body>p{margin-top:0;margin-bottom:16px;word-wrap:break-word}html body>ol,html body>ul{margin-bottom:16px}html body ol,html body ul{padding-left:2em}html body ol.no-list,html body ul.no-list{padding:0;list-style-type:none}html body ol ol,html body ol ul,html body ul ol,html body ul ul{margin-top:0;margin-bottom:0}html body li{margin-bottom:0}html body li.task-list-item{list-style:none}html body li>p{margin-top:0;margin-bottom:0}html body .task-list-item-checkbox{margin:0 .2em .25em -1.8em;vertical-align:middle}html body .task-list-item-checkbox:hover{cursor:pointer}html body blockquote{margin:16px 0;font-size:inherit;padding:0 15px;color:#5c5c5c;background-color:#f0f0f0;border-left:4px solid #d6d6d6}html body blockquote>:first-child{margin-top:0}html body blockquote>:last-child{margin-bottom:0}html body hr{height:4px;margin:32px 0;background-color:#d6d6d6;border:0 none}html body table{margin:10px 0 15px 0;border-collapse:collapse;border-spacing:0;display:block;width:100%;overflow:auto;word-break:normal;word-break:keep-all}html body table th{font-weight:700;color:#000}html body table td,html body table th{border:1px solid #d6d6d6;padding:6px 13px}html body dl{padding:0}html body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:700}html body dl dd{padding:0 16px;margin-bottom:16px}html body code{font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:.85em;color:#000;background-color:#f0f0f0;border-radius:3px;padding:.2em 0}html body code::after,html body code::before{letter-spacing:-.2em;content:'\00a0'}html body pre>code{padding:0;margin:0;word-break:normal;white-space:pre;background:0 0;border:0}html body .highlight{margin-bottom:16px}html body .highlight pre,html body pre{padding:1em;overflow:auto;line-height:1.45;border:#d6d6d6;border-radius:3px}html body .highlight pre{margin-bottom:0;word-break:normal}html body pre code,html body pre tt{display:inline;max-width:initial;padding:0;margin:0;overflow:initial;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}html body pre code:after,html body pre code:before,html body pre tt:after,html body pre tt:before{content:normal}html body blockquote,html body dl,html body ol,html body p,html body pre,html body ul{margin-top:0;margin-bottom:16px}html body kbd{color:#000;border:1px solid #d6d6d6;border-bottom:2px solid #c7c7c7;padding:2px 4px;background-color:#f0f0f0;border-radius:3px}@media print{html body{background-color:#fff}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{color:#000;page-break-after:avoid}html body blockquote{color:#5c5c5c}html body pre{page-break-inside:avoid}html body table{display:table}html body img{display:block;max-width:100%;max-height:100%}html body code,html body pre{word-wrap:break-word;white-space:pre}}\ No newline at end of filediff --git a/mineru/resources/html/crossnote/github.css b/mineru/resources/html/crossnote/github.cssdeleted file mode 100644index c16c50d5..00000000--- a/mineru/resources/html/crossnote/github.css+++ /dev/null@@ -1 +0,0 @@-code[class*=language-],pre[class*=language-]{color:#333;background:0 0;font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.4;-moz-tab-size:8;-o-tab-size:8;tab-size:8;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:.8em;overflow:auto;border-radius:3px;background:#f5f5f5}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal;background:#f5f5f5}.token.blockquote,.token.comment{color:#969896}.token.cdata{color:#183691}.token.doctype,.token.macro.property,.token.punctuation,.token.variable{color:#333}.token.builtin,.token.important,.token.keyword,.token.operator,.token.rule{color:#a71d5d}.token.attr-value,.token.regex,.token.string,.token.url{color:#183691}.token.atrule,.token.boolean,.token.code,.token.command,.token.constant,.token.entity,.token.number,.token.property,.token.symbol{color:#0086b3}.token.prolog,.token.selector,.token.tag{color:#63a35c}.token.attr-name,.token.class,.token.class-name,.token.function,.token.id,.token.namespace,.token.pseudo-class,.token.pseudo-element,.token.url-reference .token.variable{color:#795da3}.token.entity{cursor:help}.token.title,.token.title .token.punctuation{font-weight:700;color:#1d3e81}.token.list{color:#ed6a43}.token.inserted{background-color:#eaffea;color:#55a532}.token.deleted{background-color:#ffecec;color:#bd2c00}.token.bold{font-weight:700}.token.italic{font-style:italic}.language-json .token.property{color:#183691}.language-markup .token.tag .token.punctuation{color:#333}.language-css .token.function,code.language-css{color:#0086b3}.language-yaml .token.atrule{color:#63a35c}code.language-yaml{color:#183691}.language-ruby .token.function{color:#333}.language-markdown .token.url{color:#795da3}.language-makefile .token.symbol{color:#795da3}.language-makefile .token.variable{color:#183691}.language-makefile .token.builtin{color:#0086b3}.language-bash .token.keyword{color:#0086b3}pre[data-line]{position:relative;padding:1em 0 1em 3em}pre[data-line] .line-highlight-wrapper{position:absolute;top:0;left:0;background-color:transparent;display:block;width:100%}pre[data-line] .line-highlight{position:absolute;left:0;right:0;padding:inherit 0;margin-top:1em;background:hsla(24,20%,50%,.08);background:linear-gradient(to right,hsla(24,20%,50%,.1) 70%,hsla(24,20%,50%,0));pointer-events:none;line-height:inherit;white-space:pre}pre[data-line] .line-highlight:before,pre[data-line] .line-highlight[data-end]:after{content:attr(data-start);position:absolute;top:.4em;left:.6em;min-width:1em;padding:0 .5em;background-color:hsla(24,20%,50%,.4);color:#f4f1ef;font:bold 65%/1.5 sans-serif;text-align:center;vertical-align:.3em;border-radius:999px;text-shadow:none;box-shadow:0 1px #fff}pre[data-line] .line-highlight[data-end]:after{content:attr(data-end);top:auto;bottom:.4em}\ No newline at end of filediff --git a/mineru/resources/html/crossnote/style-template.css b/mineru/resources/html/crossnote/style-template.cssdeleted file mode 100644index 6087c80a..00000000--- a/mineru/resources/html/crossnote/style-template.css+++ /dev/null@@ -1 +0,0 @@-.markdown-preview{width:100%;height:100%;box-sizing:border-box}.markdown-preview ul{list-style:disc}.markdown-preview ul ul{list-style:circle}.markdown-preview ul ul ul{list-style:square}.markdown-preview ol{list-style:decimal}.markdown-preview ol ol,.markdown-preview ul ol{list-style-type:lower-roman}.markdown-preview ol ol ol,.markdown-preview ol ul ol,.markdown-preview ul ol ol,.markdown-preview ul ul ol{list-style-type:lower-alpha}.markdown-preview .newpage,.markdown-preview .pagebreak{page-break-before:always}.markdown-preview pre.line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}.markdown-preview pre.line-numbers>code{position:relative}.markdown-preview pre.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:1em;font-size:100%;left:0;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.markdown-preview pre.line-numbers .line-numbers-rows>span{pointer-events:none;display:block;counter-increment:linenumber}.markdown-preview pre.line-numbers .line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}.markdown-preview .mathjax-exps .MathJax_Display{text-align:center!important}.markdown-preview:not([data-for=preview]) .code-chunk .code-chunk-btn-group{display:none}.markdown-preview:not([data-for=preview]) .code-chunk .status{display:none}.markdown-preview:not([data-for=preview]) .code-chunk .output-div{margin-bottom:16px}.markdown-preview .md-toc{padding:0}.markdown-preview .md-toc .md-toc-details{margin:0;padding:0;border:none}.markdown-preview .md-toc summary.md-toc-link-wrapper{cursor:pointer;list-style-position:outside}.markdown-preview .md-toc summary.md-toc-link-wrapper::marker{font-size:.85em}.markdown-preview .md-toc .md-toc-link-wrapper .md-toc-link{display:inline;padding:.25rem 0}.markdown-preview .md-toc .md-toc-link-wrapper .md-toc-link div,.markdown-preview .md-toc .md-toc-link-wrapper .md-toc-link p{display:inline}.markdown-preview .md-toc .md-toc-link-wrapper.highlighted .md-toc-link{font-weight:800}.markdown-preview .md-toc .md-toc-link-wrapper[data-level='0']{margin-left:12px}.markdown-preview .md-toc .md-toc-link-wrapper[data-level='1']{margin-left:28px}.markdown-preview .md-toc .md-toc-link-wrapper[data-level='2']{margin-left:44px}.markdown-preview .md-toc .md-toc-link-wrapper[data-level='3']{margin-left:60px}.markdown-preview .md-toc .md-toc-link-wrapper[data-level='4']{margin-left:76px}.markdown-preview .md-toc .md-toc-link-wrapper[data-level='5']{margin-left:80px}.markdown-preview a.tag,.markdown-preview a.tag:active,.markdown-preview a.tag:link,.markdown-preview a.tag:visited,.markdown-preview span.tag:not(.token){display:inline-block;background-color:var(--vscode-badge-background,rgba(127,127,127,.18));color:var(--vscode-badge-foreground,currentColor);border-radius:2em;font-size:.85em;font-weight:500;padding:.05em .55em;line-height:1.5;white-space:nowrap;text-decoration:none;text-shadow:none;box-shadow:none;transition:background-color .12s ease,opacity .12s ease}.markdown-preview a.tag{cursor:pointer}.markdown-preview a.tag:focus,.markdown-preview a.tag:hover{background-color:var(--vscode-badge-background,rgba(127,127,127,.32));color:var(--vscode-badge-foreground,currentColor);opacity:.85;text-decoration:none;outline:0}.markdown-preview .wikilink-embed-content{border-left:3px solid var(--vscode-textBlockQuote-border,rgba(128,128,128,.3));background:var(--vscode-textBlockQuote-background,rgba(128,128,128,.05));margin:.5em 0;padding:.5em .75em;border-radius:0 3px 3px 0}.markdown-preview .wikilink-embed-content.wikilink-embed-error{border-left-color:var(--vscode-errorForeground,#cf222e);color:var(--vscode-errorForeground,#cf222e);font-style:italic;opacity:.8}.markdown-preview .wikilink-embed-content h1:first-child,.markdown-preview .wikilink-embed-content h2:first-child,.markdown-preview .wikilink-embed-content h3:first-child,.markdown-preview .wikilink-embed-content h4:first-child,.markdown-preview .wikilink-embed-content h5:first-child,.markdown-preview .wikilink-embed-content h6:first-child{margin-top:.25em}.markdown-preview .wikilink-embed-content .wikilink-embed-content{margin:.25em 0;padding:.25em .5em}.markdown-preview .block-id{display:none}.scrollbar-style::-webkit-scrollbar{width:8px}.scrollbar-style::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}.scrollbar-style::-webkit-scrollbar-thumb{border-radius:5px;background-color:var(--vscode-scrollbarSlider-background,rgba(150,150,150,.66));border:4px solid var(--vscode-scrollbarSlider-background,rgba(150,150,150,.66));background-clip:content-box}.scrollbar-style::-webkit-scrollbar-thumb:hover{background-color:var(--vscode-scrollbarSlider-hoverBackground,rgba(120,120,120,.66))}html body[for=html-export]:not([data-presentation-mode]){position:relative;width:100%;height:100%;top:0;left:0;margin:0;padding:0;overflow:auto}html body[for=html-export]:not([data-presentation-mode]) .markdown-preview{position:relative;top:0;min-height:100vh}@media screen and (min-width:914px){html body[for=html-export]:not([data-presentation-mode]) .markdown-preview{padding:2em calc(50% - 457px + 2em)}}@media screen and (max-width:914px){html body[for=html-export]:not([data-presentation-mode]) .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for=html-export]:not([data-presentation-mode]) .markdown-preview{font-size:14px!important;padding:1em}}@media print{html body[for=html-export]:not([data-presentation-mode]) #sidebar-toc-btn{display:none}}html body[for=html-export]:not([data-presentation-mode]) #sidebar-toc-btn{position:fixed;bottom:8px;left:8px;font-size:28px;cursor:pointer;color:inherit;z-index:99;width:32px;text-align:center;opacity:.4}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] #sidebar-toc-btn{opacity:1}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc{position:fixed;top:0;left:0;width:300px;height:100%;padding:32px 0 48px 0;font-size:14px;box-shadow:0 0 4px rgba(150,150,150,.33);box-sizing:border-box;overflow:auto;background-color:inherit}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar{width:8px}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-thumb{border-radius:5px;background-color:var(--vscode-scrollbarSlider-background,rgba(150,150,150,.66));border:4px solid var(--vscode-scrollbarSlider-background,rgba(150,150,150,.66));background-clip:content-box}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-thumb:hover{background-color:var(--vscode-scrollbarSlider-hoverBackground,rgba(120,120,120,.66))}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc a{text-decoration:none}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc{padding:0 16px}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-details{margin:0;padding:0;border:none}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper .md-toc-link{display:inline;padding:.25rem 0}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper .md-toc-link div,html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper .md-toc-link p{display:inline}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper.highlighted .md-toc-link{font-weight:800}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper[data-level='0']{padding-left:0}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper[data-level='1']{padding-left:16px}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper[data-level='2']{padding-left:32px}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper[data-level='3']{padding-left:48px}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper[data-level='4']{padding-left:64px}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper[data-level='5']{padding-left:80px}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{left:300px;width:calc(100% - 300px);padding:2em calc(50% - 457px - 300px / 2);margin:0;box-sizing:border-box}@media screen and (max-width:1274px){html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{width:100%}}html body[for=html-export]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .markdown-preview{left:50%;transform:translateX(-50%)}html body[for=html-export]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .md-sidebar-toc{display:none}\ No newline at end of filediff --git a/mineru/resources/html/mineru.css b/mineru/resources/html/mineru.cssindex 248ea7ab..37f5e8b2 100644--- a/mineru/resources/html/mineru.css+++ b/mineru/resources/html/mineru.css@@ -1,6 +1,32 @@-/* MinerU HTML 渲染器补充样式;除打印页边距外均限定在文档根节点内。 */+/* MinerU 独立 HTML 主题。所有文档规则均限定在 MinerU 根节点内。 */+.mineru-html-body {+ background: #ffffff;+ margin: 0;+}++.mineru-html-body > .mineru-document {+ margin: 0 auto;+ max-width: 60rem;+ min-height: 100vh;+ padding: 2rem;+}+.mineru-document {+ --mineru-accent: #f97316;+ --mineru-accent-hover: #c2410c;+ --mineru-background: #ffffff;+ --mineru-border: #d1d5db;+ --mineru-muted: #6b7280;+ --mineru-surface: #f8fafc;+ --mineru-text: #1f2937;+ background: var(--mineru-background);box-sizing: border-box;+ color: var(--mineru-text);+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;+ font-size: 16px;+ line-height: 1.65;+ overflow-wrap: break-word;+ width: 100%;}.mineru-document *,@@ -9,68 +35,128 @@box-sizing: inherit;}-/* FULL 模式保留页面边界,空页也应维持可见的页面容器。 */-.mineru-document .mineru-page {- min-width: 0;- position: relative;+/* 标题与正文使用紧凑但稳定的阅读节奏。 */+.mineru-document :is(h1, h2, h3, h4, h5, h6) {+ color: var(--mineru-text);+ font-weight: 600;+ line-height: 1.3;+ margin: 1.5em 0 0.65em;}-.mineru-document--full .mineru-page {- min-height: 1.5rem;+.mineru-document h1 {+ font-size: 2rem;}-.mineru-document .mineru-page-break {- background: transparent;- border: 0;- border-top: 1px dashed #d0d7de;- height: 0;- margin: 2rem 0;+.mineru-document h2 {+ font-size: 1.5rem;}-/* 图片、表格、图表及其说明沿用同一视觉容器。 */-.mineru-document .mineru-figure,-.mineru-document figure[data-block-type] {- margin: 1.5rem 0;- max-width: 100%;+.mineru-document h3 {+ font-size: 1.25rem;}-.mineru-document .mineru-figure > img,-.mineru-document figure[data-block-type] > img {- display: block;- height: auto;- margin-inline: auto;- max-width: 100%;+.mineru-document h4 {+ font-size: 1.125rem;}-.mineru-document .mineru-caption,-.mineru-document figcaption {- color: #57606a;- font-size: 0.9em;- margin-top: 0.5rem;- text-align: center;+.mineru-document h5 {+ font-size: 1rem;}-.mineru-document .mineru-footnote {- color: #57606a;- font-size: 0.875em;- margin-top: 0.4rem;+.mineru-document h6 {+ color: var(--mineru-muted);+ font-size: 0.875rem;+}++.mineru-document .mineru-block:first-child > :first-child,+.mineru-document .mineru-page > .mineru-block:first-child > :first-child {+ margin-top: 0;+}++.mineru-document p {+ margin: 0 0 1rem;}-.mineru-document .mineru-details,-.mineru-document details[data-block-type] {- border: 1px solid #d0d7de;- border-radius: 6px;+.mineru-document :is(strong, b) {+ font-weight: 700;+}++.mineru-document :is(s, del) {+ color: var(--mineru-muted);+}++.mineru-document a {+ color: var(--mineru-accent);+ text-decoration: none;+ text-underline-offset: 0.15em;+}++.mineru-document a:hover {+ color: var(--mineru-accent-hover);+ text-decoration: underline;+}++.mineru-document a:focus-visible {+ border-radius: 0.15rem;+ outline: 2px solid var(--mineru-accent);+ outline-offset: 2px;+}++.mineru-document blockquote {+ background: var(--mineru-surface);+ border-left: 0.25rem solid var(--mineru-accent);+ color: var(--mineru-muted);margin: 1rem 0;- padding: 0.65rem 0.85rem;+ padding: 0.75rem 1rem;}-.mineru-document .mineru-details > summary,-.mineru-document details[data-block-type] > summary {- cursor: pointer;- font-weight: 600;+.mineru-document blockquote > :first-child {+ margin-top: 0;+}++.mineru-document blockquote > :last-child {+ margin-bottom: 0;+}++/* 普通列表使用浏览器语义,混合标记列表使用 renderer 输出的显式网格。 */+.mineru-document :is(ol, ul) {+ margin: 0 0 1rem;+ padding-left: 1.75rem;+}++.mineru-document ul {+ list-style: disc;+}++.mineru-document ul ul {+ list-style: circle;+}++.mineru-document ul ul ul {+ list-style: square;+}++.mineru-document ol {+ list-style: decimal;+}++.mineru-document :is(ol, ul) ol {+ list-style-type: lower-roman;+}++.mineru-document :is(ol, ul) :is(ol, ul) ol {+ list-style-type: lower-alpha;+}++.mineru-document li + li {+ margin-top: 0.25rem;+}++.mineru-document li > :is(ol, ul) {+ margin-bottom: 0;+ margin-top: 0.25rem;}-/* 非标准或混合列表标记由渲染器显式输出,避免浏览器重新编号。 */.mineru-document .mineru-list--explicit {list-style: none;padding-left: 1.5rem;@@ -78,6 +164,7 @@.mineru-document .mineru-list--unmarked {list-style: none;+ padding-left: 0;}.mineru-document .mineru-list-item--explicit {@@ -87,6 +174,16 @@grid-template-columns: max-content minmax(0, 1fr);}+.mineru-document .mineru-list-item--orphan {+ display: grid;+ grid-template-columns: 0 minmax(0, 1fr);+ list-style: none;+}++.mineru-document .mineru-list-item--markerless {+ list-style: none;+}+.mineru-document .mineru-list-marker {font-variant-numeric: tabular-nums;text-align: right;@@ -94,12 +191,8 @@white-space: pre;}-.mineru-document .mineru-list-item--orphan {- list-style: none;-}--.mineru-document .mineru-list-item--markerless {- list-style: none;+.mineru-document .mineru-list-content {+ min-width: 0;}.mineru-document .mineru-list-item--orphan > .mineru-list-marker {@@ -112,7 +205,6 @@margin-bottom: 0;}-/* 目录不显示普通列表项目符号,并为长标题保留可换行空间。 */.mineru-document .mineru-index,.mineru-document .mineru-index ul {list-style: none;@@ -127,29 +219,33 @@overflow-wrap: anywhere;}-/* MathJax 接管前保留可见 TeX;块公式允许横向滚动。 */-.mineru-document .mineru-math {- overflow-wrap: anywhere;-}--.mineru-document .mineru-math--block {+/* 表格在屏幕内独立滚动,打印时恢复为完整 table。 */+.mineru-document table {+ border-collapse: collapse;+ border-spacing: 0;display: block;margin: 1rem 0;max-width: 100%;overflow-x: auto;- overflow-y: hidden;- text-align: center;+ width: 100%;}-.mineru-document .mineru-preserve-whitespace {- white-space: pre-wrap;+.mineru-document :is(th, td) {+ border: 1px solid var(--mineru-border);+ padding: 0.5rem 0.75rem;+ text-align: left;+ vertical-align: top;}-.mineru-document .mineru-text-emphasis {- -webkit-text-emphasis: dot;- -webkit-text-emphasis-position: under right;- text-emphasis: dot;- text-emphasis-position: under right;+.mineru-document th {+ background: var(--mineru-surface);+ font-weight: 600;+}++.mineru-document caption {+ color: var(--mineru-muted);+ margin-bottom: 0.5rem;+ text-align: left;}.mineru-document :is(th, td).mineru-align-left {@@ -164,13 +260,178 @@text-align: right;}-.mineru-document mjx-container[display="true"] {+/* 图片、图表及说明共享同一视觉容器。 */+.mineru-document img {+ height: auto;+ max-width: 100%;+}++.mineru-document .mineru-figure {+ margin: 1.5rem 0;+ max-width: 100%;+}++.mineru-document .mineru-figure > img {+ display: block;+ margin-inline: auto;+}++.mineru-document .mineru-caption {+ color: var(--mineru-muted);+ font-size: 0.9em;+ margin-top: 0.5rem;+ text-align: center;+}++.mineru-document .mineru-footnote {+ color: var(--mineru-muted);+ font-size: 0.875em;+ margin-top: 0.4rem;+}++.mineru-document .mineru-details {+ border: 1px solid var(--mineru-border);+ border-radius: 0.375rem;+ margin: 1rem 0;+ padding: 0.65rem 0.85rem;+}++.mineru-document .mineru-details > summary {+ cursor: pointer;+ font-weight: 600;+}++.mineru-document .mineru-page-aux {+ color: var(--mineru-muted);+ font-size: 0.875rem;+}++/* 行内代码、预格式内容和 Prism token 采用 MinerU 自有配色。 */+.mineru-document code,+.mineru-document pre,+.mineru-document .mineru-algorithm {+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;+}++.mineru-document code {+ background: var(--mineru-surface);+ border-radius: 0.25rem;+ font-size: 0.875em;+ padding: 0.15em 0.35em;+}++.mineru-document pre {+ background: var(--mineru-surface);+ border: 1px solid var(--mineru-border);+ border-radius: 0.375rem;+ line-height: 1.5;+ margin: 1rem 0;+ max-width: 100%;+ overflow: auto;+ padding: 1rem;+ tab-size: 4;+ white-space: pre;+}++.mineru-document pre > code {+ background: transparent;+ border-radius: 0;+ display: inline;+ font-size: inherit;+ line-height: inherit;+ padding: 0;+ white-space: inherit;+}++.mineru-document :is(code, pre)[class*="language-"] {+ color: #374151;+ text-align: left;+ text-shadow: none;+ word-break: normal;+ word-spacing: normal;+}++.mineru-document .token.comment,+.mineru-document .token.prolog,+.mineru-document .token.doctype,+.mineru-document .token.cdata {+ color: #6b7280;+}++.mineru-document .token.punctuation {+ color: #374151;+}++.mineru-document .token.namespace {+ opacity: 0.75;+}++.mineru-document .token.keyword,+.mineru-document .token.operator,+.mineru-document .token.important,+.mineru-document .token.atrule {+ color: #7c3aed;+}++.mineru-document .token.string,+.mineru-document .token.attr-value,+.mineru-document .token.regex,+.mineru-document .token.url {+ color: #047857;+}++.mineru-document .token.number,+.mineru-document .token.boolean,+.mineru-document .token.constant,+.mineru-document .token.property,+.mineru-document .token.symbol {+ color: #0369a1;+}++.mineru-document .token.tag,+.mineru-document .token.selector,+.mineru-document .token.builtin {+ color: #b45309;+}++.mineru-document .token.function,+.mineru-document .token.class-name,+.mineru-document .token.attr-name {+ color: #be123c;+}++.mineru-document .token.important,+.mineru-document .token.bold {+ font-weight: 700;+}++.mineru-document .token.italic {+ font-style: italic;+}++.mineru-document .token.inserted {+ background: #ecfdf5;+ color: #047857;+}++.mineru-document .token.deleted {+ background: #fff1f2;+ color: #be123c;+}++.mineru-document .token.entity {+ cursor: help;+}++.mineru-document .mineru-algorithm {max-width: 100%;overflow-x: auto;- overflow-y: hidden;+ tab-size: 4;+ white-space: pre-wrap;+ word-break: normal;}-/* 空间投影表格和不可解析原文必须保持空白与换行。 */+/* 空间投影表格和无法结构化的原文保留空白与换行。 */.mineru-document .mineru-table-text,.mineru-document .mineru-raw-fallback {overflow: auto;@@ -184,44 +445,82 @@}.mineru-document .mineru-raw-fallback {- border-left: 3px solid #d0d7de;- color: #57606a;+ border-left: 0.2rem solid var(--mineru-border);+ color: var(--mineru-muted);}-/* 算法文本保留缩进,同时允许行内公式和上下标参与排版。 */-.mineru-document .mineru-algorithm {- font-family: Menlo, Monaco, Consolas, "Courier New", monospace;+/* MathJax 接管前保持 TeX 可见,长公式只在自身容器内滚动。 */+.mineru-document .mineru-math {+ overflow-wrap: anywhere;+}++.mineru-document .mineru-math--block {+ display: block;+ margin: 1rem 0;max-width: 100%;overflow-x: auto;- tab-size: 4;- white-space: pre-wrap;- word-break: normal;+ overflow-y: hidden;+ text-align: center;}-/* Prism 异步加载语言组件时,补充少量通用 token 表现。 */-.mineru-document pre[class*="language-"] {+.mineru-document mjx-container[display="true"] {max-width: 100%;+ overflow-x: auto;+ overflow-y: hidden;}-.mineru-document pre[class*="language-"] > code {- text-shadow: none;+.mineru-document .mineru-preserve-whitespace {+ white-space: pre-wrap;}-.mineru-document .token.namespace {- opacity: 0.75;+.mineru-document .mineru-text-emphasis {+ -webkit-text-emphasis: dot;+ -webkit-text-emphasis-position: under right;+ text-emphasis: dot;+ text-emphasis-position: under right;}-.mineru-document .token.important {- font-weight: 700;+/* FULL 模式在屏幕上显示页间边界,在打印时改用硬分页。 */+.mineru-document .mineru-page {+ min-width: 0;+ position: relative;+}++.mineru-document--full .mineru-page {+ min-height: 1.5rem;+}++.mineru-document .mineru-page-break {+ background: transparent;+ border: 0;+ border-top: 1px dashed var(--mineru-border);+ height: 0;+ margin: 2rem 0;+}++@media screen and (max-width: 40rem) {+ .mineru-html-body > .mineru-document {+ padding: 1rem;+ }++ .mineru-document h1 {+ font-size: 1.75rem;+ }++ .mineru-document :is(th, td) {+ padding: 0.4rem 0.55rem;+ }}@media print {- body[for="html-export"] {- margin: 0;+ .mineru-html-body {+ background: #ffffff;}- .mineru-document {+ .mineru-html-body > .mineru-document {max-width: none;+ min-height: 0;+ padding: 0;}.mineru-document .mineru-page-break {@@ -238,9 +537,19 @@page-break-after: auto;}- .mineru-document .mineru-figure,- .mineru-document figure[data-block-type] {+ .mineru-document .mineru-figure {break-inside: avoid;page-break-inside: avoid;}++ .mineru-document table {+ display: table;+ overflow: visible;+ }++ .mineru-document pre {+ overflow: visible;+ white-space: pre-wrap;+ word-break: break-word;+ }}diff --git a/mineru/resources/html/mineru.min.css b/mineru/resources/html/mineru.min.cssnew file mode 100644index 00000000..af801dcd--- /dev/null+++ b/mineru/resources/html/mineru.min.css@@ -0,0 +1 @@+.mineru-html-body{background:#ffffff;margin:0}.mineru-html-body>.mineru-document{margin:0 auto;max-width:60rem;min-height:100vh;padding:2rem}.mineru-document{--mineru-accent:#f97316;--mineru-accent-hover:#c2410c;--mineru-background:#ffffff;--mineru-border:#d1d5db;--mineru-muted:#6b7280;--mineru-surface:#f8fafc;--mineru-text:#1f2937;background:var(--mineru-background);box-sizing:border-box;color:var(--mineru-text);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;font-size:16px;line-height:1.65;overflow-wrap:break-word;width:100%}.mineru-document *,.mineru-document *::before,.mineru-document *::after{box-sizing:inherit}.mineru-document:is(h1,h2,h3,h4,h5,h6){color:var(--mineru-text);font-weight:600;line-height:1.3;margin:1.5em 0 0.65em}.mineru-document h1{font-size:2rem}.mineru-document h2{font-size:1.5rem}.mineru-document h3{font-size:1.25rem}.mineru-document h4{font-size:1.125rem}.mineru-document h5{font-size:1rem}.mineru-document h6{color:var(--mineru-muted);font-size:0.875rem}.mineru-document .mineru-block:first-child>:first-child,.mineru-document .mineru-page>.mineru-block:first-child>:first-child{margin-top:0}.mineru-document p{margin:0 0 1rem}.mineru-document:is(strong,b){font-weight:700}.mineru-document:is(s,del){color:var(--mineru-muted)}.mineru-document a{color:var(--mineru-accent);text-decoration:none;text-underline-offset:0.15em}.mineru-document a:hover{color:var(--mineru-accent-hover);text-decoration:underline}.mineru-document a:focus-visible{border-radius:0.15rem;outline:2px solid var(--mineru-accent);outline-offset:2px}.mineru-document blockquote{background:var(--mineru-surface);border-left:0.25rem solid var(--mineru-accent);color:var(--mineru-muted);margin:1rem 0;padding:0.75rem 1rem}.mineru-document blockquote>:first-child{margin-top:0}.mineru-document blockquote>:last-child{margin-bottom:0}.mineru-document:is(ol,ul){margin:0 0 1rem;padding-left:1.75rem}.mineru-document ul{list-style:disc}.mineru-document ul ul{list-style:circle}.mineru-document ul ul ul{list-style:square}.mineru-document ol{list-style:decimal}.mineru-document:is(ol,ul) ol{list-style-type:lower-roman}.mineru-document:is(ol,ul):is(ol,ul) ol{list-style-type:lower-alpha}.mineru-document li + li{margin-top:0.25rem}.mineru-document li>:is(ol,ul){margin-bottom:0;margin-top:0.25rem}.mineru-document .mineru-list--explicit{list-style:none;padding-left:1.5rem}.mineru-document .mineru-list--unmarked{list-style:none;padding-left:0}.mineru-document .mineru-list-item--explicit{align-items:start;display:grid;gap:0.5em;grid-template-columns:max-content minmax(0,1fr)}.mineru-document .mineru-list-item--orphan{display:grid;grid-template-columns:0 minmax(0,1fr);list-style:none}.mineru-document .mineru-list-item--markerless{list-style:none}.mineru-document .mineru-list-marker{font-variant-numeric:tabular-nums;text-align:right;user-select:none;white-space:pre}.mineru-document .mineru-list-content{min-width:0}.mineru-document .mineru-list-item--orphan>.mineru-list-marker{visibility:hidden}.mineru-document .mineru-list-item--orphan>:is(ol,ul),.mineru-document .mineru-list-item--explicit>:is(ol,ul){grid-column:2;margin-bottom:0}.mineru-document .mineru-index,.mineru-document .mineru-index ul{list-style:none;padding-left:0}.mineru-document .mineru-index ul ul{padding-left:1.5rem}.mineru-document .mineru-index a{overflow-wrap:anywhere}.mineru-document table{border-collapse:collapse;border-spacing:0;display:block;margin:1rem 0;max-width:100%;overflow-x:auto;width:100%}.mineru-document:is(th,td){border:1px solid var(--mineru-border);padding:0.5rem 0.75rem;text-align:left;vertical-align:top}.mineru-document th{background:var(--mineru-surface);font-weight:600}.mineru-document caption{color:var(--mineru-muted);margin-bottom:0.5rem;text-align:left}.mineru-document:is(th,td).mineru-align-left{text-align:left}.mineru-document:is(th,td).mineru-align-center{text-align:center}.mineru-document:is(th,td).mineru-align-right{text-align:right}.mineru-document img{height:auto;max-width:100%}.mineru-document .mineru-figure{margin:1.5rem 0;max-width:100%}.mineru-document .mineru-figure>img{display:block;margin-inline:auto}.mineru-document .mineru-caption{color:var(--mineru-muted);font-size:0.9em;margin-top:0.5rem;text-align:center}.mineru-document .mineru-footnote{color:var(--mineru-muted);font-size:0.875em;margin-top:0.4rem}.mineru-document .mineru-details{border:1px solid var(--mineru-border);border-radius:0.375rem;margin:1rem 0;padding:0.65rem 0.85rem}.mineru-document .mineru-details>summary{cursor:pointer;font-weight:600}.mineru-document .mineru-page-aux{color:var(--mineru-muted);font-size:0.875rem}.mineru-document code,.mineru-document pre,.mineru-document .mineru-algorithm{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace}.mineru-document code{background:var(--mineru-surface);border-radius:0.25rem;font-size:0.875em;padding:0.15em 0.35em}.mineru-document pre{background:var(--mineru-surface);border:1px solid var(--mineru-border);border-radius:0.375rem;line-height:1.5;margin:1rem 0;max-width:100%;overflow:auto;padding:1rem;tab-size:4;white-space:pre}.mineru-document pre>code{background:transparent;border-radius:0;display:inline;font-size:inherit;line-height:inherit;padding:0;white-space:inherit}.mineru-document:is(code,pre)[class*="language-"]{color:#374151;text-align:left;text-shadow:none;word-break:normal;word-spacing:normal}.mineru-document .token.comment,.mineru-document .token.prolog,.mineru-document .token.doctype,.mineru-document .token.cdata{color:#6b7280}.mineru-document .token.punctuation{color:#374151}.mineru-document .token.namespace{opacity:0.75}.mineru-document .token.keyword,.mineru-document .token.operator,.mineru-document .token.important,.mineru-document .token.atrule{color:#7c3aed}.mineru-document .token.string,.mineru-document .token.attr-value,.mineru-document .token.regex,.mineru-document .token.url{color:#047857}.mineru-document .token.number,.mineru-document .token.boolean,.mineru-document .token.constant,.mineru-document .token.property,.mineru-document .token.symbol{color:#0369a1}.mineru-document .token.tag,.mineru-document .token.selector,.mineru-document .token.builtin{color:#b45309}.mineru-document .token.function,.mineru-document .token.class-name,.mineru-document .token.attr-name{color:#be123c}.mineru-document .token.important,.mineru-document .token.bold{font-weight:700}.mineru-document .token.italic{font-style:italic}.mineru-document .token.inserted{background:#ecfdf5;color:#047857}.mineru-document .token.deleted{background:#fff1f2;color:#be123c}.mineru-document .token.entity{cursor:help}.mineru-document .mineru-algorithm{max-width:100%;overflow-x:auto;tab-size:4;white-space:pre-wrap;word-break:normal}.mineru-document .mineru-table-text,.mineru-document .mineru-raw-fallback{overflow:auto;tab-size:4;white-space:pre-wrap;word-break:break-word}.mineru-document .mineru-table-text{white-space:pre}.mineru-document .mineru-raw-fallback{border-left:0.2rem solid var(--mineru-border);color:var(--mineru-muted)}.mineru-document .mineru-math{overflow-wrap:anywhere}.mineru-document .mineru-math--block{display:block;margin:1rem 0;max-width:100%;overflow-x:auto;overflow-y:hidden;text-align:center}.mineru-document mjx-container[display="true"]{max-width:100%;overflow-x:auto;overflow-y:hidden}.mineru-document .mineru-preserve-whitespace{white-space:pre-wrap}.mineru-document .mineru-text-emphasis{-webkit-text-emphasis:dot;-webkit-text-emphasis-position:under right;text-emphasis:dot;text-emphasis-position:under right}.mineru-document .mineru-page{min-width:0;position:relative}.mineru-document--full .mineru-page{min-height:1.5rem}.mineru-document .mineru-page-break{background:transparent;border:0;border-top:1px dashed var(--mineru-border);height:0;margin:2rem 0}@media screen and (max-width:40rem){.mineru-html-body>.mineru-document{padding:1rem}.mineru-document h1{font-size:1.75rem}.mineru-document:is(th,td){padding:0.4rem 0.55rem}}@media print{.mineru-html-body{background:#ffffff}.mineru-html-body>.mineru-document{max-width:none;min-height:0;padding:0}.mineru-document .mineru-page-break{display:none}.mineru-document--full .mineru-page{break-after:page;page-break-after:always}.mineru-document--full .mineru-page:last-child{break-after:auto;page-break-after:auto}.mineru-document .mineru-figure{break-inside:avoid;page-break-inside:avoid}.mineru-document table{display:table;overflow:visible}.mineru-document pre{overflow:visible;white-space:pre-wrap;word-break:break-word}}\ No newline at end of filediff --git a/scripts/build_html_css.py b/scripts/build_html_css.pynew file mode 100644index 00000000..c4371585--- /dev/null+++ b/scripts/build_html_css.py@@ -0,0 +1,168 @@+#!/usr/bin/env python3+"""生成并校验 MinerU HTML 渲染器使用的压缩 CSS。"""++from __future__ import annotations++import argparse+import os+import tempfile+from pathlib import Path+from typing import Sequence+++_PROJECT_ROOT = Path(__file__).resolve().parents[1]+_SOURCE_PATH = _PROJECT_ROOT / "mineru" / "resources" / "html" / "mineru.css"+_OUTPUT_PATH = _PROJECT_ROOT / "mineru" / "resources" / "html" / "mineru.min.css"+_COMPACT_PUNCTUATION = frozenset("{}:;,>")+++def minify_css(source: str) -> str:+ """在不改写 CSS 值的前提下删除注释和可安全省略的空白。"""+ output: list[str] = []+ pending_space = False+ quote: str | None = None+ brace_depth = 0+ index = 0++ while index < len(source):+ char = source[index]++ if quote is not None:+ output.append(char)+ if char == "\\":+ index += 1+ if index >= len(source):+ raise ValueError("CSS 字符串以未完成的转义结尾")+ output.append(source[index])+ elif char == quote:+ quote = None+ index += 1+ continue++ if source.startswith("/*", index):+ comment_end = source.find("*/", index + 2)+ if comment_end < 0:+ raise ValueError("CSS 包含未闭合的注释")+ pending_space = bool(output)+ index = comment_end + 2+ continue++ if char in {'"', "'"}:+ if pending_space and _needs_separator(output, char):+ output.append(" ")+ pending_space = False+ quote = char+ output.append(char)+ index += 1+ continue++ if char == "\\":+ if pending_space and _needs_separator(output, char):+ output.append(" ")+ pending_space = False+ output.append(char)+ index += 1+ if index >= len(source):+ raise ValueError("CSS 以未完成的转义结尾")+ output.append(source[index])+ index += 1+ continue++ if char.isspace():+ pending_space = bool(output)+ index += 1+ continue++ if char in _COMPACT_PUNCTUATION:+ if output and output[-1] == " ":+ output.pop()+ if char == "}" and output and output[-1] == ";":+ output.pop()+ if char == "{":+ brace_depth += 1+ elif char == "}":+ brace_depth -= 1+ if brace_depth < 0:+ raise ValueError("CSS 包含多余的右花括号")+ output.append(char)+ pending_space = False+ index += 1+ continue++ if pending_space and _needs_separator(output, char):+ output.append(" ")+ pending_space = False+ output.append(char)+ index += 1++ if quote is not None:+ raise ValueError("CSS 包含未闭合的字符串")+ if brace_depth:+ raise ValueError("CSS 包含未闭合的规则块")+ return "".join(output).strip()+++def _needs_separator(output: list[str], next_char: str) -> bool:+ """判断待处理空白是否用于分隔两个不能直接相邻的 CSS token。"""+ return (+ bool(output)+ and output[-1] not in _COMPACT_PUNCTUATION+ and next_char not in _COMPACT_PUNCTUATION+ )+++def _write_atomically(path: Path, content: str) -> None:+ """在目标目录创建临时文件并原子替换最终 CSS 产物。"""+ temporary_path: Path | None = None+ try:+ with tempfile.NamedTemporaryFile(+ "w",+ encoding="utf-8",+ dir=path.parent,+ prefix=f".{path.name}.",+ delete=False,+ ) as temporary:+ temporary.write(content)+ temporary_path = Path(temporary.name)+ temporary_path.chmod(0o644)+ os.replace(temporary_path, path)+ temporary_path = None+ finally:+ if temporary_path is not None:+ temporary_path.unlink(missing_ok=True)+++def build_html_css(*, check: bool) -> bool:+ """生成压缩 CSS,或只检查现有产物是否与源码一致。"""+ minified = minify_css(_SOURCE_PATH.read_text(encoding="utf-8"))+ existing = _OUTPUT_PATH.read_text(encoding="utf-8") if _OUTPUT_PATH.exists() else None+ if existing == minified:+ return True+ if check:+ return False+ _write_atomically(_OUTPUT_PATH, minified)+ return True+++def _parse_args(argv: Sequence[str] | None) -> argparse.Namespace:+ """解析构建脚本的只校验选项。"""+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--check", action="store_true", help="仅校验 mineru.min.css 是否需要重新生成")+ return parser.parse_args(argv)+++def main(argv: Sequence[str] | None = None) -> int:+ """执行 CSS 构建并用退出码报告同步状态。"""+ args = _parse_args(argv)+ if build_html_css(check=args.check):+ action = "校验通过" if args.check else "生成完成"+ print(f"{action}: {_OUTPUT_PATH.relative_to(_PROJECT_ROOT)}")+ return 0+ print(+ f"压缩 CSS 已过期,请运行: {Path(__file__).relative_to(_PROJECT_ROOT)}",+ )+ return 1+++if __name__ == "__main__":+ raise SystemExit(main())diff --git a/tests/unittest/test_html_css_build.py b/tests/unittest/test_html_css_build.pynew file mode 100644index 00000000..fd6b904a--- /dev/null+++ b/tests/unittest/test_html_css_build.py@@ -0,0 +1,76 @@+from __future__ import annotations++from pathlib import Path++import pytest++from scripts import build_html_css+++def test_committed_minified_css_matches_readable_source() -> None:+ """验证仓库提交的 min 产物始终由当前可读源码确定性生成。"""+ project_root = Path(__file__).resolve().parents[2]+ resource_root = project_root / "mineru" / "resources" / "html"+ source = resource_root.joinpath("mineru.css").read_text(encoding="utf-8")+ minified = resource_root.joinpath("mineru.min.css").read_text(encoding="utf-8")++ assert minified == build_html_css.minify_css(source)+++def test_minify_css_preserves_strings_escapes_and_calc_spacing() -> None:+ """验证压缩过程只删除安全空白,不破坏字符串、转义和 calc 运算符。"""+ source = r"""+/* removable */+@media screen and (max-width: 40rem) {+ .demo::before {+ content: "a /* not comment */ b";+ font-family: "Courier New";+ width: calc(100% - 2rem);+ }+ .escaped\ class {+ --label: 'x\' y';+ }+}+"""++ expected = (+ '@media screen and (max-width:40rem){.demo::before{content:"a /* not comment */ b";'+ 'font-family:"Courier New";width:calc(100% - 2rem)}'+ ".escaped\\ class{--label:'x\\' y'}}"+ )+ assert build_html_css.minify_css(source) == expected+++ "source",+ [+ "a { color: red;",+ "a { content: \"unterminated; }",+ "a { color: red; /* unterminated",+ "a { color: red; }}",+ "a { content: \\",+ ],+)+def test_minify_css_rejects_unterminated_or_unbalanced_input(source: str) -> None:+ """验证生成器拒绝未闭合字符串、注释、转义和规则块。"""+ with pytest.raises(ValueError):+ build_html_css.minify_css(source)+++def test_build_html_css_check_detects_and_repairs_stale_output(+ tmp_path: Path,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """验证 check 模式无写入地报告过期产物,普通模式再原子修复。"""+ source_path = tmp_path / "mineru.css"+ output_path = tmp_path / "mineru.min.css"+ source_path.write_text(".demo { color: red; }\n", encoding="utf-8")+ output_path.write_text("stale", encoding="utf-8")+ monkeypatch.setattr(build_html_css, "_SOURCE_PATH", source_path)+ monkeypatch.setattr(build_html_css, "_OUTPUT_PATH", output_path)++ assert build_html_css.build_html_css(check=True) is False+ assert output_path.read_text(encoding="utf-8") == "stale"+ assert build_html_css.build_html_css(check=False) is True+ assert output_path.read_text(encoding="utf-8") == ".demo{color:red}"+ assert build_html_css.build_html_css(check=True) is Truediff --git a/tests/unittest/test_html_render.py b/tests/unittest/test_html_render.pyindex ff12122d..ecce91da 100644--- a/tests/unittest/test_html_render.py+++ b/tests/unittest/test_html_render.py@@ -1,7 +1,6 @@from __future__ import annotationsfrom copy import deepcopy-from hashlib import sha256from importlib import resourcesfrom bs4 import BeautifulSoup@@ -80,13 +79,12 @@ def test_public_contract_fragment_standalone_title_and_input_immutability() -> Nfragment = render_html(middle, standalone=False)standalone = render_html(middle)- assert fragment.startswith('<article class="crossnote markdown-preview mineru-document')+ assert fragment.startswith('<article class="mineru-document mineru-document--default">')assert fragment in standaloneassert '<html lang="und">' in standaloneassert "<title>Demo <unsafe></title>" in standalone- assert '<body for="html-export">' in standalone+ assert '<body class="mineru-html-body">' in standaloneassert "<style>" in standalone- assert "Crossnote 0.9.31 CSS license notice" in standaloneassert "mathjax@" not in standaloneassert "prismjs@" not in standaloneassert middle == original@@ -579,23 +577,20 @@ def test_chart_gfm_pipe_matches_markdown_it_backslash_decoding(slash_count: int,assert soup.select_one(".mineru-chart-table td").get_text() == expected-def test_crossnote_resources_are_byte_exact_and_packaged_with_license() -> None:- """验证三份上游 CSS 字节、来源声明及 NCSA 许可证随包存在。"""- root = resources.files("mineru").joinpath("resources", "html", "crossnote")- expected = {- "github-light.css": "020bb992e41828c9ef14f687f2a71e99e2bf6f69e32de9d1ee1e292604f0d779",- "style-template.css": "054061cb501481af702df4adf8d2c224d666b6fe78a84a1c3a362e6a92cfdcdf",- "github.css": "885fa37a859ef386c471e7dee272e882d09c1c600b853b6f518daf40bbd1ba02",- }-- for name, digest in expected.items():- assert sha256(root.joinpath(name).read_bytes()).hexdigest() == digest- assert "University of Illinois/NCSA" in root.joinpath("LICENSE.md").read_text(encoding="utf-8")- assert sha256(root.joinpath("LICENSE.md").read_bytes()).hexdigest() == (- "a0459e70cef4048eba8c05562387fb05913ad8bbc67904ac866edded85e9d073"- )- source = root.joinpath("SOURCE.md").read_text(encoding="utf-8")- assert "Crossnote 0.9.31" in source and "MPE 0.8.30" in source+def test_mineru_styles_are_minified_scoped_and_inlined_byte_exact() -> None:+ """验证独立样式产物体积、作用域及 standalone 的逐字内联契约。"""+ root = resources.files("mineru").joinpath("resources", "html")+ source = root.joinpath("mineru.css").read_text(encoding="utf-8")+ minified = root.joinpath("mineru.min.css").read_text(encoding="utf-8")+ standalone = render_html(_middle())+ style = BeautifulSoup(standalone, "html.parser").style++ assert len(minified.encode("utf-8")) <= 10 * 1024+ assert "\n" not in minified and "/*" not in minified+ assert ".mineru-document" in source and ".mineru-html-body" in source+ assert style is not None and style.string == minified+ assert f"<style>{minified}</style>" in standalone+ assert not root.joinpath("crossnote").is_dir()def test_empty_document_and_equation_image_do_not_load_external_scripts() -> None:@@ -603,7 +598,7 @@ def test_empty_document_and_equation_image_do_not_load_external_scripts() -> Nonempty = render_html(_middle())image_equation = render_html(_middle(_page(0, EquationBlock(type="equation", index=0, content="", image_base64=_PNG_URI))))- assert '<article class="crossnote markdown-preview mineru-document mineru-document--default">\n\n</article>' in empty+ assert '<article class="mineru-document mineru-document--default">\n\n</article>' in emptyassert "mathjax@" not in empty and "prismjs@" not in emptyassert "mathjax@" not in image_equation and "prismjs@" not in image_equationassert "data:image/png" in image_equationdiff --git a/tests/unittest/test_render_api.py b/tests/unittest/test_render_api.pyindex 322651ff..8f55fd8d 100644--- a/tests/unittest/test_render_api.py+++ b/tests/unittest/test_render_api.py@@ -117,7 +117,7 @@ def test_unified_render_forwards_format_specific_options() -> None:original_tree = render(middle, RenderFormat.CONTENT_LIST)assert "\n\n---\n\n" in markdown- assert html.startswith('<article class="crossnote markdown-preview mineru-document')+ assert html.startswith('<article class="mineru-document mineru-document--full">')assert "<!doctype html>" not in htmlassert content_list["pages"][0]["blocks"][0]["image_source"] == ("https://cdn.example/doc/images/a%20b.png"