Implement fix for footnote links (PR 1666 by steka)
This commit is contained in:
@@ -956,16 +956,32 @@ void XMLCALL ChapterHtmlSlimParser::characterData(void* userData, const XML_Char
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Collect footnote link display text (for the number label)
|
// Collect footnote link display text (for the number label)
|
||||||
// Skip whitespace and brackets to normalize noterefs like "[1]" → "1"
|
// Remove leading/trailing whitespace and square brackets from the
|
||||||
|
// footnote link text to normalize noterefs like "[1]" → "1"
|
||||||
if (self->insideFootnoteLink) {
|
if (self->insideFootnoteLink) {
|
||||||
for (int i = 0; i < len; i++) {
|
int start = 0;
|
||||||
unsigned char c = static_cast<unsigned char>(s[i]);
|
int end = len - 1;
|
||||||
if (isWhitespace(c) || c == '[' || c == ']') continue;
|
|
||||||
if (self->currentFootnoteLinkTextLen < static_cast<int>(sizeof(self->currentFootnoteLinkText)) - 1) {
|
// Example input and output texts:
|
||||||
self->currentFootnoteLinkText[self->currentFootnoteLinkTextLen++] = c;
|
// " [ 12 ] " => "12"
|
||||||
self->currentFootnoteLinkText[self->currentFootnoteLinkTextLen] = '\0';
|
// " turn to 256 " => "turn to 256"
|
||||||
}
|
|
||||||
|
// Ignore leading whitespaces and left square brackets
|
||||||
|
while (start < len && (isWhitespace(s[start]) || (s[start] == '['))) {
|
||||||
|
++start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore trailing whitespaces and right square brackets
|
||||||
|
while (end >= start && (isWhitespace(s[end]) || (s[end] == ']'))) {
|
||||||
|
--end;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract footnote link text
|
||||||
|
for (int i = start; (self->currentFootnoteLinkTextLen < sizeof(self->currentFootnoteLinkText) - 1) && (i <= end);
|
||||||
|
++i) {
|
||||||
|
self->currentFootnoteLinkText[self->currentFootnoteLinkTextLen++] = s[i];
|
||||||
|
}
|
||||||
|
self->currentFootnoteLinkText[self->currentFootnoteLinkTextLen] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user