sethyuan / logseq-plugin-tocgen

Generate a TOC of any page anywhere to quickly access the page's content.
MIT License
144 stars 10 forks source link

fix: manually remove collapsed property. #4

Closed jjaychen1e closed 2 years ago

jjaychen1e commented 2 years ago

When a block is collapsed, the TOC will be incomplete. Here is the explanation:

It could be a bug of Logseq. Other properties I observed all begin with a white space.

When a block is collapsed, the "collapsed" properly doesn't begin with a white space, for example, a collapsed block with content "somewords" could be: "somewordscollapsed:: true". In this case, "somewordscollapsed:: true" will entirely be replaced with empty string.

jjaychen1e commented 2 years ago

And, although other properties begin with a white space, but it seems "\b[^:]+:: [^\n]+" will match all content. If this is also confirmed as a bug, another PR is needed.

image
sethyuan commented 2 years ago

我在我的Logseq上测试了一下,没有发现collapsed是紧挨着内容的情况,都是另起一行的。你用的是什么版本的Logseq?在什么操作系统上?

jjaychen1e commented 2 years ago

我在我的Logseq上测试了一下,没有发现collapsed是紧挨着内容的情况,都是另起一行的。你用的是什么版本的Logseq?在什么操作系统上?

Logseq 0.5.6, macOS

image
jjaychen1e commented 2 years ago

And it works well if there are only Chinese characters because "\b" won't match Chinese characters.

sethyuan commented 2 years ago

I reproduced the issue, it's the regular expression that handles the properties that is not working properly, I fixed the problem and released a new version, please give it try.

jjaychen1e commented 2 years ago

I reproduced the issue, it's the regular expression that handles the properties that is not working properly, I fixed the problem and released a new version, please give it try.

It doesn't fix my problem in my test. And I create another commit, hiding the arrow if there is no sub "h" child block in "h" mode.

sethyuan commented 2 years ago

Can you send me a snippet of your markdown? It helps me track down the problem. BTW, I’ll take a look of the PR tomorrow.

在 2022年1月3日,21:17,JJAYCHEN @.***> 写道:

 I reproduced the issue, it's the regular expression that handles the properties that is not working properly, I fixed the problem and released a new version, please give it try.

It doesn't fix my problem in my test. And I create another commit, hiding the arrow if there is no sub "h" child block in "h" mode.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.

jjaychen1e commented 2 years ago

Can you send me a snippet of your markdown? It helps me track down the problem. BTW, I’ll take a look of the PR tomorrow. 在 2022年1月3日,21:17,JJAYCHEN @.***> 写道:  I reproduced the issue, it's the regular expression that handles the properties that is not working properly, I fixed the problem and released a new version, please give it try. It doesn't fix my problem in my test. And I create another commit, hiding the arrow if there is no sub "h" child block in "h" mode. — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.

Thanks. Here is a test markdown snippet:

- {{renderer(:tocgen,[[TOC Test]])}}
- # Title
    - ## English Subtitle
        - something...
    - ## 中文标题
        - 内容
    - ## English + 中文标题
        - something

This snippet is placed in a page named "TOC Test", and tocgen is configured in "h" mode. And here is a recorded video:

https://user-images.githubusercontent.com/31304335/147941354-b7da0cc5-5d5d-4a8b-aa5b-bf30d8668e2a.mov

sethyuan commented 2 years ago

Thanks for contributing! I integrated your code and made some refactorings. It should be now fix your issues.

jjaychen1e commented 2 years ago

Thanks for contributing! I integrated your code and made some refactorings. It should be now fix your issues.

Thanks for reply. In my test, the newest version still shows collapse arrow even there are no more sub "h" blocks in "h" mode, if I set the default value of collapse property to false: https://github.com/sethyuan/logseq-plugin-tocgen/blob/0a8b9ecf1ddc00dfd754ba861d6e5842a6b1075e/public/comps/Block.jsx#L33

jjaychen1e commented 2 years ago

Thanks for contributing! I integrated your code and made some refactorings. It should be now fix your issues.

Thanks for reply. In my test, the newest version still shows collapse arrow even there are no more sub "h" blocks in "h" mode, if I set the default value of collapse property to false:

https://github.com/sethyuan/logseq-plugin-tocgen/blob/0a8b9ecf1ddc00dfd754ba861d6e5842a6b1075e/public/comps/Block.jsx#L33

Maybe we can control this in a separate "opacity" CSS style?

jjaychen1e commented 2 years ago

And this doesn't work: https://github.com/sethyuan/logseq-plugin-tocgen/blob/f3f28a596f0e8aea4c5c30cde6f7860fb6ed8168/public/marked-renderer.js#L43

And I try to put htmlDecode(text) into: https://github.com/sethyuan/logseq-plugin-tocgen/blob/f3f28a596f0e8aea4c5c30cde6f7860fb6ed8168/public/marked-renderer.js#L38 It works.

sethyuan commented 2 years ago

@JJAYCHEN1e The collapse behavior is intentional. It's there to make level indentation more apparent.

As for htmlDecode, I should've placed it for text instead of paragraph, that would cover both heading and paragraph cases. I released a new version with this patch.