]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
mdwn: Enable footnotes by default when using Discount
authorSimon McVittie <smcv@debian.org>
Sun, 14 May 2017 17:16:53 +0000 (18:16 +0100)
committerSimon McVittie <smcv@debian.org>
Sun, 14 May 2017 17:16:53 +0000 (18:16 +0100)
A new mdwn_footnotes option can be used to disable footnotes in
MultiMarkdown and Discount.

IkiWiki/Plugin/mdwn.pm
debian/changelog
doc/bugs/footnotes-look-weird.mdwn

index aeb3a3fd7f6aabf72a01248e45036da01257a1d5..e142fec4633272d67c7feb79778f08b465d2e2cc 100644 (file)
@@ -7,6 +7,7 @@ use strict;
 use IkiWiki 3.00;
 
 sub import {
+       hook(type => "checkconfig", id => "mdwn", call => \&checkconfig);
        hook(type => "getsetup", id => "mdwn", call => \&getsetup);
        hook(type => "htmlize", id => "mdwn", call => \&htmlize, longname => "Markdown");
        hook(type => "htmlize", id => "md", call => \&htmlize, longname => "Markdown (popular file extension)", nocreate => 1);
@@ -33,6 +34,17 @@ sub getsetup () {
                        safe => 1,
                        rebuild => 1,
                },
+               mdwn_footnotes => {
+                       type => "boolean",
+                       example => 1,
+                       description => "enable footnotes in Markdown (where supported)?",
+                       safe => 1,
+                       rebuild => 1,
+               },
+}
+
+sub checkconfig () {
+       $config{mdwn_footnotes} = 1 unless defined $config{mdwn_footnotes};
 }
 
 my $markdown_sub;
@@ -54,7 +66,13 @@ sub htmlize (@) {
                        }
                        else {
                                $markdown_sub=sub {
-                                       Text::MultiMarkdown::markdown(shift, {use_metadata => 0});
+                                       my %flags=( use_metadata => 0 );
+
+                                       if ($config{mdwn_footnotes}) {
+                                               $flags{disable_footnotes}=1;
+                                       }
+
+                                       Text::MultiMarkdown::markdown(shift, \%flags);
                                }
                        }
                }
@@ -79,6 +97,10 @@ sub htmlize (@) {
                                        # Use the typography plugin instead
                                        $flags |= Text::Markdown::Discount::MKD_NOPANTS();
 
+                                       if ($config{mdwn_footnotes}) {
+                                               $flags |= Text::Markdown::Discount::MKD_EXTRA_FOOTNOTE();
+                                       }
+
                                        # Workaround for discount's eliding
                                        # of <style> blocks.
                                        # https://rt.cpan.org/Ticket/Display.html?id=74016
index 08e320f30945d84ee6bcfaaf00569b79fafa2500..e2a861c3cd35bd6453c58b6c2d27eeef3ca8f21e 100644 (file)
@@ -8,6 +8,9 @@ ikiwiki (3.20170112) UNRELEASED; urgency=medium
     a set-but-empty name as if they were not signed in.
   * When the CGI fails, print the error to stderr, not "Died"
   * mdwn: Don't mangle <style> into <elyts> under some circumstances
+  * mdwn: Enable footnotes by default when using the default Discount
+    implementation. A new mdwn_footnotes option can be used to disable
+    footnotes in MultiMarkdown and Discount.
 
  -- Simon McVittie <smcv@debian.org>  Sun, 14 May 2017 15:34:52 +0100
 
index be1e5d562e8a588703722a420caa73f724fe0cdb..a821ab43c14d9a132dc8458a304d8d333bba3762 100644 (file)
@@ -92,6 +92,10 @@ screen readers), as detailed in [this Stack Overflow discussion][].
 >>> --[[smcv]]
 >>>
 >>>> Makes perfect sense to me. --[[anarcat]]
+>>>>
+>>>>> I have now enabled footnotes in Discount by default, with a new
+>>>>> `mdwn_footnotes` option that can switch them off if they become
+>>>>> problematic. --[[smcv]]
 >>>
 >> For example, to enable footnotes, one needs to call Discount like this:
 >>