fountain-js
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -9,2 +9,17 @@ # Change Log | ||
## [1.1.2] - 2023-09-17 | ||
### Fixed | ||
- a deep copy of `this.tokens` is created in order to perserve token text from being mutated by the inline lexer within `to_html`. **The text within tokens will no longer contain HTML.** | ||
### Notes | ||
- any token text will now need to be seperately lexed either by the `InlineLexer` class, a modified version of said class, or alternatively you can use `Fountain.to_html()` seperately if desired. | ||
### Changed | ||
- tokens can be accessed as traditionally through the `getTokens` parameter on `parse` or through the `tokens` property on the `Fountain` class itself. | ||
- the `regex` object and lexer classes like `Lexer` and `InlineLexer` can now be imported in order extend for additional token manipulation, particularly when it comes to lexing token text. | ||
## [1.1.1] - 2023-09-13 | ||
@@ -11,0 +26,0 @@ |
@@ -11,3 +11,3 @@ import { Token } from './token'; | ||
export declare class Fountain { | ||
private tokens; | ||
tokens: Token[]; | ||
private scanner; | ||
@@ -14,0 +14,0 @@ private inlineLex; |
@@ -15,10 +15,17 @@ import { Scanner } from './scanner'; | ||
try { | ||
let title; | ||
this.tokens = this.scanner.tokenize(script); | ||
let title = this.tokens.find(token => token.type === 'title'); | ||
const tokenCopy = JSON.parse(JSON.stringify(this.tokens)); | ||
const titleToken = this.tokens.find(token => token.type === 'title'); | ||
if (titleToken) { | ||
// lexes any inlines on the title then removes any HTML / line breaks | ||
title = this.inlineLex.reconstruct(titleToken.text) | ||
.replace('<br />', ' ') | ||
.replace(/<(?:.|\n)*?>/g, ''); | ||
} | ||
return { | ||
title: title ? this.inlineLex.reconstruct(title.text) | ||
.replace('<br />', ' ').replace(/<(?:.|\n)*?>/g, '') : undefined, | ||
title, | ||
html: { | ||
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('') | ||
title_page: tokenCopy.filter(token => token.is_title).map(token => this.to_html(token)).join(''), | ||
script: tokenCopy.filter(token => !token.is_title).map(token => this.to_html(token)).join('') | ||
}, | ||
@@ -25,0 +32,0 @@ tokens: getTokens ? this.tokens : undefined |
export * from './fountain'; | ||
export * from './token'; | ||
export { Token } from './token'; | ||
export { regex } from './regex'; | ||
export { Lexer, InlineLexer } from './lexer'; |
export * from './fountain'; | ||
export * from './token'; | ||
export { regex } from './regex'; | ||
export { Lexer, InlineLexer } from './lexer'; | ||
//# sourceMappingURL=index.js.map |
@@ -11,3 +11,3 @@ import { Token } from './token'; | ||
export declare class Fountain { | ||
private tokens; | ||
tokens: Token[]; | ||
private scanner; | ||
@@ -14,0 +14,0 @@ private inlineLex; |
@@ -18,10 +18,17 @@ "use strict"; | ||
try { | ||
let title; | ||
this.tokens = this.scanner.tokenize(script); | ||
let title = this.tokens.find(token => token.type === 'title'); | ||
const tokenCopy = JSON.parse(JSON.stringify(this.tokens)); | ||
const titleToken = this.tokens.find(token => token.type === 'title'); | ||
if (titleToken) { | ||
// lexes any inlines on the title then removes any HTML / line breaks | ||
title = this.inlineLex.reconstruct(titleToken.text) | ||
.replace('<br />', ' ') | ||
.replace(/<(?:.|\n)*?>/g, ''); | ||
} | ||
return { | ||
title: title ? this.inlineLex.reconstruct(title.text) | ||
.replace('<br />', ' ').replace(/<(?:.|\n)*?>/g, '') : undefined, | ||
title, | ||
html: { | ||
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('') | ||
title_page: tokenCopy.filter(token => token.is_title).map(token => this.to_html(token)).join(''), | ||
script: tokenCopy.filter(token => !token.is_title).map(token => this.to_html(token)).join('') | ||
}, | ||
@@ -28,0 +35,0 @@ tokens: getTokens ? this.tokens : undefined |
export * from './fountain'; | ||
export * from './token'; | ||
export { Token } from './token'; | ||
export { regex } from './regex'; | ||
export { Lexer, InlineLexer } from './lexer'; |
@@ -14,3 +14,7 @@ "use strict"; | ||
__exportStar(require("./fountain"), exports); | ||
__exportStar(require("./token"), exports); | ||
var regex_1 = require("./regex"); | ||
Object.defineProperty(exports, "regex", { enumerable: true, get: function () { return regex_1.regex; } }); | ||
var lexer_1 = require("./lexer"); | ||
Object.defineProperty(exports, "Lexer", { enumerable: true, get: function () { return lexer_1.Lexer; } }); | ||
Object.defineProperty(exports, "InlineLexer", { enumerable: true, get: function () { return lexer_1.InlineLexer; } }); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "fountain-js", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "A simple parser for Fountain, a markup language for formatting screenplays.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -75,3 +75,3 @@ # 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-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 Script object generated by Fountain-js. | ||
@@ -83,5 +83,16 @@ ``` javascript | ||
Below is a small sample of the `tokens` output from [Brick & Steel](samples/brick%26steel.fountain). | ||
Alternatively, you can also access the tokens directly from the `tokens` property of the class after parsing as well. | ||
``` javascript | ||
let output = fountain.parse(script); | ||
console.log(fountain.tokens); | ||
``` | ||
### Token Structure | ||
Version `1.0` of Fountain-js creates a flat token strucure and is not like a usual AST. | ||
Below is a small sample of the `tokens` output from [Brick & Steel](samples/brick%26steel.fountain): | ||
``` javascript | ||
[ | ||
@@ -155,4 +166,22 @@ ..., | ||
### Inline Lexing | ||
Originally, the text within tokens would have their inline markup, e.g. emphasis, underline, or line breaks, converted to HTML; however, given some use cases, this is not practical for all library users. | ||
As of version `1.1.2`, any inline markup will remain **unchanged** in the token text. | ||
```javascript | ||
[ | ||
... | ||
{ type: 'action', text: 'Screaming, chaos, *frenzy*.\nThree words that apply to this scene.' }, | ||
... | ||
] | ||
``` | ||
This means you'll have to perform an inline lex on the token text when processing your tokens. | ||
As a suggestion, one can import and extend the `InlineLexer` class. Its `inline` property and `reconstruct` method can be overwritten and modified to suit your needs if something other than HTML output is desired. | ||
## Fountain.ts | ||
For those looking for Fountain.ts, please note that this package has been deprecated in its original form and is now Fountain-js. Please source and upgrade packages from the [Fountain-js NPM package](https://www.npmjs.com/package/fountain-js) to receive all updates and fixes. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
93578
1430
185