有没有大佬能写一个类似 logseq 的层次子弹线 css 片段

本贴最后更新于 265 天前,其中的信息可能已经时移世异

如下图所示,之前好像看到有大佬实现了,但是必须使用对应的主题,有咩有对应的 css 片段能够实现呢,之前还看到 obsidion 社区他们那边也在求,这个其实还是挺好用的

image.png

  • 思源笔记

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

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

    19139 引用 • 71957 回帖
  • Q&A

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

    6678 引用 • 29949 回帖 • 242 关注

相关帖子

被采纳的回答
  • mdzz2048 6 1 赞同

    css 片段

    /* REF https://github.com/svchord/Rem-Craft */
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.protyle-action{
        color:rgb(70, 110, 220);;
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.protyle-action svg{
        margin:0;
        width:16px;
        height:16px;
        padding:0px 0px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.list:has(.block-focus)>.li::after{
        content:"";
        display:block;
        position:absolute;
        pointer-events:none;
        width:34px;
        left:-18px;
        top:-20px;
        border-style:solid;
        border-color:rgb(70, 110, 220);;
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.list:has(.block-focus)>.li:not(:has(.block-focus))::after{
        bottom:-2px;
        border-width:0 0 0 2px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.list:has(.block-focus)>.li:has(.block-focus)::after{
        height:38px;
        border-radius:0 0 0 8px;
        border-width:0 0 2px 2px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.list:has(.block-focus)>.li:has(.block-focus)~.li:not(:has(.block-focus))::after{
        border-color:rgba(0,0,0,0)
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.list:has(.block-focus)>.li[data-subtype=o]::after{
        width:24px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.list:has(.block-focus)>.li[data-subtype=t]::after{
        width:28px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id]::after{
        content:"";
        display:block;
        position:absolute;
        pointer-events:none;
        width:34px;
        left:-18px;
        top:-20px;
        border-style:solid;
        border-color:rgb(70, 110, 220);
        top:20px;
        height:calc(100% + 4px);
        border-width:0 0 0 2px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id]:has(+.list)::after{
        height:auto;
        bottom:0
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id][data-type=NodeHeading]::after{
        top:0;
        height:185%
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id].list:has(.block-focus)::after,.protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id].list:has(.block-focus)~[data-node-id]::after,.protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id].bq:has(.block-focus)::after,.protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id].bq:has(.block-focus)~[data-node-id]::after,.protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id].sb:has(.block-focus)::after,.protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id].sb:has(.block-focus)~[data-node-id]::after{
        border-color:rgba(0,0,0,0)
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[fold="1"]>[data-node-id]::after,.protyle-wysiwyg [data-node-id].li:has(.block-focus):has(>.block-focus)>[data-node-id]::after{
        border-color:rgba(0,0,0,0)
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=o]:has(.block-focus)>.list:has(.block-focus)>.li::after{
        top:-10px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=o]:has(.block-focus)>.list:has(.block-focus)>.li:has(.block-focus)::after{
        height:28px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=t]:has(.block-focus)>.protyle-action{
        color:rgb(70, 110, 220);;
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=t]:has(.block-focus)>.protyle-action svg{
        margin:0;
        width:14px;
        height:14px;
        padding:0px 0px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=t]:has(.block-focus)>.list:has(.block-focus)>.li::after{
        top:-14px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=t]:has(.block-focus)>.list:has(.block-focus)>.li:has(.block-focus)::after{
        height:32px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=t]:has(.block-focus).protyle-task--done>.list:has(.block-focus)>.li::after{
        border-color:rgba(139, 139, 139)
    }
    

欢迎来到这里!

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

注册 关于
请输入回帖内容 ...
  • timyhh

    可以做到如下图這樣嗎?

    zettelsequence0dd0058588689778eb82a0cbbc5cade6.png

    亦即:1 -> 1a -> 1a1

    如果到做到這樣更好:1 -> 1.1 ->1.1.1

    可以嗎?

  • 其他回帖
  • py 1 评论

    你好,只把 CSS 片段复制就可以么,还是说 JS 片段也需要做什么操作呢?

    分别把 CSS 代码、JS 代码放在 设置——外观——代码片段中。两个都要放。注意代码片段功能中 CSS 和 JS 代码需要切换一下。
    5Z4Uo6oGvKPB7o 1 赞同
  • mdzz2048 6 1 赞同

    css 片段

    /* REF https://github.com/svchord/Rem-Craft */
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.protyle-action{
        color:rgb(70, 110, 220);;
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.protyle-action svg{
        margin:0;
        width:16px;
        height:16px;
        padding:0px 0px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.list:has(.block-focus)>.li::after{
        content:"";
        display:block;
        position:absolute;
        pointer-events:none;
        width:34px;
        left:-18px;
        top:-20px;
        border-style:solid;
        border-color:rgb(70, 110, 220);;
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.list:has(.block-focus)>.li:not(:has(.block-focus))::after{
        bottom:-2px;
        border-width:0 0 0 2px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.list:has(.block-focus)>.li:has(.block-focus)::after{
        height:38px;
        border-radius:0 0 0 8px;
        border-width:0 0 2px 2px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.list:has(.block-focus)>.li:has(.block-focus)~.li:not(:has(.block-focus))::after{
        border-color:rgba(0,0,0,0)
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.list:has(.block-focus)>.li[data-subtype=o]::after{
        width:24px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>.list:has(.block-focus)>.li[data-subtype=t]::after{
        width:28px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id]::after{
        content:"";
        display:block;
        position:absolute;
        pointer-events:none;
        width:34px;
        left:-18px;
        top:-20px;
        border-style:solid;
        border-color:rgb(70, 110, 220);
        top:20px;
        height:calc(100% + 4px);
        border-width:0 0 0 2px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id]:has(+.list)::after{
        height:auto;
        bottom:0
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id][data-type=NodeHeading]::after{
        top:0;
        height:185%
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id].list:has(.block-focus)::after,.protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id].list:has(.block-focus)~[data-node-id]::after,.protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id].bq:has(.block-focus)::after,.protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id].bq:has(.block-focus)~[data-node-id]::after,.protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id].sb:has(.block-focus)::after,.protyle-wysiwyg [data-node-id].li:has(.block-focus)>[data-node-id].sb:has(.block-focus)~[data-node-id]::after{
        border-color:rgba(0,0,0,0)
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[fold="1"]>[data-node-id]::after,.protyle-wysiwyg [data-node-id].li:has(.block-focus):has(>.block-focus)>[data-node-id]::after{
        border-color:rgba(0,0,0,0)
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=o]:has(.block-focus)>.list:has(.block-focus)>.li::after{
        top:-10px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=o]:has(.block-focus)>.list:has(.block-focus)>.li:has(.block-focus)::after{
        height:28px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=t]:has(.block-focus)>.protyle-action{
        color:rgb(70, 110, 220);;
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=t]:has(.block-focus)>.protyle-action svg{
        margin:0;
        width:14px;
        height:14px;
        padding:0px 0px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=t]:has(.block-focus)>.list:has(.block-focus)>.li::after{
        top:-14px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=t]:has(.block-focus)>.list:has(.block-focus)>.li:has(.block-focus)::after{
        height:32px
    }
    .protyle-wysiwyg [data-node-id].li:has(.block-focus)[data-subtype=t]:has(.block-focus).protyle-task--done>.list:has(.block-focus)>.li::after{
        border-color:rgba(139, 139, 139)
    }
    
    1 回复
  • JS 片段我用 AI 优化了下,新代码滚动页面的延迟降低,并且没有 100ms 的显示延迟了。

    // 缓存编辑器块并处理聚焦状态的函数定义
    let cachedEditorBlocks = []; // 缓存所有编辑器块
    let focusedBlock = null; // 缓存当前聚焦的块
    
    // 初始化缓存
    function initEditorBlocksCache() {
        const editors = document.querySelectorAll('.protyle-wysiwyg');
        editors.forEach(editor => {
            if (!editor.classList.contains('NodeAttributeView')) {
                cachedEditorBlocks.push(...editor.querySelectorAll('[data-node-id]'));
            }
        });
    }
    
    // 更新聚焦状态并维护缓存
    function handleBlockFocus(e) {
        let target;
        if (e.type === 'mouseup') {
            // 鼠标事件,查找最近的具有data-node-id属性的元素
            target = e.target.closest('[data-node-id]');
        } else if (e.type === 'keyup') {
            // 键盘事件,查找当前焦点所在的具有data-node-id属性的元素
            const activeElement = document.activeElement;
            if (activeElement.classList.contains('protyle-wysiwyg')) {
                target = window.getSelection()?.focusNode?.parentElement;
                while (target && !target.dataset.nodeId) {
                    target = target.parentElement;
                    if (!target) break; // 避免空指针异常
                    if (target.classList.contains('NodeAttributeView')) {
                        target = null; // 如果找到NodeAttributeView,则不处理该元素
                        break;
                    }
                }
            }
        }
    
        if (!target || target === focusedBlock) return;
    
        if (focusedBlock) {
            focusedBlock.classList.remove('block-focus');
        }
        focusedBlock = target;
        focusedBlock.classList.add('block-focus');
    
        // 根据需要调用相关功能,例如:
        // setSelector(focusedBlock);
    }
    
    // 初始化编辑器块缓存
    initEditorBlocksCache();
    
    // 绑定事件监听器
    document.addEventListener('mouseup', handleBlockFocus, true);
    document.addEventListener('keyup', handleBlockFocus, true);
    
    // 立即调用的异步函数表达式,执行handleBlockFocus并输出日志
    (async () => {
        // 这里我们调用handleBlockFocus函数,但由于它不返回Promise,所以不需要await
        handleBlockFocus({ type: 'dummy' }); // 模拟事件调用
        console.log('加载子弹线成功');
    })();
    
    1 操作
    5kyfkr 在 2024-05-11 21:29:55 更新了该回帖
  • 查看全部回帖

推荐标签 标签

  • Logseq

    Logseq 是一个隐私优先、开源的知识库工具。

    Logseq is a joyful, open-source outliner that works on top of local plain-text Markdown and Org-mode files. Use it to write, organize and share your thoughts, keep your to-do list, and build your own digital garden.

    4 引用 • 55 回帖 • 10 关注
  • 资讯

    资讯是用户因为及时地获得它并利用它而能够在相对短的时间内给自己带来价值的信息,资讯有时效性和地域性。

    53 引用 • 85 回帖 • 1 关注
  • 互联网

    互联网(Internet),又称网际网络,或音译因特网、英特网。互联网始于 1969 年美国的阿帕网,是网络与网络之间所串连成的庞大网络,这些网络以一组通用的协议相连,形成逻辑上的单一巨大国际网络。

    96 引用 • 330 回帖
  • 倾城之链
    23 引用 • 66 回帖 • 110 关注
  • Solo

    Solo 是一款小而美的开源博客系统,专为程序员设计。Solo 有着非常活跃的社区,可将文章作为帖子推送到社区,来自社区的回帖将作为博客评论进行联动(具体细节请浏览 B3log 构思 - 分布式社区网络)。

    这是一种全新的网络社区体验,让热爱记录和分享的你不再感到孤单!

    1425 引用 • 10043 回帖 • 474 关注
  • 京东

    京东是中国最大的自营式电商企业,2015 年第一季度在中国自营式 B2C 电商市场的占有率为 56.3%。2014 年 5 月,京东在美国纳斯达克证券交易所正式挂牌上市(股票代码:JD),是中国第一个成功赴美上市的大型综合型电商平台,与腾讯、百度等中国互联网巨头共同跻身全球前十大互联网公司排行榜。

    14 引用 • 102 回帖 • 405 关注
  • 新人

    让我们欢迎这对新人。哦,不好意思说错了,让我们欢迎这位新人!
    新手上路,请谨慎驾驶!

    51 引用 • 226 回帖 • 1 关注
  • 设计模式

    设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用。设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是众多软件开发人员经过相当长的一段时间的试验和错误总结出来的。

    198 引用 • 120 回帖
  • 数据库

    据说 99% 的性能瓶颈都在数据库。

    330 引用 • 614 回帖
  • Sym

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

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

    523 引用 • 4581 回帖 • 693 关注
  • gRpc
    10 引用 • 8 回帖 • 52 关注
  • Node.js

    Node.js 是一个基于 Chrome JavaScript 运行时建立的平台, 用于方便地搭建响应速度快、易于扩展的网络应用。Node.js 使用事件驱动, 非阻塞 I/O 模型而得以轻量和高效。

    138 引用 • 268 回帖 • 184 关注
  • CodeMirror
    1 引用 • 2 回帖 • 121 关注
  • 导航

    各种网址链接、内容导航。

    37 引用 • 168 回帖 • 2 关注
  • 面试

    面试造航母,上班拧螺丝。多面试,少加班。

    324 引用 • 1395 回帖
  • OpenShift

    红帽提供的 PaaS 云,支持多种编程语言,为开发人员提供了更为灵活的框架、存储选择。

    14 引用 • 20 回帖 • 606 关注
  • Electron

    Electron 基于 Chromium 和 Node.js,让你可以使用 HTML、CSS 和 JavaScript 构建应用。它是一个由 GitHub 及众多贡献者组成的活跃社区共同维护的开源项目,兼容 Mac、Windows 和 Linux,它构建的应用可在这三个操作系统上面运行。

    15 引用 • 136 回帖 • 2 关注
  • Typecho

    Typecho 是一款博客程序,它在 GPLv2 许可证下发行,基于 PHP 构建,可以运行在各种平台上,支持多种数据库(MySQL、PostgreSQL、SQLite)。

    12 引用 • 60 回帖 • 466 关注
  • ReactiveX

    ReactiveX 是一个专注于异步编程与控制可观察数据(或者事件)流的 API。它组合了观察者模式,迭代器模式和函数式编程的优秀思想。

    1 引用 • 2 回帖 • 124 关注
  • Mac

    Mac 是苹果公司自 1984 年起以“Macintosh”开始开发的个人消费型计算机,如:iMac、Mac mini、Macbook Air、Macbook Pro、Macbook、Mac Pro 等计算机。

    164 引用 • 594 回帖
  • C++

    C++ 是在 C 语言的基础上开发的一种通用编程语言,应用广泛。C++ 支持多种编程范式,面向对象编程、泛型编程和过程化编程。

    106 引用 • 152 回帖 • 2 关注
  • Hexo

    Hexo 是一款快速、简洁且高效的博客框架,使用 Node.js 编写。

    21 引用 • 140 回帖 • 29 关注
  • 自由行
    4 关注
  • Vue.js

    Vue.js(读音 /vju ː/,类似于 view)是一个构建数据驱动的 Web 界面库。Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件。

    261 引用 • 662 回帖 • 1 关注
  • danl
    76 关注
  • Linux

    Linux 是一套免费使用和自由传播的类 Unix 操作系统,是一个基于 POSIX 和 Unix 的多用户、多任务、支持多线程和多 CPU 的操作系统。它能运行主要的 Unix 工具软件、应用程序和网络协议,并支持 32 位和 64 位硬件。Linux 继承了 Unix 以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统。

    918 引用 • 931 回帖
  • OkHttp

    OkHttp 是一款 HTTP & HTTP/2 客户端库,专为 Android 和 Java 应用打造。

    16 引用 • 6 回帖 • 52 关注