docsify icon indicating copy to clipboard operation
docsify copied to clipboard

Title in block quotes are displayed in the sidebar

Open noraj opened this issue 1 year ago • 8 comments

Bug Report

Steps to reproduce

Put a markdown title in a quote.

What is current behaviour

Title inside Block quotes are rendered to the sidebar menu.

image

What is the expected behaviour

Title inside Block quotes should not be listed in the sidebar.

Other relevant information

  • [x] Bug does still occur when all/other plugins are disabled?

  • Your OS: ArchLinux

  • Node.js version: 19.3.0

  • npm/yarn version: N/A

  • Browser version: 19.3.0

  • Docsify version: 4.13.0

  • Docsify plugins: N/A

Please create a reproducible sandbox

Edit smoosh-wood-iv8fgb

Mention the docsify version in which this bug was not present (if any)

None

noraj avatar Dec 29 '22 11:12 noraj

Hi @noraj , you can use <!-- {docsify-ignore} --> to mark those headers which you do not wanna show on sidebar. refer doc here Ignoring Subheaders .

Koooooo-7 avatar Jan 03 '23 16:01 Koooooo-7

<!-- {docsify-ignore} --> is ok as a temporary workaround, be one doesn't want to add this extra directive for each title in each block quote.

noraj avatar Jan 03 '23 21:01 noraj

<!-- {docsify-ignore} --> is ok as a temporary workaround, be one doesn't want to add this extra directive for each title in each block quote.

Now, we treat those contents which are marked as title (## H2) to sidebar since it's based on markdown syntax. If u have lots of cases like this, I suppose you could write a hook/plugin to rewrite those titles with ignore tags instead.

Koooooo-7 avatar Jan 04 '23 05:01 Koooooo-7

If you need to use bold, you can use **, I feel that few people use the title in the quote

sy-records avatar Jan 04 '23 05:01 sy-records

Now, we treat those contents which are marked as title (## H2) to sidebar since it's based on markdown syntax. If u have lots of cases like this, I suppose you could write a hook/plugin to rewrite those titles with ignore tags instead.

Those are not ## H2 but content (that happens to be a ## H2) in a blockquote. I mean I use many SSG (static site generator) that are using different markdown parser with some of them that are commonmark compliant and some others don't, some SSG are also using ToC (table of content) helper etc. and none oh them has this behavior. In all SSG when a ToC is generated for example, only true root title are used not the title in the blockquotes because precisely they are not part of the document but rather a quote from a third party document.

But I can see the markdown parser used here is marked but in a pretty old version (1.2.9 while the last is 4.2.5)

https://github.com/docsifyjs/docsify/blob/a8f9fc1d5f5c7808efe65e5ca9359f38014b1bcd/package.json#L68

so maybe things have changed since then?

Or this is maybe due to the fact that marked is not a true parser that parse the syntax but rather use regexp to do so and so is not aware of the context (cf. https://github.com/markedjs/marked/blob/master/src/rules.js and https://github.com/markedjs/marked/issues/1549).

If this is due to the broken way of marked to parser markdown I would then suggest to move to a more robust, true parser and commonmark compliant parser like https://github.com/markdown-it/markdown-it or https://github.com/commonmark/commonmark.js.

If you need to use bold, you can use **, I feel that few people use the title in the quote

The point of a blockquote is to copy a content and paste it as it, since it's a quote you don't rewrite the 3rd party content. So changing all title to bold just because the sidebar as a bug is not a solution.

noraj avatar Jan 04 '23 09:01 noraj

Hi @noraj . Although the content in blockquote ideally should not be a title in an article , the point is the > ## h2 acts as a title item indeed when the parser compiles it. i.e.

In here parser by github. e.g

> ## h2

h2

## h2

h2

We can see the blockquote one is same to ## h2 with the bigger font size like a title.

And about the parser such as markdown-it, it is the same behavior on the test site.

image

Generally we should follow the common markdown parser behavior and we can and have exposed hooks and other ways to let user have access to handle it if needs to, otherwise docsify should create its own parser to refine the whole content beyond the markdown syntax (such as filter those specific blockquote and move out of the title scope which should similar to user's custom plugin/script). So I recommend to let user custom hooks/handle it when they have those kinds of needs instead.

Maybe it gonna be enhanced into docsify when the blockquote title and other cases of sidebar more common in future.

Koooooo-7 avatar Jan 04 '23 15:01 Koooooo-7

Yeah of course h2 in blockquotes are rendered as h2 and are see by the user user as h2 (in a blockquote). I don't think there is any need of a custom parser.

## h2

> ## h2

Produces:

<h2>h2</h2>
<blockquote>
<h2>h2</h2>
</blockquote>

h2 in blockquotes would be rendered as is (untouched) in the page but it's just that the content of <blockquote> should be ignored for things such as sidebars, tables of contents, etc.

For example Hexo SSG use Marked as default renderer but is also compatible with markdown-it. It's as a toc helper. Their toc helper will ignore titles in blockquotes. Here is the code of the toc helper https://github.com/hexojs/hexo/blob/master/lib/plugins/helper/toc.js. The toc helper uses a tocObj defined in hexo-util here: https://github.com/hexojs/hexo-util/blob/master/lib/toc_obj.ts#L31-L70.

Maybe this is a good example and this can help.

noraj avatar Jan 04 '23 21:01 noraj

Hi @noraj , yep. I agree that docsify should handle some general cases of sidebar. For current case the blockquote with title marks, as I mentioned, docsify treats all the title ducks type into sidebar, maybe it is not friendly to users in some cases ( they may need enhancements). and instead, we provide many flexible ways to allow users to custom and handle some cases which are out current docsify scope.

FYI, the solution that I recommend to handle this case with hook below. About the time when docsify gonna handle this case by itself I m sorry that I can not say an exact time for now.

        hook.beforeEach((markdown) => 
           markdown.replace(/(\s{0,3}> #+.*)/g, '$1 {docsify-ignore} ')
        );

Koooooo-7 avatar Jan 05 '23 07:01 Koooooo-7