Footnote callback tooltips for MP-WP thetarpit Markdown plugin

February 20, 2020 by Lucian Mogosanu

Since we're here, let's do a brief retrospective of the MP-WP V tree:

at which point the tree diverges, more precisely into a "main" branch, which is supposed to be pressed by whomever is interested in installing MP-WP, and what I've decided to call the "thetarpit" branch, which contains changes particular to my own tastes, because whaddaya know, spyked has decided to have such things as "tastes" in what software he uses. So in the former we have so far:

while the latter contains, brace yourselves:

to which I'm adding1:

And now let's see what this new V patch does, beginning with the first hunk:

diff -uNr a/mp-wp/wp-content/plugins/markdown.php b/mp-wp/wp-content/plugins/markdown.php
--- a/mp-wp/wp-content/plugins/markdown.php 7fd6211503f141ddb220bb13de09975f1e4704d2090aa5383c00de93216df9a247f4c5c74a1cbf2e8b96d4
96905ae8087237405e4ea4aa88acc3f0ff83f98851
+++ b/mp-wp/wp-content/plugins/markdown.php c68903603b46fec830712a4f272e2ae70f93e6baa2ddebe380ed4a05a3ea3fbefc7f4233c664fc78cfb06e
d4845f2b6db7c452e781a5e911352d9d841762d7be
@@ -26,10 +26,6 @@
 # Define the width of a tab for code blocks.
 @define( 'MARKDOWN_TAB_WIDTH',     4 );

-# Optional title attribute for footnote links and backlinks.
-@define( 'MARKDOWN_FN_LINK_TITLE',         "" );
-@define( 'MARKDOWN_FN_BACKLINK_TITLE',     "" );
-
 # Optional class attribute for footnote links and backlinks.
 @define( 'MARKDOWN_FN_LINK_CLASS',         "" );
 @define( 'MARKDOWN_FN_BACKLINK_CLASS',     "" );

This removes the definition for two constants, MARKDOWN_FN_LINK_TITLE and MARKDOWN_FN_BACKLINK_TITLE, which were supposedly useful for defining custom tooltips in both the callback link (the link leading to the footnote) and the backlink (the link at the end of the footnote, leading back to the main text). I've never used those and I have no clue why I'd want to define them as constants, so since I'm going to do the proper thing, I might as well remove them. Note that, similarly, there's a MARKDOWN_FN_LINK_CLASS and a MARKDOWN_FN_BACKLINK_CLASS, which actually make a whole lot of sense, given that I'd perhaps want all footnote links/backlinks to fall under a common CSS class. Not that I found any use for this yet, but I don't find it useless either, so there it remains.

Moreover, there's a fn_link_title and a fn_backlink_title, both variables associated with the constants above. There's no need to keep these anymore, so away they go:

@@ -1679,10 +1675,6 @@
    # Prefix for footnote ids.
    var $fn_id_prefix = "";

-   # Optional title attribute for footnote links and backlinks.
-   var $fn_link_title = MARKDOWN_FN_LINK_TITLE;
-   var $fn_backlink_title = MARKDOWN_FN_BACKLINK_TITLE;
-   
    # Optional class attribute for footnote links and backlinks.
    var $fn_link_class = MARKDOWN_FN_LINK_CLASS;
    var $fn_backlink_class = MARKDOWN_FN_BACKLINK_CLASS;

Finally, we remove all references to the two variables and we replace fn_link_title with a "title" attribute comprising (a stripped version of2) the footnote text:

@@ -2707,11 +2699,6 @@
                $class = $this->encodeAttribute($class);
                $attr .= " class="$class"";
            }
-           if ($this->fn_backlink_title != "") {
-               $title = $this->fn_backlink_title;
-               $title = $this->encodeAttribute($title);
-               $attr .= " title="$title"";
-           }
            $num = 0;

            while (!empty($this->footnotes_ordered)) {
@@ -2753,6 +2740,7 @@
        if (isset($this->footnotes[$node_id])) {
            # Transfert footnote content to the ordered list.
            $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id];
+           $content = $this->footnotes_ordered[$node_id];
            unset($this->footnotes[$node_id]);

            $num = $this->footnote_counter++;
@@ -2762,11 +2750,11 @@
                $class = $this->encodeAttribute($class);
                $attr .= " class="$class"";
            }
-           if ($this->fn_link_title != "") {
-               $title = $this->fn_link_title;
-               $title = $this->encodeAttribute($title);
-               $attr .= " title="$title"";
-           }
+           // Set callback title attribute to (a html-tag-less
+           // version of the) footnote content.
+           $title = $this->runBlockGamut($content);
+           $title = str_replace('"', '`', strip_tags($title));
+           $attr .= " title="$title"";

            $attr = str_replace("%%", $num, $attr);
            $node_id = $this->encodeAttribute($node_id);

Und das ist alles! The V patch has already been pressed into the main The Tar Pit install for a while now, please don't hesitate to let me know if you find any problems with it.


  1. By the way, it's a real pain to generate these lists by hand. Fortunately for me, there's some preliminary discussion on something called "V repositories" which would be an immense help in replicating some of Phf's patch viewer functionality... which would make something such as this retrospective -- on which I've spent no less than three quarters of an hour! -- a piece of cake. One thing's certain: I won't spend another three quarters of an hour doing this kind of manual labour, when I could just as well allocate that time to program the goddamn machine to do it for me. 

  2. Shamelessly stolen from the footnotes plugin

Filed under: computing.
RSS 2.0 feed. Comment. Send trackback.

7 Responses to “Footnote callback tooltips for MP-WP thetarpit Markdown plugin”

  1. #1:
    Diana Coman says:

    The trunk of the mp-wp tree has actually one more vpatch, for filtering comments. And fwiw the vpatch is added to billymg's main vtree too.

  2. #2:
    Mircea Popescu says:

    Nice, tooltips!

  3. #3:
    spyked says:

    @Diana Coman: Huh, shame on me for missing this! I mirrored the vpatch and updated the article with the link.

    @Mircea Popescu: Danke schon!

  4. #4:
    Mircea Popescu says:

    http://thetarpit.org/2020/footnote-callback-tooltips-for-mp-wp-thetarpit-markdown-plugin%3Fb%3Dmp-wp_html-c%26e%3Dmp-wp_html-comments-regrind.vpatch%2520%2528hanbot%2529%2520%2528sauc%23select 404s (linked from http://thewhet.net/2019/03/mp-wp-patch-for-enabling-html-comments/#comment-55524 )

  5. #5:
    spyked says:

    It looks like Hannah's linkback/selection thingie is broken, 'cause it encodes URL delimiters (in this case: question mark, ampersand, equals sign, hash) using percent. http://thetarpit.org/2020/footnote-callback-tooltips-for-mp-wp-thetarpit-markdown-plugin?b=mp-wp_html-c&e=mp-wp_html-comments-regrind.vpatch%2520%2528hanbot%2529%2520%2528sauc#select loads fine on this end.

  6. #6:
    Mircea Popescu says:

    Ah okay

  7. [...] haven't much to show for last month, unfortunately: I fixed some shit on my blog and that about sums it up. On the bright side, this means that you don't have all that [...]

Leave a Reply