| 1 | package Pod::Simple::Wiki::Twiki; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | ############################################################################### | ||||||||||||||||||
| 4 | # | ||||||||||||||||||
| 5 | # Pod::Simple::Wiki::Twiki - A class for creating Pod to Twiki filters. | ||||||||||||||||||
| 6 | # | ||||||||||||||||||
| 7 | # | ||||||||||||||||||
| 8 | # Copyright 2003-2012, John McNamara, jmcnamara@cpan.org | ||||||||||||||||||
| 9 | # | ||||||||||||||||||
| 10 | # Documentation after __END__ | ||||||||||||||||||
| 11 | # | ||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | # perltidy with the following options: -mbl=2 -pt=0 -nola | ||||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | 3 | ▶ | use Pod::Simple::Wiki; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 16 | 3 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 17 | 3 | ▶ | use vars qw(@ISA $VERSION); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | 3 | @ISA = qw(Pod::Simple::Wiki); | |||||||||||||||||
| 21 | 3 | $VERSION = '0.20'; | |||||||||||||||||
| 22 | |||||||||||||||||||
| 23 | |||||||||||||||||||
| 24 | ############################################################################### | ||||||||||||||||||
| 25 | # | ||||||||||||||||||
| 26 | # The tag to wiki mappings. | ||||||||||||||||||
| 27 | # | ||||||||||||||||||
| 28 | 3 | my $tags = { | |||||||||||||||||
| 29 | '<b>' => '*', | ||||||||||||||||||
| 30 | '</b>' => '*', | ||||||||||||||||||
| 31 | '<i>' => '_', | ||||||||||||||||||
| 32 | '</i>' => '_', | ||||||||||||||||||
| 33 | '<tt>' => '=', | ||||||||||||||||||
| 34 | '</tt>' => '=', | ||||||||||||||||||
| 35 | '<pre>' => "\n<verbatim>\n", | ||||||||||||||||||
| 36 | '</pre>' => "\n</verbatim>\n\n", | ||||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | '<h1>' => '---+ ', | ||||||||||||||||||
| 39 | '</h1>' => "\n\n", | ||||||||||||||||||
| 40 | '<h2>' => '---++ ', | ||||||||||||||||||
| 41 | '</h2>' => "\n\n", | ||||||||||||||||||
| 42 | '<h3>' => '---+++ ', | ||||||||||||||||||
| 43 | '</h3>' => "\n\n", | ||||||||||||||||||
| 44 | '<h4>' => '---++++ ', | ||||||||||||||||||
| 45 | '</h4>' => "\n\n", | ||||||||||||||||||
| 46 | }; | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | |||||||||||||||||||
| 49 | ############################################################################### | ||||||||||||||||||
| 50 | # | ||||||||||||||||||
| 51 | # new() | ||||||||||||||||||
| 52 | # | ||||||||||||||||||
| 53 | # Simple constructor inheriting from Pod::Simple::Wiki. | ||||||||||||||||||
| 54 | # | ||||||||||||||||||
| 55 | 22 | ▶ | sub new { | ||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 56 | |||||||||||||||||||
| 57 | 22 | my $class = shift; | |||||||||||||||||
| 58 | 22 | my $self = Pod::Simple::Wiki->new( 'wiki', @_ ); | |||||||||||||||||
| 59 | 22 | $self->{_tags} = $tags; | |||||||||||||||||
| 60 | |||||||||||||||||||
| 61 | 22 | bless $self, $class; | |||||||||||||||||
| 62 | 22 | return $self; | |||||||||||||||||
| 63 | } | ||||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | |||||||||||||||||||
| 66 | ############################################################################### | ||||||||||||||||||
| 67 | # | ||||||||||||||||||
| 68 | # _indent_item() | ||||||||||||||||||
| 69 | # | ||||||||||||||||||
| 70 | # Indents an "over-item" to the correct level. | ||||||||||||||||||
| 71 | # | ||||||||||||||||||
| 72 | 37 | ▶ | sub _indent_item { | ||||||||||||||||
|
Subroutine
_indent_item: called CC=4 SCAR=13.9
| |||||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | 37 | my $self = shift; | |||||||||||||||||
| 75 | 37 | my $item_type = $_[0]; | |||||||||||||||||
| 76 | 37 | my $item_param = $_[1]; | |||||||||||||||||
| 77 | 37 | my $indent_level = $self->{_item_indent}; | |||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | 37 | ▶ | if ( $item_type eq 'bullet' ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 80 | 12 | $self->_append( ' ' x $indent_level . '* ' ); | |||||||||||||||||
| 81 | } | ||||||||||||||||||
| 82 | elsif ( $item_type eq 'number' ) { | ||||||||||||||||||
| 83 | 12 | $self->_append( ' ' x $indent_level . $item_param . '. ' ); | |||||||||||||||||
| 84 | } | ||||||||||||||||||
| 85 | elsif ( $item_type eq 'text' ) { | ||||||||||||||||||
| 86 | 13 | $self->_append( ' ' x $indent_level . '$ ' ); | |||||||||||||||||
| 87 | } | ||||||||||||||||||
| 88 | } | ||||||||||||||||||
| 89 | |||||||||||||||||||
| 90 | |||||||||||||||||||
| 91 | ############################################################################### | ||||||||||||||||||
| 92 | # | ||||||||||||||||||
| 93 | # _handle_text() | ||||||||||||||||||
| 94 | # | ||||||||||||||||||
| 95 | # Perform any necessary transforms on the text. This is mainly used to escape | ||||||||||||||||||
| 96 | # inadvertent CamelCase words. | ||||||||||||||||||
| 97 | # | ||||||||||||||||||
| 98 | 60 | ▶ | sub _handle_text { | ||||||||||||||||
|
Subroutine
_handle_text: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 99 | |||||||||||||||||||
| 100 | 60 | my $self = shift; | |||||||||||||||||
| 101 | 60 | my $text = $_[0]; | |||||||||||||||||
| 102 | |||||||||||||||||||
| 103 | # Split the text into tokens but maintain the whitespace | ||||||||||||||||||
| 104 | 60 | my @tokens = split /(\s+)/, $text; | |||||||||||||||||
| 105 | |||||||||||||||||||
| 106 | # Escape any tokens here. | ||||||||||||||||||
| 107 | |||||||||||||||||||
| 108 | # Rejoin the tokens and whitespace. | ||||||||||||||||||
| 109 | 60 | $self->{_wiki_text} .= join '', @tokens; | |||||||||||||||||
| 110 | } | ||||||||||||||||||
| 111 | |||||||||||||||||||
| 112 | |||||||||||||||||||
| 113 | ############################################################################### | ||||||||||||||||||
| 114 | # | ||||||||||||||||||
| 115 | # Functions to deal with =over ... =back regions for | ||||||||||||||||||
| 116 | # | ||||||||||||||||||
| 117 | # Bulleted lists | ||||||||||||||||||
| 118 | # Numbered lists | ||||||||||||||||||
| 119 | # Text lists | ||||||||||||||||||
| 120 | # Block lists | ||||||||||||||||||
| 121 | # | ||||||||||||||||||
| 122 | 13 | ▶ | sub _end_item_text { $_[0]->_output( ': ' ) } | ||||||||||||||||
|
Subroutine
_end_item_text: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 123 | |||||||||||||||||||
| 124 | |||||||||||||||||||
| 125 | ############################################################################### | ||||||||||||||||||
| 126 | # | ||||||||||||||||||
| 127 | # _start_Para() | ||||||||||||||||||
| 128 | # | ||||||||||||||||||
| 129 | # Special handling for paragraphs that are part of an "over" block. | ||||||||||||||||||
| 130 | # | ||||||||||||||||||
| 131 | 19 | ▶ | sub _start_Para { | ||||||||||||||||
|
Subroutine
_start_Para: called CC=2 SCAR=6.9
| |||||||||||||||||||
| 132 | |||||||||||||||||||
| 133 | 19 | my $self = shift; | |||||||||||||||||
| 134 | 19 | my $indent_level = $self->{_item_indent}; | |||||||||||||||||
| 135 | |||||||||||||||||||
| 136 | 19 | ▶ | if ( $self->{_in_over_block} ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 137 | |||||||||||||||||||
| 138 | # Do something here is necessary | ||||||||||||||||||
| 139 | } | ||||||||||||||||||
| 140 | } | ||||||||||||||||||
| 141 | |||||||||||||||||||
| 142 | |||||||||||||||||||
| 143 | 3 | 1; | |||||||||||||||||
| 144 | |||||||||||||||||||
| 145 | |||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||