Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: markdown file inclusion support specify title #4382

Closed

Conversation

btea
Copy link
Contributor

@btea btea commented Nov 24, 2024

Description

Linked Issues

close #4375

Additional Context


Tip

The author of this PR can publish a preview release by commenting /publish below.

@github-actions github-actions bot added the stale label Dec 27, 2024
@btea
Copy link
Contributor Author

btea commented Feb 22, 2025

Could you please help review this PR? Thanks! @brc-dd

@brc-dd
Copy link
Member

brc-dd commented Feb 22, 2025

It's bit tricky than that.

  • Need to handle nesting.
  • Also, what should be done when same title is there many times?
  • /[^#]/g matches ^ or #, you probably meant to write /^#+/

@btea
Copy link
Contributor Author

btea commented Feb 22, 2025

  • Need to handle nesting.
  • Also, what should be done when same title is there many times?

Indeed, I thought too simply.

  • /[^#]/g matches ^ or #, you probably meant to write /^#+/

I reviewed it and there is no mistake here.

/[^#]/gmatches all characters except #. I intentionally remove all characters here to get the length of the title # and find the end of the content under the matching title.

@brc-dd
Copy link
Member

brc-dd commented Feb 22, 2025

Ah right, sorry. So, you're essentially counting number of # in a heading? But this will give prefix length for # hi # there = 2. Might be better to do str.match(/^#+/)?.[0]?.length

@btea
Copy link
Contributor Author

btea commented Feb 22, 2025

Yeah, you wrote it is better for the situation you mentioned. 👍

@btea
Copy link
Contributor Author

btea commented Feb 23, 2025

  • Need to handle nesting.

The interior looks to have handled the situation.

return processIncludes(srcDir, content, includePath, includes)

  • Also, what should be done when same title is there many times?

Generally speaking, a page should not have multiple identical titles. If this is the case, perhaps we can keep the current logic and give a warning message.

@brc-dd brc-dd removed the stale label Mar 2, 2025
brc-dd added a commit that referenced this pull request Mar 8, 2025
…nclusion

closes #4375
closes #4382

Co-authored-by: btea <2356281422@qq.com>
@brc-dd
Copy link
Member

brc-dd commented Mar 8, 2025

@btea Can you review the implementation in #4608? The main change is it using heading ids (the one you see in url fragments) instead of whole title.

It solves various cases where there are things like badges or markdown syntax in headings, or even duplicate heading (markdown-it-anchor internally adds -{counter} to repeated headings. I think repeated subheadings (inside separate parent headings) are quite common). It also prevents false positives like headings inside code blocks, etc. Though that's quite uncommon.

The md.parse step might add some performance overhead but I think markdown-it's parser is quite fast and the difference will be in order of few milliseconds, which is tolerable for the features it provides.

@brc-dd brc-dd closed this in b99d512 Mar 9, 2025
@brc-dd brc-dd closed this in #4608 Mar 9, 2025
@btea btea deleted the feat/file-inclusion-support-specify-title branch March 9, 2025 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants