0) {
$fntext = array_filter($fntext, function ($fn) { return ($fn != '#'); });
ksort($fntext);
/* Blue line if ‘#’; no line if ‘@’.
(Setting $FootnoteBlockStartLine to false disables blue line
even for ‘#’.)
*/
$footnotes_class = 'footnotes'
. ($FootnoteBlockStartLine && $fn_str == "#"
? ' footnotes-with-start-line'
: '');
$out = "
\n";
} else {
/* If we’re here, then a [^#^] or [^@^] has been encountered before
any footnotes have been defined. We ignore it.
*/
$out = '';
}
/* Clear all defined footnotes, reset footnote numbering, and increment
footnote group number.
*/
$fntext = [ ];
$fncount = 0;
$fngroup++;
} else {
/* This branch of the conditional means that we’re processing a
footnote reference and/or definition. (Note that no footnotes will
ever be printed unless we take the other branch at some point.)
*/
$fncount++;
/* If there’s a footnote number specified explicitly, then set the
number of the current footnote to that number.
If there is, additionally, footnote text provided with the number,
then set the footnote text to that (i.e., chop off the number
prefix). (If there’s only a number and no text, then this is either
a reference to a numbered footnote previously defined inline, OR a
reference to a numbered footnote that will later be defined
non-inline).
*/
if (preg_match('/^#([0-9]+)(\s+(.+))?$/s', $fn_str, $fn_str_parts)) {
$fncount = $fn_str_parts[1];
$fn_str = (isset($fn_str_parts[2]) ? $fn_str_parts[2] : '');
}
/* The CSS ‘id’ attributes of both the in-text footnote link and the
footnote block itself include the footnote group and number.
*/
$fnid = $fngroup . '_' . $fncount;
/* If there’s footnote text provided, AND a footnote number is given,
AND the footnote of that number has been previously referenced, then
output nothing (as this must therefore be a non-inline footnote
definition). Otherwise, output the footnote link (as this must be
a numbered footnote use without an inline definition; or the first
use of a numbered footnote with an an inline definition; or a
non-numbered, inline-defined footnote).
*/
$out = ( isset($fn_str_parts[2])
&& isset($fntext[$fncount])
&& $fntext[$fncount] == '#')
? ''
: ( "");
if ($fn_str != '') {
/* If there’s footnote text provided, then store the text as the
definition of the footnote of the current number (which might be
either specified explicitly, or computed by incrementing), for
later output. (This could be an inline definition, with or
without an explicit number, or else a non-inline definition.)
*/
$fntext[$fncount] = "";
} else if (!isset($fntext[$fncount])) {
/* If there’s no footnote text provided, then record that this
footnote number has been referenced. This may be checked later,
to identify non-inline numbered footnote definitions (see the
definition of $out, above).
*/
$fntext[$fncount] = '#';
}
}
return $out;
}