playfair

Playfair Script Formatter
git clone https://git.stjo.hn/playfair
Log | Files | Refs | README | LICENSE

html.pl (5027B)


      1 % Parse an HTML-style script into its component parts.
      2 html(parsed_script(Type, [Title, Author|Variables], Scenes)) -->
      3 	"<!DOCTYPE html>",
      4 	newline,
      5 	"<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">",
      6 	newline,
      7 	"<head>",
      8 	newline, tab,
      9 	"<meta charset=\"utf-8\" />",
     10 	newline, tab,
     11 	"<meta name=\"author\" id=\"authortag\" content=\"", text("\n", Author), "\" />",
     12 	newline, tab,
     13 	"<link rel=\"stylesheet\" href=\"common.css\" />",
     14 	newline,
     15 	html_type_css(Type),
     16 	newline, tab,
     17 	"<title>", text("\n", Title), "</title>",
     18 	newline,
     19 	"</head>",
     20 	newline,
     21 	"<body>",
     22 	newline,
     23 	html_body(Type, Title, Author, Variables, Scenes),
     24 	newline,
     25 	"</body>",
     26 	newline,
     27 	"</html>",
     28 	newline.
     29 
     30 
     31 html_type_css(screen) -->
     32 	tab,
     33 	"<link rel=\"stylesheet\" href=\"scriptfrenzy_screen.css\" />".
     34 
     35 html_type_css(stage) -->
     36 	tab,
     37 	"<link rel=\"stylesheet\" href=\"scriptfrenzy_stage.css\" />".
     38 
     39 
     40 html_body(Type, Title, Author, Variables, Scenes) -->
     41 	html_title_page(Title, Author),
     42 	newline,
     43 	html_meta_page(Variables),
     44 	newline,
     45 	html_play(Type, Scenes).
     46 
     47 
     48 html_title_page(Title, Author) -->
     49 	tab,
     50 	"<div id=\"titlepage\">",
     51 	newline, tab, tab,
     52 	"<h1>", Title, "</h1>",
     53 	newline, tab, tab,
     54 	"<p id=\"author\">", Author, "</p>",
     55 	newline, tab,
     56 	"</div>".
     57 
     58 
     59 html_meta_page([]) --> [].
     60 
     61 html_meta_page([Personae, Time, Setting]) -->
     62 	tab,
     63 	"<div id=\"metapage\">",
     64 	newline, tab, tab,
     65 	"<div>",
     66 	newline, tab, tab, tab,
     67 	"<p class=\"level3\">Dramatis Personæ</p>",
     68 	html_personae(Personae),
     69 	newline, tab, tab,
     70 	"</div>",
     71 	newline, tab, tab,
     72 	"<div>",
     73 	newline, tab, tab, tab,
     74 	"<p class=\"level3\">Time</p>",
     75 	newline, tab, tab, tab,
     76 	"<p>", text("\n", Time), "</p>",
     77 	newline, tab, tab,
     78 	"</div>",
     79 	newline, tab, tab,
     80 	"<div>",
     81 	newline, tab, tab, tab,
     82 	"<p class=\"level3\">Setting</p>",
     83 	newline, tab, tab, tab,
     84 	"<p>", text("\n", Setting), "</p>",
     85 	newline, tab, tab,
     86 	"</div>",
     87 	newline, tab,
     88 	"</div>".
     89 
     90 
     91 html_personae([]) --> [].
     92 
     93 html_personae([Persona|Rest]) -->
     94 	newline, tab, tab, tab,
     95 	"<p>", text("\n", Persona), "</p>",
     96 	html_personae(Rest).
     97 
     98 
     99 html_play(Type, Scenes) -->
    100 	tab,
    101 	"<div id=\"play\">",
    102 	newline,
    103 	html_scene_repeater(Type, Scenes),
    104 	newline, tab, tab,
    105 	"<p class=\"character end\">The End.</p>",
    106 	newline, tab,
    107 	"</div>",
    108 	newline.
    109 
    110 
    111 html_scene_repeater(_, []) --> [].
    112 
    113 html_scene_repeater(Type, [Scene|Scenes]) -->
    114 	html_scene(Type, Scene),
    115 	newline,
    116 	html_scene_repeater(Type, Scenes).
    117 
    118 
    119 % Scene definition for stage plays
    120 html_scene(stage, scene(Act, SceneDirections, Island)) -->
    121 	tab, tab,
    122 	"<div class=\"scene\">",
    123 	newline, tab, tab, tab,
    124 	"<h3 class=\"actScene\">ACT ", Act, "</h3>",
    125 	newline,
    126 	html_scene_directions(SceneDirections),
    127 	newline,
    128 	html_island_repeater(Island),
    129 	newline, tab, tab,
    130 	"</div>".
    131 
    132 % Scene definition for screenplays
    133 html_scene(screen, scene(Slug, null, Island)) -->
    134 	tab, tab,
    135 	"<div class=\"scene\">",
    136 	newline,
    137 	html_slug(Slug),
    138 	newline,
    139 	html_island_repeater(Island),
    140 	tab, tab,
    141 	"</div>".
    142 
    143 
    144 html_island_repeater([]) --> [].
    145 	
    146 html_island_repeater([Island|Rest]) -->
    147 	html_island(Island),
    148 	newline,
    149 	html_island_repeater(Rest).
    150 
    151 
    152 html_island(character_dialogue(Character, Dialogue)) -->
    153 	tab, tab, tab,
    154 	"<div class=\"dialogue\">",
    155 	newline, tab, tab, tab, tab,
    156 	"<p class=\"character\">", text("\n", Character), "</p>",
    157 	newline,
    158 	html_dialogue_combo(Dialogue),
    159 	newline, tab, tab, tab,
    160 	"</div>".
    161 
    162 html_island(stage_directions(StageDirections)) -->
    163 	tab, tab, tab,
    164 	"<div class=\"stageDirections\">",
    165 	newline, tab, tab, tab, tab,
    166 	"<p class=\"stageDirections\">", text("\n", StageDirections), "</p>",
    167 	newline, tab, tab, tab,
    168 	"</div>".
    169 
    170 
    171 html_scene_directions([]) --> [].
    172 
    173 html_scene_directions([SceneDirections|Rest]) -->
    174 	tab, tab, tab,
    175 	"<p class=\"sceneDirections\">", text("\n<", SceneDirections), "</p>",
    176 	newline,
    177 	html_scene_directions(Rest).
    178 
    179 
    180 html_dialogue_combo([]) --> [].
    181 
    182 html_dialogue_combo([character_stage_directions(Directions)|Rest]) -->
    183 	html_character_stage_directions(Directions),
    184 	newline,
    185 	html_dialogue_combo(Rest).
    186 
    187 html_dialogue_combo([dialogue(Dialogue)|Rest]) -->
    188 	tab, tab, tab, tab,
    189 	"<p class=\"dialogue\">",
    190 	html_dialogue(Dialogue),
    191 	"</p>",
    192 	newline,
    193 	html_dialogue_combo(Rest).
    194 
    195 
    196 
    197 html_dialogue([]) --> [].
    198 
    199 html_dialogue([Unit|Rest]) -->
    200 	html_dialogue_unit(Unit),
    201 	html_dialogue(Rest).
    202 
    203 
    204 html_dialogue_unit(emphatic(Emphatic)) --> html_emphatic(Emphatic).
    205 
    206 html_dialogue_unit(break(Break)) --> html_line_break(Break).
    207 
    208 html_dialogue_unit(neutral(Text)) --> text("\n<>*", Text).
    209 
    210 
    211 html_character_stage_directions(Text) -->
    212 	tab, tab, tab, tab,
    213 	"<p class=\"characterStageDirections\">",
    214 	"(",
    215 	text("\n<>)", Text),
    216 	")",
    217 	"</p>".
    218 
    219 
    220 html_emphatic(Text) --> "<em>", text("\n<>()", Text), "</em>".
    221 
    222 
    223 html_line_break([]) --> [].
    224 
    225 html_line_break([br|Rest]) -->
    226 	"<br />",
    227 	html_line_break(Rest).
    228 
    229 
    230 html_slug(slug(int, Text)) -->
    231 	tab, tab, tab,
    232 	"<h2 class=\"slug\"> INT. ",
    233 	text("\n", Text),
    234 	"</h2>".
    235 
    236 html_slug(slug(ext, Text)) -->
    237 	tab, tab, tab,
    238 	"<h2 class=\"slug\"> EXT. ",
    239 	text("\n", Text),
    240 	"</h2>".
    241