Skip to main content
Topic: Footnotes (Read 2070 times) previous topic - next topic - Topic derived from ElkArte german langua...
0 Members and 1 Guest are viewing this topic.

Footnotes

I noticed it's broken when the footnote starts with a newline *and* the /me doesn't cope very well with it.
I'm afraid it's worse than that. Footnotes can't be nested, either.
It's a very special bbcode, so Wedge (and my SMF mod, to a lesser extent) have some specific code for it inside the parse_bbc loop, I don't know how exactly you're doing it in Elk (I try not to look at your codebase too often, don't want to get 'free inspiration' when I can't really share back[1]), but I guess it's not a bbcode that can just be 'improvised' (is that US or UK spelling?), it needs some extra thought to work correctly. I even fixed it again a couple of months ago, when Arantor pointed out that the footnotes didn't get constrained by their surrounding quotes. And I may have to fix it again in the future, you never know.
Actually I shared back, since my single-line commit to SMF got cherry-picked by Elk (saves me the trouble of having to do a pull request for it as well.) I'm wondering, though... How exactly did you guys transfer my commit when it's in a different file at this point..? Does git handle that by itself through its dreaded 3-way merge..? Even across renamed and moved files?

Re: Re: ElkArte german language files

Reply #1
Footnotes is basically just this.  As part of parseBBC if finds the tag and just replaces it with the % fn % thing, then at the end of parsebbc it finds all those % fn % and moves the footnote text to the end of the message and does the link to the note and back to the link anchors, most of the stuff there is just to have those unique anchor id's.  Why am I telling you this, you are the footnote master :) so be gentile !

