Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ local/
tmp/
.idea/

report.*.json
changelog.txt
npm-debug.log
npm-debug.log
yarn.lock
.vscode/launch.json
20 changes: 16 additions & 4 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ var regex = {
transition: /^((?:FADE (?:TO BLACK|OUT)|CUT TO BLACK)\.|.+ TO\:|^TO\:$)|^(?:> *)(.+)/,

dialogue: /^([A-Z*_]+[0-9A-Z (._\-')]*)(\^?)?(?:\n(?!\n+))([\s\S]+)/,
dialogue_double_line_break: /^\s*\{two spaces}\s*$/,
character: /^([A-Z*_]+[0-9A-Z (._\-')]*)\^?$|^@.*$/,
parenthetical: /^(\(.+\))$/,

action: /^(.+)/g,
centered: /^(?:> *)(.+)(?: *<)(\n.+)*/g,

page_break: /^\={3,}$/,
line_break: /^ {2}$/
line_break: /^ {2}$/,
};

parser.parse = function(original_script, cfg) {
Expand Down Expand Up @@ -184,15 +185,15 @@ parser.parse = function(original_script, cfg) {
token.text = token.text.substr(1);
} else if ((token.text.length > 0 && token.text[0] === "@") || (token.text === token.text.toUpperCase() && top_or_separated)) {
if (i === lines_length || i === lines_length - 1 || lines[i + 1].trim().length === 0) {
token.type = "shot";
token.type = "shot";
} else {
state = "dialogue";
token.type = "character";
token.text = token.text.replace(/^@/, "");
if (token.text[token.text.length - 1] === "^") {
if (cfg.use_dual_dialogue) {
// update last dialogue to be dual:left
var dialogue_tokens = ["dialogue", "character", "parenthetical"];
var dialogue_tokens = ["dialogue", "character", "parenthetical", "dialogue_double_line_break"];
while (dialogue_tokens.indexOf(result.tokens[last_character_index].type) !== -1) {
result.tokens[last_character_index].dual = "left";
last_character_index++;
Expand All @@ -209,8 +210,11 @@ parser.parse = function(original_script, cfg) {
token.type = "action";
}
} else {
if (token.text.match(regex.parenthetical)) {
if (token.text.match(regex.parenthetical)) {
token.type = "parenthetical";
} else if (token.text.match(regex.dialogue_double_line_break)) {
token.type = "dialogue_double_line_break";
token.text = "";
} else {
token.type = "dialogue";
}
Expand Down Expand Up @@ -258,6 +262,14 @@ parser.parse = function(original_script, cfg) {
result.tokens.splice(current_index, 0, additional_separator);
current_index++;
}

if (current_token.is("dialogue_double_line_break")) {
var separators =
h.create_separator(token.end + 1, token.end + 1);
result.tokens.splice(current_index + 1, 0, separators);
current_index++;
}

previous_type = current_token.type;
current_index++;
}
Expand Down
37 changes: 35 additions & 2 deletions test/parser.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable quotes */

var parser = require('../parser');
var testHelper = require('./helper/test-helper');
var chai = require('chai');
Expand All @@ -14,16 +16,18 @@ describe('Parser', function() {

it('Parsing types', function() {
config = testHelper.getConfigWith(true);
script = '#Section\n\n=Synopsis\n\nINT. HEADER 1\n\nAction\n\nHERO\n(Parenthetical)\nDialogue';
script = '#Section\n\n=Synopsis\n\nINT. HEADER 1\n\nAction\n\nHERO\n(Parenthetical)\nDialogue\n {two spaces} \nDialogue';
result = parser.parse(script, config);

testHelper.verifyTokenTypes(result.tokens, [
'section', 'separator',
'synopsis', 'separator',
'scene_heading', 'separator',
'action', 'separator',
'action', 'separator',
'character',
'parenthetical',
'dialogue',
'dialogue_double_line_break', "separator",
'dialogue'
]);

Expand Down Expand Up @@ -193,7 +197,36 @@ describe('Parser', function() {
chai.assert.strictEqual(result.tokens[3].text, lines[3].trim());
});

it('Adds double line break between dialogue', function() {
var lines = [
'HERO',
'Dialogue line.',
'{two spaces}', // double line break - no spaces
'Dialogue line.',
'Dialogue line.',
' {two spaces} ', // double line break - spaces
'Dialogue line.'
];

var renderedLines = [
'HERO',
'Dialogue line.',
"", "", // double line break - no spaces
'Dialogue line.',
'Dialogue line.',
"", "",
'Dialogue line.'
];
script = lines.join('\n');
result = parser.parse(script, config);
testHelper.verifyTokenTypes(result.tokens, ['character', 'dialogue', 'dialogue_double_line_break', 'separator', 'dialogue', 'dialogue', 'dialogue_double_line_break', 'separator', 'dialogue']);

result.tokens.forEach(function(token, index) {
chai.assert.strictEqual(token.text, renderedLines[index].trim());
});
});
});


describe('Newline', function() {

Expand Down