aboutsummaryrefslogtreecommitdiff
path: root/doc/plugins/contrib/screenplay.pm.mdwn
blob: 5ff082da5820aedfe7b7d39d5113bc33ce70a647 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
This plugin works for me. It follows the standard for a movie screenplay pretty closely, I am not aware of any errors in format. Please let me know if you find any.

Right now all it does is display your pages properly in a web browser. What I would like to add is the ability to output a file that could easily be printed once the screenplay is finished. We keep all the scenes we work on in one folder and eventually we will want to print a script out of that folder. It would be great if an up to date PDF or TXT script could be put in the folder when a scene is saved. I will do it, it just isn't a priority yet. 

I am not a published writer and not an authority on script formatting. I got what I know out of a book.

Briefly, you type a command on a line, like ".d", then on the next line (for the dialog command) you type a person's name. Then you hit return again and write the words he is supposed to speak out all on one line. When you save your document this simple text will become a properly formatted script.

Thank you Joey for having me here.

###Headings: 
	Most headings should begin with a transition. The list of valid commands is:
	.fi    =>    FADE IN: a gradual transition from a solid color to an image 
	.fo    =>    FADE OUT.
	.ftb    =>    FADE TO BLACK.
	.ftw    =>    FADE TO WHITE.
	.ct     =>    CUT TO: indicates an instantaneous shift from one shot to the next
	.shot    =>    lack of an explicit transition assumes a cut
	.hct    =>    HARD CUT TO: describes a jarring transition
	.qct    =>    QUICK CUT TO: describes a cut sooner than expected
	.tct    =>    TIME CUT TO: emphasizes time passing
	.mct    =>    MATCH CUT TO: image in first shot visually or thematically matches image in second
	.dt    =>    DISSOLVE TO: gradual transition from image to another implies passage of time.
	.rdt    =>    RIPPLE DISSOLVE TO: indicates transition into daydream or imagination
	.wt    =>    WIPE TO: new image slides over top of last one
	
	Example transition:
	
	.fi (or any transition command) <= Writes a transition line, except .shot which omits it.
	type shot heading here   <= this line will be capitalized
	First direction.   <= these lines are not capitalized.
	Second direction.
	Third direction, etc...
	
	Direction without a shot heading:
	.dir
	First direction.
	Second direction.
	Third direction, etc...
	
	Some items aren't implemented in dialogue yet:
	1) you must watch that you don't leave a " -- " dangling on a line by itself, 
	     instead, carry the last word onto the line with a dash
	2) observe lyrical line endings in dialogue by indenting wrapped lines by two spaces
	3) you must watch that the four line limit for parenthetical direction is not exceeded
	
	Example dialogue:
	
	.d 
	char name   <= this line will be capitalized
	this is what he's saying                  <= Dialogue
	raises hand to wave                       <= Parenthetical direction
	this is more of what he's saying          <= Dialogue
	this is going to be in parenthesis        <= Parenthetical direction
	this is more of what he's saying, etc...  <= Dialogue
	
	.note 
	Allows you to add a temporary note to a script without getting an error. 
	All notes need to be removed eventually because they are a format violation.
	
	
	
	###name this file screenplay.pm and pop it in your Plugin folder. Then you need to add the plugin to your Ikiwiki setup file.
	
	#!/usr/bin/perl
	# Screenplay markup language
	package IkiWiki::Plugin::screenplay;
	
	use warnings;
	use strict;
	use IkiWiki 3.00;
	use Text::Format;
	use Log::Log4perl qw(:easy);
	Log::Log4perl->easy_init($INFO);
	#Log::Log4perl->easy_init($ERROR);
	
	sub import {
		hook(type => "getsetup", id => "screenplay", call => \&getsetup);
		hook(type => "htmlize", id => "screenplay", call => \&htmlize, longname => "Screenplay");
	}
	
	sub getsetup () {
	        return
	                plugin => {
	                        safe => 1,
	                        rebuild => 1, # format plugin
	                        section => "format",
	                },
	}
	
	sub htmlize (@) {
		#set up variables and fill with defaults
		my %params=@_;
		my $content = $params{content};
		my @lines = split(/\r\n|\r|\n/, $content);
		my @chunk;
		my @formatted;
		my $current_line = shift(@lines);
		my $current_command = "";
		my $current_chunk = "";
	
	    while (scalar(@lines) > 0) {
		until ( &dot_command($current_line) || scalar(@lines) == 0 ) {
		    #skip spaces; mark bad lines
	            unless ( &blank_line($current_line) ) {
	                push(@formatted, "<br />");
			push(@formatted, &no_command($current_line));
		    }
		    $current_line = shift(@lines);
		}
	
		#Exit while loop if we're out of lines
	        last if (scalar(@lines) == 0);
	
		#set command for chunk
		$current_command = $current_line;
		$current_line = shift(@lines);
	
		#get chunk, i.e. all text up to next blank line or a dot command.
		until (substr($current_line,0,1) eq '.' || $current_line =~ m// || $current_line =~ m/^\s*$/) {
		    push(@chunk,$current_line);
		    $current_line = shift(@lines);
		    last unless defined $current_line;
	        } 
	
		#Start with a blank line unless unneeded.
		if (scalar(@formatted) > 0 ) {
			push(@formatted, "<br />");
		}
	
		#remaining lines are not commands.
		if (scalar(@chunk)) {
			$current_chunk = shift(@chunk);
			if ($current_command eq ".shot") {
				push(@formatted, &indent(&chunk(uc($current_chunk),57),17));
	                        while (scalar(@chunk)) {
	                                $current_chunk = shift(@chunk);
	                                push(@formatted, "<br />");
	                                push(@formatted, &indent(&chunk($current_chunk,57),17));
	                        }
	
	                } elsif ($current_command eq ".note") { 
				push(@formatted, "NOTE:<br />");
	                        push(@formatted, &chunk($current_chunk,75));
	                        while (scalar(@chunk)) {
	                                $current_chunk = shift(@chunk);
	                                push(@formatted, "<br />");
	                                push(@formatted, &chunk($current_chunk,75));
	                        }
	
	                } elsif ($current_command eq ".dir") {
	                        push(@formatted, &indent(&chunk($current_chunk,57),17));
				while (scalar(@chunk)) {
	                                $current_chunk = shift(@chunk);
					push(@formatted, "<br />");
	                                push(@formatted, &indent(&chunk($current_chunk,57),17));
	                        }		
	
	                } elsif ($current_command eq ".d") {
				push(@formatted, &indent(&chunk(uc($current_chunk),32),41));
				$current_chunk = shift(@chunk);
	                        push(@formatted, &indent(&chunk($current_chunk,34),27));
				while (scalar(@chunk) / 2 >= 1 ) {
					$current_chunk = shift(@chunk);
					push(@formatted, &indent(&chunk(&pd($current_chunk),19),34));
					$current_chunk = shift(@chunk);
					push(@formatted, &indent(&chunk($current_chunk,34),27));
				}
	
	                } elsif ($current_command eq ".pd") {
	                        push(@formatted, &indent(&chunk(uc($current_chunk),32),41));
	                        $current_chunk = shift(@chunk);
	                        push(@formatted, &indent(&chunk(&pd($current_chunk),19),34));
	                        $current_chunk = shift(@chunk);
	                        push(@formatted, &indent(&chunk($current_chunk,34),27));
	                        while (scalar(@chunk) / 2 >= 1 ) {
	                                $current_chunk = shift(@chunk);
	                                push(@formatted, &indent(&chunk(&pd($current_chunk),19),34));
	                                $current_chunk = shift(@chunk);
	                                push(@formatted, &indent(&chunk($current_chunk,34),27));
	                        }
	
	                } elsif ($current_command =~ m/^\.(fi|fo|ct|hct|qct|tct|mct|dt|rdt)$/) {
				if ($current_command eq ".fi") {
					push(@formatted, &indent(&chunk(uc("FADE IN:"),20),17));
				} elsif ($current_command eq ".fo") {
	                                push(@formatted, &indent(&chunk(uc("FADE OUT:"),20),60));
				} elsif ($current_command eq ".ct") {
	                                push(@formatted, &indent(&chunk(uc("CUT TO:"),20),60));
	                        } elsif ($current_command eq ".hct") {
	                                push(@formatted, &indent(&chunk(uc("HARD CUT TO:"),20),60));
	                        } elsif ($current_command eq ".qct") {
	                                push(@formatted, &indent(&chunk(uc("QUICK CUT TO:"),20),60));
	                        } elsif ($current_command eq ".tct") {
	                                push(@formatted, &indent(&chunk(uc("TIME CUT TO:"),20),60));
	                        } elsif ($current_command eq ".mct") {
	                                push(@formatted, &indent(&chunk(uc("MATCH CUT TO:"),20),60));
	                        } elsif ($current_command eq ".dt") {
	                                push(@formatted, &indent(&chunk(uc("DISSOLVE TO:"),20),60));
	                        } elsif ($current_command eq ".rdt") {
	                                push(@formatted, &indent(&chunk(uc("RIPPLE DISSOLVE TO:"),20),60));
	                        } elsif ($current_command eq ".wt") {
	                                push(@formatted, &indent(&chunk(uc("WIPE TO:"),20),60));
				}
				push(@formatted, &indent(&chunk(uc($current_chunk),57),17));
	                        while (scalar(@chunk)) {
	                                $current_chunk = shift(@chunk);
	                                push(@formatted, "<br />");
	                                push(@formatted, &indent(&chunk($current_chunk,57),17));
	                        }
						
			}
			#mark the rest of the chunk as 'no command'
	        	if (scalar(@chunk)) {
	                	$current_chunk = shift(@chunk);
	        	        push(@formatted, &no_command($current_chunk));
	        	}
	
		}
	    }
	    my @content;
	    my $i = 0;
	    $current_line = "";
	    while (scalar(@formatted)) {
		$i++;
		$current_line = shift(@formatted);	
		if ( $i % 60 == 0 ) {
		    push(@content, &indent($i/60  . ".<br />",72) );
		}
		push(@content, $current_line);
	    }
	    $content = join("\r\n",@content);
	    return $content;
	}
	
	sub blank_line {
		my $line = shift(@_);
		my $ret = 0;
	
	        if ($line =~ m// || $line =~ m/^\s*$/) {
	            $ret = 1;
	        } else {
		    $ret = 0;
		}
	
		return $ret;
	}
	
	sub chunk () {
	        my $unchunked = shift(@_);
	        my $columns = shift(@_);
		my $text = new Text::Format;
		$text->rightFill(1);
		$text->columns($columns);
		$text->firstIndent(0);
		$text->tabstop(0);
		$text->extraSpace(1);
	        my @chunked = split /\n/, $text->format($unchunked);
	        my @formatted;
	        foreach (@chunked) {
	                push(@formatted, $_ . "<br />");
	        }
	        return @formatted;
	}
	
	sub dot_command {
	        my $line = shift(@_);
	        my $ret = 0;
	
	        if ($line =~ m/^\.(ct|dir|dt|d|fi|fo|hct|mct|note|pd|qct|rdt|shot|tct)$/) {
	            $ret = 1;
	        } else {
	            $ret = 0;
	        }
	
	        return $ret;
	}
	
	sub indent () {
		my @unindented = @_;
		my $spaces = pop @unindented;
		my @indented;
		foreach (@unindented) {
			push(@indented, "&nbsp;" x $spaces . $_);
		}
		return @indented;
	}
	
	sub no_command () {
		my $line = shift(@_);
	          my $text = new Text::Format;
	        $text->rightFill(1);
	        $text->columns(68);
	        $text->firstIndent(0);
	        $text->tabstop(0);
	        $text->extraSpace(1);
	        my @chunked = split /\n/, $text->format($line);
	        my @formatted;
		push(@formatted, ("NO COMMAND: "));
	        foreach (@chunked) {
	                push(@formatted, ( $_ . "<br />" ));
	        }
	        return @formatted;
	}
	
	sub pd () {
	        my @chunk = @_;
	        # add '(' to top item
	        my $line = "(" . shift(@chunk);
	        unshift(@chunk, $line);
	
	        # add ')' to bottom item
	        $line = pop(@chunk) . ")";
	        push(@chunk, $line);
	
	        return @chunk;
	}
	
	1