I should use something other than % fn % (the real one does not have the spaces) since if someone did type that in a line it would try to render things ... I thought that was the bug you were hinting at!
Code: [Select]
	if (strpos($message, '% fn %'))
{
global $fn_num, $fn_content, $fn_count;
static $fn_total;

$fn_num = 0;
$fn_content = array();
$fn_count = isset($fn_total) ? $fn_total : 0;

$message = preg_replace_callback('~(% fn %(.*?)% fn %)~is', create_function('$m', '
global $fn_num, $fn_content, $fn_count;

$fn_num++;
$fn_content[] = "<sup id=\"fn$fn_num" . "_" . "$fn_count\">$fn_num&nbsp;</sup>$m[2]<a class=\"footnote_return\" href=\"#ref$fn_num" . "_" . "$fn_count\">&crarr;</a>";
return "<a href=\"#fn$fn_num" . "_" . "$fn_count\" id=\"ref$fn_num" . "_" . "$fn_count\">[$fn_num]</a>";'), $message);

$fn_total += $fn_num;
if (!empty($fn_num))
$message .= '<div class="bbc_footnotes">' . implode('<br>', $fn_content) . '</div>';
}

Quote
Actually I shared back, since my single-line commit to SMF got cherry-picked by Elk (saves me the trouble of having to do a pull request for it as well.) I'm wondering, though... How exactly did you guys transfer my commit when it's in a different file at this point..?
It was done manually ... even when things are in different files, or have to be re-done to even work for Elk (which most do at this point),  I use the -author tag to credit who authored the original fix/update/etc, plus that way if its wrong I have someone to blame :P
Squish squish. squish, squish, squish.
Find a bug,
Make a wish.

Re: Re: ElkArte german language files

Reply #2
Footnotes is basically just this.  As part of parseBBC if finds the tag and just replaces it with the % fn % thing, then at the end of parsebbc it finds all those % fn % and moves the footnote text to the end of the message and does the link to the note and back to the link anchors, most of the stuff there is just to have those unique anchor id's.  Why am I telling you this, you are the footnote master :) so be gentile !
Well, it's interesting. At least you're handling it as the special tag that it is, so extra points for you guys. I'm not sure there's a need to turn tags into % fn % though, it seems like an extra unnecessary step, to me, but I suppose you simply wanted to leverage SMF's non-regex-based parser, and save an extra preg_match at the end?

Quote
I should use something other than % fn % (the real one does not have the spaces) since if someone did type that in a line it would try to render things ... I thought that was the bug you were hinting at!
Nope. It's really about the fact that you can't nest footnotes in ElkArte, while you can do it in Wedge. (In fact, I think it was possible since the very first version of my mod.)
I'm sorry that I can't help you by providing my code, but whether it be the SMF mod[1], and the Wedge version[2], you can't re-use my code as it is. You can re-ask me in a year's time if you still have problems with it; at that time I'll either be bored with Wedge or it'll be released officially and I probably won't be as protective of my code.
Oh, an alternative would be to take the MediaWiki code. I think they're BSD or something...? And I'm sure it's very solid. I have no idea how they do it, though, the fun is in the implementation, after all.

Quote
$message = preg_replace_callback('~(% fn %(.*?)% fn %)~is', create_function('$m', '
 global $fn_num, $fn_content, $fn_count;
Oh, wait, you *do* have a preg_replace in the end... ;)

Overall, my code is about twice as long, because it's been refined over the years. I guess it was to be expected. My starting code (in the mod) was much simpler.
I think there's still a bug in my implementation, though (when using multiple quotes, each with multiple footnotes), but I haven't seen it in a while, so it probably was fixed by my recent additions.

Quote
It was done manually ... even when things are in different files, or have to be re-done to even work for Elk (which most do at this point),  I use the -author tag to credit who authored the original fix/update/etc, plus that way if its wrong I have someone to blame :P
Oh... I see, I see. Well, I'm far from understanding all the tricks in git anyway, so this isn't the kind of thing you could expect me to know, I suppose. My entire body is rejecting git every day I use it. I'm starting to look into Mercurial again (perhaps also because its branching systems make a bit more sense to me), but in the end I'd return to SVN in a blink if I could have the equivalent (and relative ease of use?) of a Signed-Off-By in it. And something in-between pull requests and SVN patches.
Sorry for the rant!
Which you can at least freely look into for inspiration, but has as its license terms "you will not distribute a modified version of it", I just checked)
Which some of you can look into, but you know the license terms too, they're SMF 1.x's

Re: Footnotes

Reply #3
I wanted to give it a try, to show off my abominable regexp skillz! :P

It was funny. :o (sort of :P)

Code: [Select]
	// Finish footnotes if we have any.
if (strpos($message, '% fn%'))
// ____________________________^_ nospace
{
global $fn_num, $fn_content, $fn_count, $has_footnote;
static $fn_total;

$fn_num = 1;
$has_footnote = false;
$fn_content = array();
$fn_count = isset($fn_total) ? $fn_total : 0;

$message = preg_replace_callback('~(% fn%|%/fn%)~is', create_function('$m', '
// __________________________________________________^_ nospace
global $fn_num, $fn_content, $fn_count;

if ($m[0] == \'% fn%\')
// _____________________________________^_ nospace
return \'% fn\' . $fn_num++ . \'%\';
// _____________________________________^_ nospace
else
return \'%/fn\' . --$fn_num . \'%\';
'), $message);

$message = footnotes__callback($message);
ksort($fn_content);

$fn_total += $fn_num;
if (!empty($has_footnote))
$message .= '<div class="bbc_footnotes">' . implode('<br>', $fn_content) . '</div>';
}

Code: [Select]

function footnotes__callback($message)
{
$message = preg_replace_callback('~(%(fn(\d)+)%(.*?)%/\\2%)~is', create_function('$m', '
global $fn_content, $fn_count, $has_footnote;

$has_footnote = true;
if (strpos($m[4], \'%fn\'))
$m[4] = footnotes__callback($m[4]);

$fn_num = $m[3];
$fn_content[$fn_num] = "<sup id=\"fn$fn_num" . "_" . "$fn_count\">$fn_num&nbsp;</sup>$m[4]<a class=\"footnote_return\" href=\"#ref$fn_num" . "_" . "$fn_count\">&crarr;</a>";
return "<a href=\"#fn$fn_num" . "_" . "$fn_count\" id=\"ref$fn_num" . "_" . "$fn_count\">[$fn_num]</a>";'), $message);

return $message;
}

And the bbcode changed to:
Code: [Select]
			array(
'tag' => 'footnote',
'before' => '<sup class="bbc_footnotes">% fn%',
// ______________________________________________________________________^_ nospace
'after' => '%/fn%</sup>',
'disallow_parents' => array('quote', 'anchor', 'url', 'iurl'),
'disallow_before' => '',
'disallow_after' => '',
'block_level' => true,
),
Bugs creator.
Features destroyer.
Template killer.

Re: Footnotes

Reply #4
Having some fun are we :)  ... It got your me action working in the footnote for an upcoming PR for you as well.


Looking at your code, I think the problem is going to be when you have multiple non-nested footnotes, it looks like then they would all render to the same number (that $fn_num++ --$fn_num will just stay at 1 for sequential notes and increment only for nested I think).  I need to go play with this and see!
Squish squish. squish, squish, squish.
Find a bug,
Make a wish.

Re: Footnotes

Reply #5
Argh... you are right! :P
Bugs creator.
Features destroyer.
Template killer.