Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

Fixes that TOC hasn't id attribute when the title is all 2-byte characters#2994

Merged
Rokt33r merged 13 commits into
BoostIO:masterfrom
roottool:fix#2920
Jun 28, 2019
Merged

Fixes that TOC hasn't id attribute when the title is all 2-byte characters#2994
Rokt33r merged 13 commits into
BoostIO:masterfrom
roottool:fix#2920

Conversation

@roottool

@roottool roottool commented May 8, 2019

Copy link
Copy Markdown
Contributor

Description

This PR fixes that TOC hasn't id attribute when the title is all 2-byte characters.
I referred to browser/lib/slugify.js in 4f9b374 and a logic of Slug in Visual Studio Code.

According to RFC3986, the underscore can be used in URI.

unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"

So, I don't replace the underscore.

"." and "~" is used by file path.
e.g. ~/example.js
I think that the file path which is written in href of <a> is a security risk.
Therefore, I exclude "." and "~".

Screenshot

FixedSlug

Issue fixed

#2920

Type of changes

  • 🔘 Bug fix (Change that fixed an issue)
  • ⚪ Breaking change (Change that can cause existing functionality to change)
  • ⚪ Improvement (Change that improves the code. Maybe performance or development improvement)
  • ⚪ Feature (Change that adds new functionality)
  • ⚪ Documentation change (Change that modifies documentation. Maybe typo fixes)

Checklist:

  • 🔘 My code follows the project code style
  • 🔘 I have written test for my code and it has been tested
  • 🔘 All existing tests have been passed
  • 🔘 I have attached a screenshot/video to visualize my change if possible

IssueHunt Summary

Referenced issues

This pull request has been submitted to:


IssueHunt has been backed by the following sponsors. Become a sponsor

@ZeroX-DG ZeroX-DG added the awaiting review ❇️ Pull request is awaiting a review. label May 10, 2019
@ZeroX-DG

Copy link
Copy Markdown
Member

The TOC is broken, can you fix it? It tries to open the TOC link as an attachment I guess.

@roottool

Copy link
Copy Markdown
Contributor Author

href
A URL fragment is a name preceded by a hash mark (#), which specifies an internal target location (an id of an HTML element) within the current document.
<a>: The Anchor element

When the anchor element in <iframe> was clicked, it can't jump the heading in <iframe> which is created by script.
Because the heading element doesn't exist in current HTML file.
e.g.
href

Therefore, I added onclick to the ancher element that the hash link exists in href.
jumpToHeading

Comment thread browser/components/MarkdownPreview.js Outdated
if (hashLink !== '' && isHeadingInMarkdownPreview && targetEl) {
const dataLine = targetEl.dataset.line
a.onclick = () => {
this.scrollTo(dataLine)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this code into this function? Because we already have an existing link click listener.
https://github.com/BoostIO/Boostnote/blob/9a6ee9d2ef2d853b623d386c928088356ba4dbce/browser/components/MarkdownPreview.js#L1014-L1024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood. I fixed it.

Since the link hash this time did not match the regular expression, the regular expression has been changed.
https://github.com/BoostIO/Boostnote/blob/857367efba4312b842b5ece6fd5e6912702090ff/browser/components/MarkdownPreview.js#L1029-L1030
e.g.
FixRegExp

@ZeroX-DG ZeroX-DG added awaiting changes 🖊️ Pull request has been reviewed, but contributor needs to make changes. and removed awaiting review ❇️ Pull request is awaiting a review. labels May 11, 2019
Comment thread browser/components/MarkdownPreview.js Outdated
if (!href) return

const regexNoteInternalLink = /main.html#(.+)/
const extractId = /(main.html)*#/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be /(main.html)?#/ ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think I need this line.
First, the id of the target element don't have a hash.
e.g.
FixedSlug
Therefore, I had to remove a hash in linkHash.

Second, the past regexNoteInternalLink didn't match linkHash.
linkHash doesn't include main.html.
e.g.
FixRegExp
So, I had to change the regex rule.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that, it's just I want to replace the regex from (main.html)*# to (main.html)?#. But I think it doesn't matter 😄 We can go by your way then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry. I misunderstood that this line was not necessary.
Thank you for a suggestion. I think (main.html)?# is better than (main.html)*# too.

@ZeroX-DG ZeroX-DG left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@ZeroX-DG

ZeroX-DG commented Jun 9, 2019

Copy link
Copy Markdown
Member

@roottool Can you resolve the conflict?

@roottool

roottool commented Jun 9, 2019

Copy link
Copy Markdown
Contributor Author

I solved the conflict by adopting the master branch code.
FYI: #2990 (comment) and #2990 (comment)

Because I don't want to change the code of the current master branch.
Operation check result is like the following gif.

Screenshot

AdjustedMasterBranch

@ZeroX-DG ZeroX-DG added approved 👍 Pull request has been approved by sufficient reviewers. needs extra review 🔎 Pull request requires review from an additional reviewer. and removed awaiting changes 🖊️ Pull request has been reviewed, but contributor needs to make changes. labels Jun 27, 2019
@ZeroX-DG ZeroX-DG requested a review from Rokt33r June 27, 2019 11:28
@Rokt33r Rokt33r merged commit 6736a08 into BoostIO:master Jun 28, 2019
@Rokt33r Rokt33r added this to the v0.12.0 milestone Jun 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

approved 👍 Pull request has been approved by sufficient reviewers. needs extra review 🔎 Pull request requires review from an additional reviewer.

4 participants