-
Notifications
You must be signed in to change notification settings - Fork 132
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
Debug cannot import footnote from hash #2441
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2441 +/- ##
==========================================
+ Coverage 49.04% 51.22% +2.17%
==========================================
Files 124 124
Lines 5262 5281 +19
Branches 1118 1121 +3
==========================================
+ Hits 2581 2705 +124
+ Misses 2376 2290 -86
+ Partials 305 286 -19 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay, thanks for the tests!
The issue #2203 also raises the example of the footnote in reader facing features. However, this is not fixed by your PR (is it because the new line isn't there?)
Can you also fix this documentation bug to demonstrate that this feature works?
Thanks for the comment; should be fixed in this commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work @yiwen101!
This is a rather tricky bug to fix so appreciate the work.
I have some concerns about the ordering of the footnote. I understand you aren't trying to address the wrong ordering here but I think this might result in overlaps - not just an issue with wrong ordering. Could you explain why you change the footnote number and why the appended footnote item will has the number 1-1?
Thanks!
let toAppend = '<mb-temp-footnotes>'; | ||
matches.forEach((match) => { | ||
const href = match.match(hrefPattern)![1]; | ||
const replaceTo = `<a aria-describedby="footnote-label" href="#${href}">[${footnoteNumber}]`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it necessary to do this replace here? Why are you changing the number for the footnote?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Motivation being, as this initially is to fix the error in display footnote in the user doc, I decided to be defensive and do the best (without going beyond the scope and making changes outside the hash
part) to strive for making importing footnote from a single hash look good.
@@ -230,6 +230,24 @@ export function processInclude(node: MbNode, context: Context, pageSources: Page | |||
const $ = cheerio.load(actualContent); | |||
const actualContentOrNull = $(hash).html(); | |||
actualContent = actualContentOrNull || ''; | |||
if (actualContent !== '') { | |||
const footnotePattern = /<a aria-describedby="footnote-label" href="#fn-\d+-\d+">\[\d+\]/g; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh also small thing but i was wondering if using cheerio here makes more sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emm, but is not to use cheerio, we need the exact id (eg: #${href}.footnote-item
)? So we still need to pattern matching (and also to replace the index in the original content).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I get that cheerio will do the same thing but I think its cleaner to use cheerio to select out and append. In that case, we can use cheerio node to do the modifications below as well. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yucheng11122017
Thank you for the clarification; I have explored cheerio apis and made the requested changes. Following is a quick snapshot:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(console.log on last line was removed in later commits)
Thanks for the careful review. |
@kaixin-hc @yucheng11122017 The bahaviour of the master branch (after adding empty to enable the markdown:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @yiwen101 thanks for the work! Some more corrections
@@ -230,6 +230,24 @@ export function processInclude(node: MbNode, context: Context, pageSources: Page | |||
const $ = cheerio.load(actualContent); | |||
const actualContentOrNull = $(hash).html(); | |||
actualContent = actualContentOrNull || ''; | |||
if (actualContent !== '') { | |||
const footnotePattern = /<a aria-describedby="footnote-label" href="#fn-\d+-\d+">\[\d+\]/g; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I get that cheerio will do the same thing but I think its cleaner to use cheerio to select out and append. In that case, we can use cheerio node to do the modifications below as well. What do you think?
Co-authored-by: Chan Yu Cheng <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @yiwen101 thanks so much for cleaning up the code! I think using cheerio makes it more consistent with the rest of the code base. Just addition of one comment and I think this PR is ready to merge.
Thanks for the good work!
if (footnodeHrefs.length > 0) { | ||
const tempFootnotes = $('<mb-temp-footnotes></mb-temp-footnotes>'); | ||
footnodeHrefs.forEach((href) => { | ||
const listItem = $('<li></li>').attr('id', href.substring(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment to explain why we need to do a substring here? It is just to get rid of the hash in front right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the comment; has added the the latest commit
Co-authored-by: Chan Yu Cheng <[email protected]>
What is the purpose of this pull request?
Resolve #2203 (but #2430 still persists)
Overview of changes:
Anything you'd like to highlight/discuss:
Testing instructions:
Proposed commit message: (wrap lines at 72 characters)
Fix issue of cannot import footnote from hash
Checklist: ☑️
currently, when importing from hash, footnote is missing. For example, with
and
this is rendered
but we expect
This is fixed by using regular pattern to greedily extract and append the missing information.
Please note that #2430 still persists (the index of the imported footnotes may remain be conflicting). This PR only fixes only failure in importing footnote from hash, but did not touch the issue of wrong index.
Reviewer checklist:
Indicate the SEMVER impact of the PR:
At the end of the review, please label the PR with the appropriate label:
r.Major
,r.Minor
,r.Patch
.Breaking change release note preparation (if applicable):