fountain.ts
Advanced tools
Comparing version 0.1.0 to 0.1.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Fountain = void 0; | ||
var scanner_1 = require("./scanner"); | ||
@@ -4,0 +5,0 @@ var lexer_1 = require("./lexer"); |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./fountain")); | ||
__exportStar(require("./fountain"), exports); | ||
__exportStar(require("./token"), exports); |
@@ -16,2 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InlineLexer = exports.Lexer = void 0; | ||
var regex_1 = require("./regex"); | ||
@@ -18,0 +19,0 @@ var Lexer = /** @class */ (function () { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.regex = void 0; | ||
exports.regex = { | ||
@@ -4,0 +5,0 @@ title_page: /^((?:title|credit|author[s]?|source|notes|draft date|date|contact|copyright)\:)/gim, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Scanner = void 0; | ||
var regex_1 = require("./regex"); | ||
@@ -4,0 +5,0 @@ var lexer_1 = require("./lexer"); |
{ | ||
"name": "fountain.ts", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A Typescript based parser for the screenplay format Fountain. Source originally from Matt Daly's fountain.js", | ||
@@ -8,4 +8,3 @@ "main": "dist/index.js", | ||
"build": "tsc -p .", | ||
"test": "tsc -b test/ && mocha test/dist/test/*.js", | ||
"playground": "tsc -b test/ && node test/dist/test/fountiants_playground.js" | ||
"test": "tsc -b test/ && mocha test/dist/test/*.js" | ||
}, | ||
@@ -30,7 +29,7 @@ "keywords": [ | ||
"devDependencies": { | ||
"@types/assert": "^1.4.6", | ||
"@types/mocha": "^7.0.1", | ||
"mocha": "^7.0.1", | ||
"typescript": "^3.7.5" | ||
"@types/assert": "^1.5.1", | ||
"@types/mocha": "^7.0.2", | ||
"mocha": "^7.2.0", | ||
"typescript": "^3.9.5" | ||
} | ||
} |
@@ -6,5 +6,5 @@ Fountain-ts | ||
# Syntax Support | ||
## Syntax Support | ||
Supports *most* of the Fountain syntax. | ||
Supports *most* of the Fountain syntax. Based on the latest version of fountain-js. | ||
@@ -15,65 +15,47 @@ Currently fountain-ts supports a limited range of key-value pairs for title pages - | ||
<!-- Work is being done to make title page parsing friendlier, allowing custom key-value pairs, but as of version 0.1.0 only the above are supported. | ||
## How To | ||
Instructions | ||
============ | ||
Fountain-ts behaves as fountain-js does. Import `Fountain` and create a new instance of it. | ||
fountain-js accepts a string value to it's parse function, therefore opening or retrieving files is down to you - open the file, retrieve it's string contents and pass it to fountain-js. | ||
``` Typescript | ||
import { Fountain } from 'fountain'; | ||
``` | ||
The parser doesn't simply change scripts lines in to html, it first splits the script down line by line and generates an array of tokens representing each script element. This tokenized array provides the opportunity to iterate over a script in it's raw state and do some analysis (e.g. we could search for every character element with the name STEEL, we could do this against the HTML using jQuery but it'd be a slower process). By default, fountain-js simply returns the generated html, but you can also gain access to those tokens if you ask for them (more on that below). | ||
The output provided by Fountain-ts is an object literal of the format `{ title: '...', html: { title_page: '...', script: '...' } }`. | ||
To use Fountain.js, either import it within an HTML page or require it as a module inside Node.js (it's available to both by default). | ||
An example. | ||
``` | ||
<script type="text/javascript" src="fountain.js"></script> | ||
<script type="text/javascript"> | ||
var file = ... open the file from somewhere and get it's string value ... | ||
var output = fountain.parse(file); | ||
</script> | ||
``` | ||
``` Typescript | ||
import { Fountain, Script } from 'fountain'; | ||
import * as assert from 'assert'; | ||
fountain-js supports both sync and async functionality, the function names remain the same. For async, simply attach a callback to the parse function and handle the result inside that callback. | ||
let text = `.OPENING TITLES | ||
``` | ||
<script type="text/javascript" src="fountain.js"></script> | ||
<script type="text/javascript"> | ||
var file = ... open the file from somewhere and get it's string value ... | ||
fountain.parse(file, function (output) { | ||
// do something | ||
}); | ||
</script> | ||
``` | ||
> BRICK & STEEL < | ||
> FULL RETIRED < | ||
The output provided by fountain-js is of a specific format. The output to both sync and async functions is an object literal of the format { title: '...', html: { title_page: '...', script: '...' } }. If a title was set in the original file the title property will be set to it (as plain text with formatting removed), the html.title_page property contains the html generated for any title page syntax definitions, and the html.script property contains the html generated for the rest of the script. | ||
SMASH CUT TO:`; | ||
let fountain = new Fountain(); | ||
let output: Script = fountain.parse(text), | ||
actual: string = output.html.script; | ||
const expected = '<h3>OPENING TITLES</h3><p class="centered">BRICK & STEEL <br /> FULL RETIRED</p><h2>SMASH CUT TO:</h2>'; | ||
assert.equal(actual, expected); | ||
``` | ||
<script type="text/javascript" src="fountain.js"></script> | ||
<script type="text/javascript"> | ||
var file = ... open the file from somewhere and get it's string value ... | ||
fountain.parse(file, function (output) { | ||
// output.title - 'Big Fish' | ||
// output.html.title_page - '<h1>Big Fish</h1><p class="author">...' | ||
// output.html.script - '<h2><span class="bold">FADE IN:</span></h2>...' | ||
}); | ||
</script> | ||
``` | ||
If you want access to the tokens that fountain-js generates, simply attach a true parameter to your parse calls. Requesting tokens adds a tokens property to the output generated by fountain-js. That tokens property is an array of object literals, each of the form { type: '...', text: '...' }, some elements have additional properties (e.g. the type 'scene_heading' also has a property called 'scene-number' if a scene number was attached to that specific scene heading). It should also be noted that fountain-js iterates the script from bottom to top, therefore requesting tokens requires reversing the array before fountain-js returns you the data, this might add a slight delay (milliseconds in most cases) on large scripts. | ||
### Parser Tokens | ||
Like fountain-js, if you want access to the tokens that Fountain-js generates, simply attach a `true` parameter to your parse calls. Requesting tokens adds a tokens property to the output generated by Fountain-ts. | ||
``` Typescript | ||
let output: Script = fountain.parse(script, true); | ||
console.log(output.tokens); | ||
``` | ||
<script type="text/javascript" src="fountain.js"></script> | ||
<script type="text/javascript"> | ||
var file = ... open the file from somewhere and get it's string value ... | ||
fountain.parse(file, true, function (output) { | ||
// output.title - 'Big Fish' | ||
// output.html.title_page - '<h1>Big Fish</h1><p class="author">...' | ||
// output.html.script - '<h2><span class="bold">FADE IN:</span></h2>...' | ||
// output.tokens - [ ... { type: 'transition'. text: '<span class="bold">FADE IN:</span>' } ... ] | ||
}); | ||
</script> | ||
``` | ||
The tokens for the Brick & Steel sample found on the fountain.io website would look as follows (just a small sample): | ||
``` | ||
``` Javascript | ||
[ | ||
@@ -110,2 +92,2 @@ ..., | ||
As you can see fountain-js attaches some extra tokens, such as 'dialogue_begin' and 'dialogue_end'. These are used to block together sections, in the case of dialogue it allows fountain-js to attach a dual dialogue property to blocks of dialogue. --> | ||
Just like fountain-js, Fountain-ts attaches some extra tokens, such as 'dialogue_begin' and 'dialogue_end'. These are used to block together sections, in the case of dialogue it allows Fountain-ts to attach a dual dialogue property to blocks of dialogue. |
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
23
600
31866
91