1 # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
2 # Niklas Volbers <mithrandir42@web.de>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the
16 # Free Software Foundation, Inc.
17 # 59 Temple Place, Suite 330
18 # Boston, MA 02111-1307 USA
20 # This module creates a list of all questions on the page, e.g.
21 # for a faq. It does so by recognizing all lines that begin with
23 # Additionally, lines starting with Q: and A: are rendered using
24 # the css classes div.question and div.answer.
26 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/faq.pl">faq.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/FAQ_Extension">FAQ Extension</a></p>';
28 $FaqHeaderText = "Questions on this page:" unless $FaqHeaderText;
29 $FaqQuestionText = "Question: " unless $FaqQuestionText;
30 $FaqAnswerText = "Answer: " unless $FaqAnswerText;
32 push(@MyRules, \
&FaqRule
);
35 if ($bol && m/\GQ: (.+)/gc) {
36 return $q->a({name
=>'FAQ_' . UrlEncode
($1)},'')
37 . $q->div({class=>'question'}, $FaqQuestionText . $1);
38 } elsif ($bol && m/\GA:[ \t]*/gc) {
39 return CloseHtmlEnvironments
()
40 . AddHtmlEnvironment
('div', "class='answer'") . $FaqAnswerText;
45 *OldFaqGetHeader
= *GetHeader
;
46 *GetHeader
= *NewFaqGetHeader
;
50 my $result = OldFaqGetHeader
(@_);
51 # append FAQ to header
52 $result .= FaqHeadings
($id) if $id;
57 $page = GetPageContent
(shift);
58 # ignore all the stuff that gets processed anyway by usemod.pl and
59 # creole.pl -- if we're not going to hook into ordinary parsing like
60 # toc.pl does, this will always be incomplete.
61 $page =~ s/<nowiki>(.*\n)*<\/nowiki>//gi
;
62 $page =~ s/<pre>(.*\n)*<\/pre>//gi
;
63 $page =~ s/<code>(.*\n)*<\/code>//gi
;
64 $page =~ s/\{\{\{[ \t]*\n(.*?)\n\}\}\}[ \t]*(\n|$)//gs;
67 foreach $line (grep(/^Q:[ \t]*(.*?)$/, split(/\n/, $page))) {
68 next unless $line =~ /^Q:[ \t]*(.*?)$/;
70 my $link = 'FAQ_' . UrlEncode
($1);
71 $Headings .= $q->li($q->a({href
=>'#' . $link}, $1));
73 return $q->div({class=>'faq'}, $FaqHeaderText . $q->ol($Headings)) if $Headings;