From c16f104f7a77d169fcf384d5284114f6fb9aa4de Mon Sep 17 00:00:00 2001 From: Alex Schroeder Date: Fri, 14 Jul 2006 07:16:59 +0000 Subject: [PATCH] (TocRule): Support headers markup headers if headers.pl is loaded. Only support usemod markup headers if usemod.pl is loaded. (TocHeadings): Transform headers.pl headers into usemod.pl headers so that the TOC can be generated correctly. --- modules/toc.pl | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/toc.pl b/modules/toc.pl index 540ee256..82e6c018 100644 --- a/modules/toc.pl +++ b/modules/toc.pl @@ -16,12 +16,12 @@ # 59 Temple Place, Suite 330 # Boston, MA 02111-1307 USA -$ModulesDescription .= '

$Id: toc.pl,v 1.33 2006/06/04 21:31:27 as Exp $

'; +$ModulesDescription .= '

$Id: toc.pl,v 1.34 2006/07/14 07:16:59 as Exp $

'; push(@MyRules, \&TocRule); -# This must come *before* the usemod.pl rules and adds support for -# portrait-support.pl +# This must come *before* either headers.pl or the usemod.pl rules and +# adds support for portrait-support.pl $RuleOrder{ \&TocRule } = 90; use vars qw($TocAutomatic); @@ -65,7 +65,7 @@ sub TocRule { || InElement('h6')) && m/\G[ \t]*=+\n?/cg) { return CloseHtmlEnvironments() . AddHtmlEnvironment('p'); - } elsif ($bol + } elsif ($bol && defined(&UsemodRule) && !$UseModMarkupInTitles && m/\G(\s*\n)*(\=+)[ \t]*(.+?)[ \t]*(=+)[ \t]*\n?/cg) { my $depth = length($2); @@ -82,6 +82,20 @@ sub TocRule { $PortraitSupportColorDiv = 0; # after the HTML has been determined. $PortraitSupportColor = 0; return $html; + } elsif ($bol && defined(&HeadersRule) + && (m/\G((.+?)[ \t]*\n(---+|===+)[ \t]*\n)/gc)) { + my $depth = substr($3,0,1) eq '=' ? 2 : 3; + my $text = $2; + my $html = CloseHtmlEnvironments() + . ($PortraitSupportColorDiv ? '' : ''); + $html .= TocHeadings() if not $TocShown and $TocAutomatic; + $TocShown = 1 if $TocAutomatic; + my $TocKey = $key . ++$TocCounter{$key}; + $html .= qq{$text} + . AddHtmlEnvironment('p'); + $PortraitSupportColorDiv = 0; # after the HTML has been determined. + $PortraitSupportColor = 0; + return $html; } return undef; } @@ -95,6 +109,9 @@ sub TocHeadings { $page =~ s!(^|\n)
.*?
!!gis if defined &UsemodRule; $page =~ s!##.*?##!!gis if defined &MarkupRule; $page =~ s!%%.*?%%!!gis if defined &MarkupRule; + # transform headers markup to usemod markup to + $page =~ s!(.+?)[ \t]*\n===+[ \t]*\n!== $1 =\n!gi if defined &HeadersRule; + $page =~ s!(.+?)[ \t]*\n---+[ \t]*\n!=== $1 =\n!gi if defined &HeadersRule; my $Headings = "

" . T('Contents') . "

"; my $HeadingsLevel = undef; my $HeadingsLevelStart = undef;