-
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
Changes from 3 commits
22b9289
8b3cc6d
c7d4915
168dd4c
f285220
eecebc2
a68e82a
52c316d
1f9dce4
6a441b3
a65218a
e77a7bc
bd50434
1e8a14e
3146481
003eeb7
53e3147
1b9f432
db02850
9620126
54cc49f
72168e0
d555215
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div id="import"> | ||
|
||
text^[footnote1], text2^[footnote2] | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
const matchs = actualContent.match(footnotePattern); | ||
if (matchs) { | ||
yiwen101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const hrefPattern = /href="#(fn-\d+-\d+)"/; | ||
let footnoteNumber = 1; | ||
yiwen101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let toAppend = '<mb-temp-footnotes>'; | ||
matchs.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 commentThe 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 commentThe 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 commentThe 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 |
||
footnoteNumber += 1; | ||
actualContent = actualContent.replace(match, replaceTo); | ||
toAppend += `\n<li id="${href}" class="footnote-item">${$('#fn-1-1.footnote-item')!.html()}</li>`; | ||
yiwen101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
toAppend += '\n</mb-temp-footnotes>'; | ||
actualContent += toAppend; | ||
} | ||
} | ||
|
||
if (actualContentOrNull === null && !isOptional) { | ||
const error = new Error(`No such segment '${hash}' in file: ${actualFilePath}\n` | ||
|
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)