fountain.ts
Advanced tools
Comparing version 0.1.1 to 0.1.2
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Fountain = void 0; | ||
var scanner_1 = require("./scanner"); | ||
var lexer_1 = require("./lexer"); | ||
var Fountain = /** @class */ (function () { | ||
function Fountain() { | ||
const scanner_1 = require("./scanner"); | ||
const lexer_1 = require("./lexer"); | ||
class Fountain { | ||
constructor() { | ||
this.scanner = new scanner_1.Scanner; | ||
this.inlineLex = new lexer_1.InlineLexer; | ||
} | ||
Fountain.prototype.parse = function (script, getTokens) { | ||
var _this = this; | ||
parse(script, getTokens) { | ||
this.tokens = this.scanner.tokenize(script); | ||
var title = this.tokens.find(function (token) { return token.type === 'title'; }); | ||
let title = this.tokens.find(token => token.type === 'title'); | ||
return { | ||
@@ -19,9 +18,9 @@ title: title ? this.inlineLex.reconstruct(title.text) | ||
html: { | ||
title_page: this.tokens.filter(function (token) { return token.is_title; }).map(function (token) { return _this.to_html(token); }).join(''), | ||
script: this.tokens.filter(function (token) { return !token.is_title; }).map(function (token) { return _this.to_html(token); }).join('') | ||
title_page: this.tokens.filter(token => token.is_title).map(token => this.to_html(token)).join(''), | ||
script: this.tokens.filter(token => !token.is_title).map(token => this.to_html(token)).join('') | ||
}, | ||
tokens: getTokens ? this.tokens : undefined | ||
}; | ||
}; | ||
Fountain.prototype.to_html = function (token) { | ||
} | ||
to_html(token) { | ||
token.text = this.inlineLex.reconstruct(token.text); | ||
@@ -58,5 +57,5 @@ switch (token.type) { | ||
} | ||
}; | ||
return Fountain; | ||
}()); | ||
} | ||
} | ||
exports.Fountain = Fountain; | ||
//# sourceMappingURL=fountain.js.map |
@@ -15,1 +15,2 @@ "use strict"; | ||
__exportStar(require("./token"), exports); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InlineLexer = exports.Lexer = void 0; | ||
var regex_1 = require("./regex"); | ||
var Lexer = /** @class */ (function () { | ||
function Lexer() { | ||
} | ||
Lexer.prototype.reconstruct = function (script) { | ||
const regex_1 = require("./regex"); | ||
class Lexer { | ||
reconstruct(script) { | ||
return script.replace(regex_1.regex.boneyard, '\n$1\n') | ||
@@ -26,11 +11,9 @@ .replace(regex_1.regex.standardizer, '\n') | ||
.replace(regex_1.regex.whitespacer, ''); | ||
}; | ||
return Lexer; | ||
}()); | ||
} | ||
} | ||
exports.Lexer = Lexer; | ||
var InlineLexer = /** @class */ (function (_super) { | ||
__extends(InlineLexer, _super); | ||
function InlineLexer() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.inline = { | ||
class InlineLexer extends Lexer { | ||
constructor() { | ||
super(...arguments); | ||
this.inline = { | ||
note: '<!-- $1 -->', | ||
@@ -46,12 +29,10 @@ line_break: '<br />', | ||
}; | ||
return _this; | ||
} | ||
InlineLexer.prototype.reconstruct = function (line) { | ||
reconstruct(line) { | ||
if (!line) | ||
return; | ||
var match; | ||
var styles = ['bold_italic_underline', 'bold_underline', 'italic_underline', 'bold_italic', 'bold', 'italic', 'underline']; | ||
let match; | ||
const styles = ['bold_italic_underline', 'bold_underline', 'italic_underline', 'bold_italic', 'bold', 'italic', 'underline']; | ||
line = line.replace(regex_1.regex.note_inline, this.inline.note).replace(/\\\*/g, '[star]').replace(/\\_/g, '[underline]').replace(/\n/g, this.inline.line_break); | ||
for (var _i = 0, styles_1 = styles; _i < styles_1.length; _i++) { | ||
var style = styles_1[_i]; | ||
for (let style of styles) { | ||
match = regex_1.regex[style]; | ||
@@ -63,5 +44,5 @@ if (match.test(line)) { | ||
return line.replace(/\[star\]/g, '*').replace(/\[underline\]/g, '_').trim(); | ||
}; | ||
return InlineLexer; | ||
}(Lexer)); | ||
} | ||
} | ||
exports.InlineLexer = InlineLexer; | ||
//# sourceMappingURL=lexer.js.map |
@@ -33,1 +33,2 @@ "use strict"; | ||
}; | ||
//# sourceMappingURL=regex.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Scanner = void 0; | ||
var regex_1 = require("./regex"); | ||
var lexer_1 = require("./lexer"); | ||
var Scanner = /** @class */ (function () { | ||
function Scanner() { | ||
const regex_1 = require("./regex"); | ||
const lexer_1 = require("./lexer"); | ||
class Scanner { | ||
constructor() { | ||
this.tokens = []; | ||
} | ||
Scanner.prototype.tokenize = function (script) { | ||
tokenize(script) { | ||
// reverse the array so that dual dialog can be constructed bottom up | ||
var source = new lexer_1.Lexer().reconstruct(script).split(regex_1.regex.splitter).reverse(); | ||
var line, match, dual; | ||
for (var _i = 0, source_1 = source; _i < source_1.length; _i++) { | ||
line = source_1[_i]; | ||
const source = new lexer_1.Lexer().reconstruct(script).split(regex_1.regex.splitter).reverse(); | ||
let line, match, dual; | ||
for (line of source) { | ||
/** title page */ | ||
if (regex_1.regex.title_page.test(line)) { | ||
match = line.replace(regex_1.regex.title_page, '\n$1').split(regex_1.regex.splitter).reverse(); | ||
for (var _a = 0, match_1 = match; _a < match_1.length; _a++) { | ||
var item = match_1[_a]; | ||
var pair = item.replace(regex_1.regex.cleaner, '').split(/\:\n*/); | ||
for (let item of match) { | ||
let pair = item.replace(regex_1.regex.cleaner, '').split(/\:\n*/); | ||
this.tokens.push({ type: pair[0].trim().toLowerCase().replace(' ', '_'), is_title: true, text: pair[1].trim() }); | ||
@@ -28,3 +26,3 @@ } | ||
if (match = line.match(regex_1.regex.scene_heading)) { | ||
var text = match[1] || match[2], meta = void 0; | ||
let text = match[1] || match[2], meta; | ||
if (text.indexOf(' ') !== text.length - 2) { | ||
@@ -57,5 +55,4 @@ if (meta = text.match(regex_1.regex.scene_number)) { | ||
this.tokens.push({ type: 'dialogue_end' }); | ||
var parts = match[3].split(/(\(.+\))(?:\n+)/).reverse(); | ||
for (var _b = 0, parts_1 = parts; _b < parts_1.length; _b++) { | ||
var part = parts_1[_b]; | ||
let parts = match[3].split(/(\(.+\))(?:\n+)/).reverse(); | ||
for (let part of parts) { | ||
if (part.length > 0) { | ||
@@ -107,5 +104,5 @@ this.tokens.push({ type: regex_1.regex.parenthetical.test(part) ? 'parenthetical' : 'dialogue', text: part }); | ||
return this.tokens.reverse(); | ||
}; | ||
return Scanner; | ||
}()); | ||
} | ||
} | ||
exports.Scanner = Scanner; | ||
//# sourceMappingURL=scanner.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=token.js.map |
{ | ||
"name": "fountain.ts", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A Typescript based parser for the screenplay format Fountain. Source originally from Matt Daly's fountain.js", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc -p .", | ||
"test": "tsc -b test/ && mocha test/dist/test/*.js" | ||
"clean": "rimraf dist dist.esm", | ||
"build": "npm run clean && npm run build:cjs && npm run build:esm", | ||
"build:cjs": "tsc -b", | ||
"build:esm": "tsc -b ./tsconfig.esm.json", | ||
"test": "npm run build && ts-mocha test/*.ts" | ||
}, | ||
@@ -16,6 +19,10 @@ "keywords": [ | ||
], | ||
"homepage": "https://github.com/jonnygreenwald/Fountain.ts#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jonnygreenwald/Fountain.ts.git" | ||
"url": "git+https://github.com/jonnygreenwald/Fountain.ts.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/jonnygreenwald/Fountain.ts/issues" | ||
}, | ||
"author": "Jonny Greenwald", | ||
@@ -27,9 +34,10 @@ "contributors": [ | ||
"license": "MIT", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/assert": "^1.5.1", | ||
"@types/mocha": "^7.0.2", | ||
"mocha": "^7.2.0", | ||
"mocha": "^9.2.2", | ||
"rimraf": "^3.0.2", | ||
"ts-mocha": "^9.0.2", | ||
"typescript": "^3.9.5" | ||
} | ||
} |
{ | ||
"compilerOptions": { | ||
"target": "ES2016", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"lib": [ "ES2016" ], | ||
"target": "ES5", | ||
"moduleResolution": "node", | ||
"outDir": "dist" | ||
"outDir": "dist", | ||
"sourceMap": true | ||
}, | ||
"include": [ "src" ], | ||
"include": [ | ||
"./src/**/*.ts" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"samples", | ||
"samples" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
64388
47
876
0
1
6