|
12 | 12 | scene_number: /( *#(.+)# *)/,
|
13 | 13 |
|
14 | 14 | transition: /^((?:FADE (?:TO BLACK|OUT)|CUT TO BLACK)\.|.+ TO\:)|^(?:> *)(.+)/,
|
15 |
| - |
16 |
| - dialogue: /^([A-Z*_]+[0-9A-Z (._\-')]*)(\^?)?(?:\n(?!\n+))([\s\S]+)/, |
| 15 | + |
| 16 | + dialogue: /^([A-Z\u00C0-\u017F*_]+[0-9A-Z (._\-')]*)(\^?)?(?:\n(?!\n+))([\s\S]+)/, |
17 | 17 | parenthetical: /^(\(.+\))$/,
|
18 | 18 |
|
19 | 19 | action: /^(.+)/g,
|
20 | 20 | centered: /^(?:> *)(.+)(?: *<)(\n.+)*/g,
|
21 |
| - |
| 21 | + |
22 | 22 | section: /^(#+)(?: *)(.*)/,
|
23 | 23 | synopsis: /^(?:\=(?!\=+) *)(.*)/,
|
24 | 24 |
|
|
50 | 50 | .replace(regex.cleaner, '')
|
51 | 51 | .replace(regex.whitespacer, '');
|
52 | 52 | };
|
53 |
| - |
| 53 | + |
54 | 54 | var tokenize = function (script) {
|
55 | 55 | var src = lexer(script).split(regex.splitter)
|
56 | 56 | , i = src.length, line, match, parts, text, meta, x, xlen, dual
|
57 | 57 | , tokens = [];
|
58 | 58 |
|
59 | 59 | while (i--) {
|
60 | 60 | line = src[i];
|
61 |
| - |
| 61 | + |
62 | 62 | // title page
|
63 | 63 | if (regex.title_page.test(line)) {
|
64 | 64 | match = line.replace(regex.title_page, '\n$1').split(regex.splitter).reverse();
|
|
94 | 94 | tokens.push({ type: 'transition', text: match[1] || match[2] });
|
95 | 95 | continue;
|
96 | 96 | }
|
97 |
| - |
| 97 | + |
98 | 98 | // dialogue blocks - characters, parentheticals and dialogue
|
99 | 99 | if (match = line.match(regex.dialogue)) {
|
100 | 100 | if (match[1].indexOf(' ') !== match[1].length - 2) {
|
|
107 | 107 |
|
108 | 108 | parts = match[3].split(/(\(.+\))(?:\n+)/).reverse();
|
109 | 109 |
|
110 |
| - for (x = 0, xlen = parts.length; x < xlen; x++) { |
| 110 | + for (x = 0, xlen = parts.length; x < xlen; x++) { |
111 | 111 | text = parts[x];
|
112 | 112 |
|
113 | 113 | if (text.length > 0) {
|
|
126 | 126 | continue;
|
127 | 127 | }
|
128 | 128 | }
|
129 |
| - |
| 129 | + |
130 | 130 | // section
|
131 | 131 | if (match = line.match(regex.section)) {
|
132 | 132 | tokens.push({ type: 'section', text: match[2], depth: match[1].length });
|
133 | 133 | continue;
|
134 | 134 | }
|
135 |
| - |
| 135 | + |
136 | 136 | // synopsis
|
137 | 137 | if (match = line.match(regex.synopsis)) {
|
138 | 138 | tokens.push({ type: 'synopsis', text: match[1] });
|
|
143 | 143 | if (match = line.match(regex.note)) {
|
144 | 144 | tokens.push({ type: 'note', text: match[1]});
|
145 | 145 | continue;
|
146 |
| - } |
| 146 | + } |
147 | 147 |
|
148 | 148 | // boneyard
|
149 | 149 | if (match = line.match(regex.boneyard)) {
|
150 | 150 | tokens.push({ type: match[0][0] === '/' ? 'boneyard_begin' : 'boneyard_end' });
|
151 | 151 | continue;
|
152 |
| - } |
| 152 | + } |
153 | 153 |
|
154 | 154 | // page breaks
|
155 | 155 | if (regex.page_break.test(line)) {
|
156 | 156 | tokens.push({ type: 'page_break' });
|
157 | 157 | continue;
|
158 | 158 | }
|
159 |
| - |
| 159 | + |
160 | 160 | // line breaks
|
161 | 161 | if (regex.line_break.test(line)) {
|
162 | 162 | tokens.push({ type: 'line_break' });
|
|
186 | 186 | inline.lexer = function (s) {
|
187 | 187 | if (!s) {
|
188 | 188 | return;
|
189 |
| - } |
| 189 | + } |
190 | 190 |
|
191 | 191 | var styles = [ 'underline', 'italic', 'bold', 'bold_italic', 'italic_underline', 'bold_underline', 'bold_italic_underline' ]
|
192 | 192 | , i = styles.length, style, match;
|
|
197 | 197 | while (i--) {
|
198 | 198 | style = styles[i];
|
199 | 199 | match = regex[style];
|
200 |
| - |
| 200 | + |
201 | 201 | if (match.test(s)) {
|
202 | 202 | s = s.replace(match, inline[style]);
|
203 | 203 | }
|
|
212 | 212 | callback = toks;
|
213 | 213 | toks = undefined;
|
214 | 214 | }
|
215 |
| - |
| 215 | + |
216 | 216 | var tokens = tokenize(script)
|
217 | 217 | , i = tokens.length, token
|
218 | 218 | , title, title_page = [], html = [], output;
|
|
253 | 253 |
|
254 | 254 | case 'action': html.push('<p>' + token.text + '</p>'); break;
|
255 | 255 | case 'centered': html.push('<p class=\"centered\">' + token.text + '</p>'); break;
|
256 |
| - |
| 256 | + |
257 | 257 | case 'page_break': html.push('<hr />'); break;
|
258 | 258 | case 'line_break': html.push('<br />'); break;
|
259 | 259 | }
|
|
271 | 271 | var fountain = function (script, callback) {
|
272 | 272 | return fountain.parse(script, callback);
|
273 | 273 | };
|
274 |
| - |
| 274 | + |
275 | 275 | fountain.parse = function (script, tokens, callback) {
|
276 | 276 | return parse(script, tokens, callback);
|
277 | 277 | };
|
|
280 | 280 | module.exports = fountain;
|
281 | 281 | } else {
|
282 | 282 | this.fountain = fountain;
|
283 |
| - } |
| 283 | + } |
284 | 284 | }).call(this);
|
0 commit comments