求助能否将“优化排版”按钮从折叠菜单中放到外面来

image.png

  • 思源笔记

    思源笔记是一款隐私优先的个人知识管理系统,支持完全离线使用,同时也支持端到端加密同步。

    融合块、大纲和双向链接,重构你的思维。

    25764 引用 • 106649 回帖
  • Q&A

    提问之前请先看《提问的智慧》,好的问题比好的答案更有价值。

    9878 引用 • 44910 回帖 • 78 关注

相关帖子

被采纳的回答
  • wilsons 2 2 赞同

    最完美的方式,当如是也

    image.png

    // 把优化排版菜单移动到文档导航条 { const main = (protyle)=>{ // 发布服务下不显示 if(window.siyuan.config.readonly) return; if(protyle?.querySelector('.protyle-breadcrumb [data-type="optimizeTypography"]')) return; const exitFocusBtn = protyle.querySelector('.protyle-breadcrumb [data-type="exit-focus"]'); if(!exitFocusBtn) return; const optimizeHtml = `<button class="block__icon fn__flex-center ariaLabel" aria-label="优化排版" data-type="optimizeTypography"><svg><use xlink:href="#iconFormat"></use></svg></button>`; exitFocusBtn.insertAdjacentHTML('afterend', optimizeHtml); const optimizeBtn = protyle.querySelector('.protyle-breadcrumb [data-type="optimizeTypography"]'); if(!optimizeBtn) return; optimizeBtn.addEventListener('click', () => { // 锁定状态下不可修改 const icon = protyle?.querySelector('button[data-type="readonly"] use')?.getAttributeNS('http://www.w3.org/1999/xlink', 'href'); if(icon === '#iconLock') { showMessage('锁定状态不可用'); return } // 优化排版 // see https://github.com/siyuan-note/siyuan/blob/a01523dc98799590396ffcabdc90b2dc6efe8474/app/src/protyle/breadcrumb/index.ts#L415 requestApi("/api/format/autoSpace", { id: protyle?.querySelector('.protyle-title')?.dataset?.nodeId }); }); }; // 监听protyle加载 whenElementExist('.protyle:not(.fn__none)').then(main); observeProtyleLoad(main); function showMessage(message, isError = false, delay = 7000) { return fetch('/api/notification/' + (isError ? 'pushErrMsg' : 'pushMsg'), { "method": "POST", "body": JSON.stringify({"msg": message, "timeout": delay}) }); } async function requestApi(url, data, method = 'POST') { return await (await fetch(url, {method: method, body: JSON.stringify(data||{})})).json(); } function whenElementExist(selector, node) { return new Promise(resolve => { const check = () => { const el = typeof selector==='function'?selector():(node||document).querySelector(selector); if (el) resolve(el); else requestAnimationFrame(check); }; check(); }); } function observeProtyleLoad(callback, parentElement) { // 如果 parentElement 是字符串,则将其转换为 DOM 元素 if (typeof parentElement === 'string') { parentElement = document.querySelector(parentElement); } // 创建一个 MutationObserver 实例 const observer = new MutationObserver((mutationsList) => { mutationsList.forEach((mutation) => { // 检查是否是属性变化并且变化的属性是 class if (mutation.type === 'attributes' && mutation.attributeName === 'class') { const targetElement = mutation.target; // 发生变化的目标元素 // 判断目标元素是否匹配指定选择器 .protyle:not(.fn__none) if (targetElement.matches('.protyle:not(.fn__none)')) { // 触发回调 callback(targetElement); } } }); }); // 配置观察选项 const config = { attributes: true, // 监听属性变化 attributeFilter: ['class'], // 仅监听 class 属性 subtree: true, // 监听父容器及其所有后代元素 }; // 启动观察,默认监听 document.body 或指定的父容器 observer.observe(parentElement || document.body, config); } }

    类似文章推荐 https://pipe.b3log.org/blogs/wilsons/articles/2025/05/13/1744703423359

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
  • wilsons 2 2 赞同 3 评论

    最完美的方式,当如是也

    image.png

    // 把优化排版菜单移动到文档导航条 { const main = (protyle)=>{ // 发布服务下不显示 if(window.siyuan.config.readonly) return; if(protyle?.querySelector('.protyle-breadcrumb [data-type="optimizeTypography"]')) return; const exitFocusBtn = protyle.querySelector('.protyle-breadcrumb [data-type="exit-focus"]'); if(!exitFocusBtn) return; const optimizeHtml = `<button class="block__icon fn__flex-center ariaLabel" aria-label="优化排版" data-type="optimizeTypography"><svg><use xlink:href="#iconFormat"></use></svg></button>`; exitFocusBtn.insertAdjacentHTML('afterend', optimizeHtml); const optimizeBtn = protyle.querySelector('.protyle-breadcrumb [data-type="optimizeTypography"]'); if(!optimizeBtn) return; optimizeBtn.addEventListener('click', () => { // 锁定状态下不可修改 const icon = protyle?.querySelector('button[data-type="readonly"] use')?.getAttributeNS('http://www.w3.org/1999/xlink', 'href'); if(icon === '#iconLock') { showMessage('锁定状态不可用'); return } // 优化排版 // see https://github.com/siyuan-note/siyuan/blob/a01523dc98799590396ffcabdc90b2dc6efe8474/app/src/protyle/breadcrumb/index.ts#L415 requestApi("/api/format/autoSpace", { id: protyle?.querySelector('.protyle-title')?.dataset?.nodeId }); }); }; // 监听protyle加载 whenElementExist('.protyle:not(.fn__none)').then(main); observeProtyleLoad(main); function showMessage(message, isError = false, delay = 7000) { return fetch('/api/notification/' + (isError ? 'pushErrMsg' : 'pushMsg'), { "method": "POST", "body": JSON.stringify({"msg": message, "timeout": delay}) }); } async function requestApi(url, data, method = 'POST') { return await (await fetch(url, {method: method, body: JSON.stringify(data||{})})).json(); } function whenElementExist(selector, node) { return new Promise(resolve => { const check = () => { const el = typeof selector==='function'?selector():(node||document).querySelector(selector); if (el) resolve(el); else requestAnimationFrame(check); }; check(); }); } function observeProtyleLoad(callback, parentElement) { // 如果 parentElement 是字符串,则将其转换为 DOM 元素 if (typeof parentElement === 'string') { parentElement = document.querySelector(parentElement); } // 创建一个 MutationObserver 实例 const observer = new MutationObserver((mutationsList) => { mutationsList.forEach((mutation) => { // 检查是否是属性变化并且变化的属性是 class if (mutation.type === 'attributes' && mutation.attributeName === 'class') { const targetElement = mutation.target; // 发生变化的目标元素 // 判断目标元素是否匹配指定选择器 .protyle:not(.fn__none) if (targetElement.matches('.protyle:not(.fn__none)')) { // 触发回调 callback(targetElement); } } }); }); // 配置观察选项 const config = { attributes: true, // 监听属性变化 attributeFilter: ['class'], // 仅监听 class 属性 subtree: true, // 监听父容器及其所有后代元素 }; // 启动观察,默认监听 document.body 或指定的父容器 observer.observe(parentElement || document.body, config); } }

    类似文章推荐 https://pipe.b3log.org/blogs/wilsons/articles/2025/05/13/1744703423359

    1 回复
    5 操作
    wilsons 在 2025-05-14 05:31:44 更新了该回帖
    wilsons 在 2025-04-16 09:29:39 更新了该回帖
    wilsons 在 2025-04-15 22:09:54 更新了该回帖
    wilsons 在 2025-04-15 15:53:51 更新了该回帖 wilsons 在 2025-04-15 13:28:24 更新了该回帖
    真不错,还顺便学会了用 pipe
    ACai 1
    @ACai 感谢打赏!我最近写了个思源文档直接发布到 pipe 的,目前仅单文档发布,后续可能增加批量和自动发布,如果有兴趣,好了 @ 你下。
    wilsons
    @wilsons 可以可以
    ACai
  • 其他回帖
  • EmptyLight 1

    我记得优化排版可以通过快捷键设置分配快捷键

  • lichlaughing via macOS

    厉害厉害,还有个问题就是,文档锁定的状态下该按钮也能发挥作用。能否让该排版按钮在锁定状态下隐藏(解锁文章显示)或者锁定状下失效(不可以点击)解锁状态下可以点击 😄

    1 回复
  • 已修改

    锁定状态下点击会提示不可用

    发布服务下不显示

  • 查看全部回帖

