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

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

Merged
merged 13 commits into from Jun 28, 2019
Merged

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

merged 13 commits into from Jun 28, 2019

Conversation

roottool
Copy link
Contributor

@roottool roottool commented May 8, 2019

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
Member

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

@roottool
Copy link
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

if (hashLink !== '' && isHeadingInMarkdownPreview && targetEl) {
const dataLine = targetEl.dataset.line
a.onclick = () => {
this.scrollTo(dataLine)
Copy link
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
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
@@ -1036,9 +1026,10 @@ export default class MarkdownPreview extends React.Component {

if (!href) return

const regexNoteInternalLink = /main.html#(.+)/
const extractId = /(main.html)*#/
Copy link
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
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
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
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.

Copy link
Member

@ZeroX-DG ZeroX-DG left a comment

Choose a reason for hiding this comment

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

LGTM πŸŽ‰

@ZeroX-DG
Copy link
Member

ZeroX-DG commented Jun 9, 2019

@roottool Can you resolve the conflict?

@roottool
Copy link
Contributor Author

roottool commented Jun 9, 2019

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
@Flexo013
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved πŸ‘ Pull request has been approved by sufficient reviewers. needs extra review πŸ”Ž Pull request requires review from an additional reviewer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants