creoleaddition.pl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #!/usr/bin/env perl
  2. use strict;
  3. use v5.10;
  4. # ====================[ creoleaddition.pl ]====================
  5. =head1 NAME
  6. creoleaddition - An Oddmuse module for augmenting the Creole Markup module with
  7. so-called, unofficial "Creole Additions" markup.
  8. =head1 INSTALLATION
  9. creoleaddition is simply installable; simply:
  10. =over
  11. =item First install the Creole Markup module; see
  12. L<http://www.oddmuse.org/cgi-bin/oddmuse/Creole_Markup_Extension>.
  13. =item Move this file into the B<wiki/modules/> directory for your Oddmuse Wiki.
  14. =back
  15. =cut
  16. AddModuleDescription('creoleaddition.pl', 'Creole Addition Markup Extension');
  17. our ($bol, @MyRules, %RuleOrder);
  18. # ....................{ CONFIGURATION }....................
  19. =head1 CONFIGURATION
  20. creoleaddition is easily configurable; set these variables in the
  21. B<wiki/config.pl> file for your Oddmuse Wiki.
  22. =cut
  23. # Since these rules are not official now, users can turn off some of
  24. # them.
  25. our ($CreoleAdditionSupSub,
  26. $CreoleAdditionDefList,
  27. $CreoleAdditionIndentedParagraphs,
  28. $CreoleAdditionQuote,
  29. $CreoleAdditionMonospace,
  30. $CreoleAdditionSmallCaps, $CreoleAdditionIsInSmallCaps);
  31. =head2 $CreoleAdditionSupSub
  32. A boolean that, if true, enables this extension's handling of
  33. ^^supscript^^ and ,,subscript,,-style markup. (By default, this boolean is
  34. true.)
  35. =cut
  36. $CreoleAdditionSupSub = 1;
  37. =head2 $CreoleAdditionDefList
  38. A boolean that, if true, enables this extension's handling of
  39. "; definition : lists"-style markup. (By default, this boolean is true.)
  40. =cut
  41. $CreoleAdditionDefList = 1;
  42. =head2 $CreoleAdditionIndentedParagraphs
  43. A boolean that, if true, enables this extension's handling of
  44. ": indented pagraphs"-style markup. (By default, this boolean is true.)
  45. =cut
  46. $CreoleAdditionIndentedParagraphs = 1;
  47. =head2 $CreoleAdditionQuote
  48. A boolean that, if true, enables this extension's handling of
  49. """block quote""" and ''inline quote''-style markup. (By default, this
  50. boolean is true.)
  51. =cut
  52. $CreoleAdditionQuote = 1;
  53. =head2 $CreoleAdditionMonospace
  54. A boolean that, if true, enables this extension's handling of
  55. ##monospaced text##-style markup. (By default, this boolean is true.)
  56. =cut
  57. $CreoleAdditionMonospace = 1;
  58. =head2 $CreoleAdditionSmallCaps
  59. A boolean that, if true, enables this extension's handling of
  60. %%small caps%%-style markup. (By default, this boolean is true.)
  61. =cut
  62. $CreoleAdditionSmallCaps = 1;
  63. # ....................{ MARKUP }....................
  64. push(@MyRules, \&CreoleAdditionRule);
  65. SetHtmlEnvironmentContainer('blockquote');
  66. # Blockquote line-breaks conflict with Creole-style line-breaks.
  67. $RuleOrder{\&CreoleAdditionRule} = -11;
  68. sub CreoleAdditionRule {
  69. # indented paragraphs
  70. if ($CreoleAdditionIndentedParagraphs && $bol && m/\G((\s*\n)*(\:+)[ \t]*)/cg) {
  71. return CloseHtmlEnvironment()
  72. . AddHtmlEnvironment('p', 'class="indent level' . length($3)
  73. . '" style="margin-left: ' . 2*length($3) . 'em"');
  74. }
  75. # definition list
  76. # ; dt
  77. # : dd
  78. elsif ($CreoleAdditionDefList && $bol && m/\G\s*\;[ \t]*(?=(.+(\n)(\s)*\:))/cg
  79. or InElement('dd') && m/\G\s*\n(\s)*\;[ \t]*(?=(.+\n(\s)*\:))/cg) {
  80. return CloseHtmlEnvironmentUntil('dd') . OpenHtmlEnvironment('dl', 1)
  81. . AddHtmlEnvironment('dt'); }# `:' needs special treatment, later
  82. elsif (InElement('dt') and m/\G\s*\n(\s)*\:[ \t]*(?=(.+(\n)(\s)*\:)*)/cg) {
  83. return CloseHtmlEnvironment() . AddHtmlEnvironment('dd');}
  84. elsif (InElement('dd') and m/\G\s*\n(\s)*\:[ \t]*(?=(.+(\n)(\s)*\:)*)/cg) {
  85. return CloseHtmlEnvironment() . AddHtmlEnvironment('dd');}
  86. # """block quotes"""
  87. elsif ($CreoleAdditionQuote and $bol and m/\G\"\"\"(\n|$)/cg) {
  88. return InElement('blockquote')
  89. ? CloseHtmlEnvironment('blockquote').AddHtmlEnvironment('p')
  90. : CloseHtmlEnvironments()
  91. .AddHtmlEnvironment('blockquote').AddHtmlEnvironment('p');
  92. }
  93. # ''inline quotes''
  94. elsif ($CreoleAdditionQuote and m/\G\'\'/cgs) { return AddOrCloseHtmlEnvironment('q'); }
  95. # ^^sup^^
  96. elsif ($CreoleAdditionSupSub and m/\G\^\^/cg) { return AddOrCloseHtmlEnvironment('sup'); }
  97. # ,,sub,,
  98. elsif ($CreoleAdditionSupSub and m/\G\,\,/cg) { return AddOrCloseHtmlEnvironment('sub'); }
  99. # ##monospace code##
  100. elsif ($CreoleAdditionMonospace and m/\G\#\#/cg) { return AddOrCloseHtmlEnvironment('code'); }
  101. # %%small caps%%
  102. elsif ($CreoleAdditionSmallCaps and m/\G\%\%/cg) {
  103. return AddOrCloseHtmlEnvironment('span', 'style="font-variant: small-caps"');
  104. }
  105. return;
  106. }
  107. =head1 COPYRIGHT AND LICENSE
  108. The information below applies to everything in this distribution,
  109. except where noted.
  110. Copyleft 2008 by B.w.Curry <http://www.raiazome.com>.
  111. Copyright 2008 by Weakish Jiang <weakish@gmail.com>.
  112. Copyright 2009 Alex Schroeder <alex@gnu.com>
  113. This program is free software; you can redistribute it and/or modify
  114. it under the terms of the GNU General Public License as published by
  115. the Free Software Foundation; either version 3 of the License, or
  116. (at your option) any later version.
  117. This program is distributed in the hope that it will be useful,
  118. but WITHOUT ANY WARRANTY; without even the implied warranty of
  119. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  120. GNU General Public License for more details.
  121. You should have received a copy of the GNU General Public License
  122. along with this program. If not, see L<http://www.gnu.org/licenses/>.
  123. =cut