推荐标签 标签

  • WebSocket

    WebSocket 是 HTML5 中定义的一种新协议,它实现了浏览器与服务器之间的全双工通信(full-duplex)。

    48 引用 • 206 回帖 • 283 关注
  • WordPress

    WordPress 是一个使用 PHP 语言开发的博客平台,用户可以在支持 PHP 和 MySQL 数据库的服务器上架设自己的博客。也可以把 WordPress 当作一个内容管理系统(CMS)来使用。WordPress 是一个免费的开源项目,在 GNU 通用公共许可证(GPLv2)下授权发布。

    45 引用 • 114 回帖 • 180 关注
  • 分享

    有什么新发现就分享给大家吧!

    248 引用 • 1794 回帖 • 7 关注
  • 前端

    前端技术一般分为前端设计和前端开发,前端设计可以理解为网站的视觉设计,前端开发则是网站的前台代码实现,包括 HTML、CSS 以及 JavaScript 等。

    246 引用 • 1338 回帖
  • jsoup

    jsoup 是一款 Java 的 HTML 解析器,可直接解析某个 URL 地址、HTML 文本内容。它提供了一套非常省力的 API,可通过 DOM,CSS 以及类似于 jQuery 的操作方法来取出和操作数据。

    6 引用 • 1 回帖 • 487 关注
  • SSL

    SSL(Secure Sockets Layer 安全套接层),及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及数据完整性的一种安全协议。TLS 与 SSL 在传输层对网络连接进行加密。

    70 引用 • 193 回帖 • 415 关注
  • Outlook
    1 引用 • 5 回帖 • 3 关注
  • 开源

    Open Source, Open Mind, Open Sight, Open Future!

    411 引用 • 3588 回帖
  • 安装

    你若安好,便是晴天。

    132 引用 • 1184 回帖
  • 尊园地产

    昆明尊园房地产经纪有限公司,即:Kunming Zunyuan Property Agency Company Limited(简称“尊园地产”)于 2007 年 6 月开始筹备,2007 年 8 月 18 日正式成立,注册资本 200 万元,公司性质为股份经纪有限公司,主营业务为:代租、代售、代办产权过户、办理银行按揭、担保、抵押、评估等。

    1 引用 • 22 回帖 • 794 关注
  • WebComponents

    Web Components 是 W3C 定义的标准,它给了前端开发者扩展浏览器标签的能力,可以方便地定制可复用组件,更好的进行模块化开发,解放了前端开发者的生产力。

    1 引用 • 8 关注
  • uTools

    uTools 是一个极简、插件化、跨平台的现代桌面软件。通过自由选配丰富的插件,打造你得心应手的工具集合。

    7 引用 • 27 回帖
  • Mobi.css

    Mobi.css is a lightweight, flexible CSS framework that focus on mobile.

    1 引用 • 6 回帖 • 762 关注
  • Android

    Android 是一种以 Linux 为基础的开放源码操作系统,主要使用于便携设备。2005 年由 Google 收购注资,并拉拢多家制造商组成开放手机联盟开发改良,逐渐扩展到到平板电脑及其他领域上。

    336 引用 • 324 回帖
  • 微服务

    微服务架构是一种架构模式,它提倡将单一应用划分成一组小的服务。服务之间互相协调,互相配合,为用户提供最终价值。每个服务运行在独立的进程中。服务于服务之间才用轻量级的通信机制互相沟通。每个服务都围绕着具体业务构建,能够被独立的部署。

    96 引用 • 155 回帖 • 2 关注
  • GAE

    Google App Engine(GAE)是 Google 管理的数据中心中用于 WEB 应用程序的开发和托管的平台。2008 年 4 月 发布第一个测试版本。目前支持 Python、Java 和 Go 开发部署。全球已有数十万的开发者在其上开发了众多的应用。

    14 引用 • 42 回帖 • 818 关注
  • 阿里巴巴

    阿里巴巴网络技术有限公司(简称:阿里巴巴集团)是以曾担任英语教师的马云为首的 18 人,于 1999 年在中国杭州创立,他们相信互联网能够创造公平的竞争环境,让小企业通过创新与科技扩展业务,并在参与国内或全球市场竞争时处于更有利的位置。

    43 引用 • 221 回帖 • 56 关注
  • PWA

    PWA(Progressive Web App)是 Google 在 2015 年提出、2016 年 6 月开始推广的项目。它结合了一系列现代 Web 技术,在网页应用中实现和原生应用相近的用户体验。

    14 引用 • 69 回帖 • 183 关注
  • OnlyOffice
    4 引用 • 26 关注
  • 996
    13 引用 • 200 回帖 • 3 关注
  • 思源笔记

    思源笔记是一款隐私优先的个人知识管理系统,支持完全离线使用,同时也支持端到端加密同步。

    融合块、大纲和双向链接,重构你的思维。

    25764 引用 • 106649 回帖
  • 人工智能

    人工智能(Artificial Intelligence)是研究、开发用于模拟、延伸和扩展人的智能的理论、方法、技术及应用系统的一门技术科学。

    113 引用 • 315 回帖 • 1 关注
  • OpenResty

    OpenResty 是一个基于 NGINX 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

    17 引用 • 52 关注
  • Vditor

    Vditor 是一款浏览器端的 Markdown 编辑器,支持所见即所得、即时渲染(类似 Typora)和分屏预览模式。它使用 TypeScript 实现,支持原生 JavaScript、Vue、React 和 Angular。

    371 引用 • 1854 回帖 • 1 关注
  • Sym

    Sym 是一款用 Java 实现的现代化社区(论坛/BBS/社交网络/博客)系统平台。

    下一代的社区系统,为未来而构建

    524 引用 • 4601 回帖 • 709 关注
  • 运维

    互联网运维工作,以服务为中心,以稳定、安全、高效为三个基本点,确保公司的互联网业务能够 7×24 小时为用户提供高质量的服务。

    151 引用 • 257 回帖
  • LaTeX

    LaTeX(音译“拉泰赫”)是一种基于 ΤΕΧ 的排版系统,由美国计算机学家莱斯利·兰伯特(Leslie Lamport)在 20 世纪 80 年代初期开发,利用这种格式,即使使用者没有排版和程序设计的知识也可以充分发挥由 TeX 所提供的强大功能,能在几天,甚至几小时内生成很多具有书籍质量的印刷品。对于生成复杂表格和数学公式,这一点表现得尤为突出。因此它非常适用于生成高印刷质量的科技和数学类文档。

    12 引用 • 59 回帖 • 5 关注