From 3a9f651efe3873e531da14acda0867811870a4f8 Mon Sep 17 00:00:00 2001 From: Michael Russo Date: Sat, 8 Nov 2014 09:12:32 -0500 Subject: [PATCH 1/2] Change directive syntax. `include:,reference:` vs. `#include,#reference`. --- README.md | 46 ++++++++++---------- mountain/join.py | 6 +-- mountain/mountain.py | 4 +- mountain/split.py | 6 +-- test/fixtures/complex/manifest.fountain | 52 +++++++++++------------ test/fixtures/complex/screenplay.fountain | 52 +++++++++++------------ test/fixtures/simple/manifest.fountain | 6 +-- test/fixtures/simple/screenplay.fountain | 6 +-- 8 files changed, 89 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index e4b66c1..bc04ef1 100644 --- a/README.md +++ b/README.md @@ -45,16 +45,16 @@ to make working with long Fountain documents more palatable._ Mountain makes use of two **directives**: -- `#include` -- `#reference` (and its companion, `/reference`) +- `include:` +- `reference:` (and its companion, `/reference`) A directive is metadata that is encoded inside of a Fountain note. (Fountain does not currently have first-class support for metadata.) -`#include` enables a Fountain document to reference another Fountain document. +`include:` enables a Fountain document to reference another Fountain document. -`#reference ... /reference` is used to wrap a document that has been inline -`#include`'d. +`reference: ... /reference` is used to wrap a document that has been inline +`include:`'d. (Examples are available in the tutorial, below.) @@ -92,7 +92,7 @@ _manifest.fountain_: = Meet the **Hero**. -[[#include intro.fountain]] +[[include: intro.fountain]] # ACT II @@ -100,13 +100,13 @@ _manifest.fountain_: ## Finale -[[#include the-end.fountain]] +[[include: the-end.fountain]] ``` This file probably looks similar to how most Fountain screenplays start out, -with the exception of the two notes that begin with `#include`. +with the exception of the two notes that begin with `include:`. -Here, `#include` is a directive that points to another file that should be +Here, `include:` is a directive that points to another file that should be included in its place. _intro.fountain_: @@ -139,7 +139,7 @@ _screenplay.fountain_: = Meet the **Hero**. -[[#reference intro.fountain]] +[[reference: intro.fountain]] FADE IN: @@ -151,7 +151,7 @@ FADE IN: ## Finale -[[#reference the-end.fountain]] +[[reference: the-end.fountain]] > FADE OUT. @@ -162,7 +162,7 @@ FADE IN: This new document is a combination of _manifest.fountain_ and each of the files referenced in the manifest (_intro.fountain_, _the-end.fountain_). These -referenced files are included in-line and wrapped in the `#reference ... +referenced files are included in-line and wrapped in the `reference: ... /reference` directives. Mountain works in both directions. To see this in action, edit the combined @@ -177,7 +177,7 @@ _screenplay.fountain_: ## The World -[[#reference intro.fountain]] +[[reference: intro.fountain]] FADE IN: @@ -191,7 +191,7 @@ A green, open field, stretching for miles in all directions. ## Finale -[[#reference the-end.fountain]] +[[reference: the-end.fountain]] > FADE OUT. @@ -230,7 +230,7 @@ _manifest.fountain_: ## The World -[[#include intro.fountain]] +[[include: intro.fountain]] # ACT II @@ -238,7 +238,7 @@ _manifest.fountain_: ## Finale -[[#include the-end.fountain]] +[[include: the-end.fountain]] ``` _intro.fountain_: @@ -257,25 +257,25 @@ be frequently jumping back and forth between these two modes. ### Additional Notes -- Use a relative file path in an `#include` directive (relative to the +- Use a relative file path in an `include:` directive (relative to the directory that the manifest file is located in). For example, if you write - `[[#include a.fountain]]`, then _a.fountain_ should be in the same folder as + `[[include: a.fountain]]`, then _a.fountain_ should be in the same folder as the manifest file. - Referenced files can be in different folders. For example, - `[[#include act iii/the-end.fountain]]` is legal (_the-end.fountain_ should + `[[include: act iii/the-end.fountain]]` is legal (_the-end.fountain_ should be located within a folder called _act iii_, relative to _manifest.fountain_'s directory). - Mountain works with any file extension, not just _.fountain_. -- If a file that does not exist is referenced in an `#include` directive, and - the `mountain join` command is executed, then the `#include` directive will +- If a file that does not exist is referenced in an `include:` directive, and + the `mountain join` command is executed, then the `include:` directive will remain in the resultant combined document. (It will not be converted to - `#reference ... \reference`, and an error will not be thrown.) + `reference: ... \reference`, and an error will not be thrown.) - Mountain does not support recursive includes (i.e., a file that is included - via `#include` can't itself include another file via `#include`). + via `include:` can't itself include another file via `include:`). ## Development diff --git a/mountain/join.py b/mountain/join.py index c0a4d72..260977f 100644 --- a/mountain/join.py +++ b/mountain/join.py @@ -20,7 +20,7 @@ def expand_manifest(manifest_path, combined_document_path): # All referenced files in the manifest are relative to this base path. base_path = os.path.dirname(manifest_path) - referenced_file_names = (re.compile("\[\[\s*#include\s+(\S.*?)\s*\]\]") + referenced_file_names = (re.compile("\[\[\s*include:\s+(\S.*?)\s*\]\]") .findall(manifest)) for file_name in referenced_file_names: @@ -34,9 +34,9 @@ def expand_manifest(manifest_path, combined_document_path): referenced_file = f.read() manifest = re.sub( - "\[\[\s*#include\s*?%s\s*\]\]" % re.escape(file_name), + "\[\[\s*include:\s*?%s\s*\]\]" % re.escape(file_name), "".join([ - "[[#reference %s]]" % file_name, + "[[reference: %s]]" % file_name, "\n" if referenced_file.startswith("\n") else "\n\n", referenced_file, "\n" if referenced_file.endswith("\n") else "\n\n", diff --git a/mountain/mountain.py b/mountain/mountain.py index fb8e11f..04008aa 100644 --- a/mountain/mountain.py +++ b/mountain/mountain.py @@ -30,7 +30,7 @@ def help(): overwritten if it already exists. The files referenced from must be referenced with the -[[#include file-path]] directive. +[[include: file-path]] directive. $ mountain split @@ -39,7 +39,7 @@ def help(): files will be overwritten if they already exist. All included files in must be indicated with the -[[#reference file-path]] ... [[/reference]] directive. +[[reference: file-path]] ... [[/reference]] directive. $ mountain --version diff --git a/mountain/split.py b/mountain/split.py index 52ffba5..65d2afd 100644 --- a/mountain/split.py +++ b/mountain/split.py @@ -20,7 +20,7 @@ def split_combined_document(manifest_path, combined_document_path): base_path = os.path.dirname(manifest_path) references = re.findall( - "\[\[#reference\s+(\S.*?)\]\](.*?)\[\[/reference\]\]", + "\[\[reference:\s+(\S.*?)\]\](.*?)\[\[/reference\]\]", combined_document, re.DOTALL) @@ -39,8 +39,8 @@ def split_combined_document(manifest_path, combined_document_path): queue_file_write(write_queue, file_path, file_contents) manifest = re.sub( - "\[\[#reference\s+%s\]\].*?\[\[/reference\]\]" % re.escape(file_name), - "[[#include %s]]" % file_name, + "\[\[reference:\s+%s\]\].*?\[\[/reference\]\]" % re.escape(file_name), + "[[include: %s]]" % file_name, manifest, 0, re.DOTALL diff --git a/test/fixtures/complex/manifest.fountain b/test/fixtures/complex/manifest.fountain index 24c06ac..1b79d20 100644 --- a/test/fixtures/complex/manifest.fountain +++ b/test/fixtures/complex/manifest.fountain @@ -1,80 +1,80 @@ # 1 -[[#include one.fountain]] +[[include: one.fountain]] ## 1.1 -[[#include one-one.fountain]] +[[include: one-one.fountain]] # 2 -[[#include two.fountain]] +[[include: two.fountain]] ## 2.1 -[[ #include part ii/one-a.fountain ]] +[[ include: part ii/one-a.fountain ]] -[[ #include part ii/one-b.fountain]] +[[ include: part ii/one-b.fountain]] -[[#include part ii/one-c.fountain ]] +[[include: part ii/one-c.fountain ]] -[[ #include part ii/one-d.fountain ]] +[[ include: part ii/one-d.fountain ]] ## 2.2 -[[#include part ii/two.txt]] +[[include: part ii/two.txt]] ## 2.3 -[[#include part ii/subpart iii/a.md]] +[[include: part ii/subpart iii/a.md]] -[[#include part ii/subpart iii/b.txt]] +[[include: part ii/subpart iii/b.txt]] ### 2.3.1 -[[#include part ii/subpart iii/1.fountain]] +[[include: part ii/subpart iii/1.fountain]] ### 2.3.2 -[[#include part ii/subpart iii/2.md]] +[[include: part ii/subpart iii/2.md]] ### 2.3.3 -[[#include part ii/subpart iii/3.txt]] +[[include: part ii/subpart iii/3.txt]] ### 2.3.4 -[[#include part ii/subpart iii/4.fountain]] +[[include: part ii/subpart iii/4.fountain]] ## 2.4 -[[#include part ii/four.txt]] +[[include: part ii/four.txt]] # 3 -[[#include three.fountain]] +[[include: three.fountain]] ## 3.1 -[[#include this-file-does-not-exist]] +[[include: this-file-does-not-exist]] -[[#include]] +[[include:]] -[[#include ]] +[[include: ]] -[[#include ]] +[[include: ]] -[[#include ]] +[[include: ]] ## 3.2 -[[#include three-two-a.fountain]] +[[include: three-two-a.fountain]] -[[#include three-two-b.fountain]] +[[include: three-two-b.fountain]] -[[#include three-two-c.fountain]] +[[include: three-two-c.fountain]] -[[#include three-two-d.fountain]] +[[include: three-two-d.fountain]] -[[#include three-two-e.fountain]] +[[include: three-two-e.fountain]] diff --git a/test/fixtures/complex/screenplay.fountain b/test/fixtures/complex/screenplay.fountain index 3052fd3..c51b02f 100644 --- a/test/fixtures/complex/screenplay.fountain +++ b/test/fixtures/complex/screenplay.fountain @@ -1,7 +1,7 @@ # 1 -[[#reference one.fountain]] +[[reference: one.fountain]] 1 @@ -9,7 +9,7 @@ ## 1.1 -[[#reference one-one.fountain]] +[[reference: one-one.fountain]] 1-1 @@ -17,7 +17,7 @@ # 2 -[[#reference two.fountain]] +[[reference: two.fountain]] 2 @@ -25,25 +25,25 @@ ## 2.1 -[[#reference part ii/one-a.fountain]] +[[reference: part ii/one-a.fountain]] 1-A [[/reference]] -[[#reference part ii/one-b.fountain]] +[[reference: part ii/one-b.fountain]] 1-B [[/reference]] -[[#reference part ii/one-c.fountain]] +[[reference: part ii/one-c.fountain]] 1-C [[/reference]] -[[#reference part ii/one-d.fountain]] +[[reference: part ii/one-d.fountain]] 1-D @@ -51,7 +51,7 @@ ## 2.2 -[[#reference part ii/two.txt]] +[[reference: part ii/two.txt]] 2 @@ -59,13 +59,13 @@ ## 2.3 -[[#reference part ii/subpart iii/a.md]] +[[reference: part ii/subpart iii/a.md]] A [[/reference]] -[[#reference part ii/subpart iii/b.txt]] +[[reference: part ii/subpart iii/b.txt]] B @@ -73,7 +73,7 @@ B ### 2.3.1 -[[#reference part ii/subpart iii/1.fountain]] +[[reference: part ii/subpart iii/1.fountain]] One @@ -81,7 +81,7 @@ One ### 2.3.2 -[[#reference part ii/subpart iii/2.md]] +[[reference: part ii/subpart iii/2.md]] Two @@ -89,7 +89,7 @@ Two ### 2.3.3 -[[#reference part ii/subpart iii/3.txt]] +[[reference: part ii/subpart iii/3.txt]] Three @@ -97,7 +97,7 @@ Three ### 2.3.4 -[[#reference part ii/subpart iii/4.fountain]] +[[reference: part ii/subpart iii/4.fountain]] Four @@ -105,7 +105,7 @@ Four ## 2.4 -[[#reference part ii/four.txt]] +[[reference: part ii/four.txt]] 4 @@ -113,7 +113,7 @@ Four # 3 -[[#reference three.fountain]] +[[reference: three.fountain]] 3 @@ -121,43 +121,43 @@ Four ## 3.1 -[[#include this-file-does-not-exist]] +[[include: this-file-does-not-exist]] -[[#include]] +[[include:]] -[[#include ]] +[[include: ]] -[[#include ]] +[[include: ]] -[[#include ]] +[[include: ]] ## 3.2 -[[#reference three-two-a.fountain]] +[[reference: three-two-a.fountain]] 3-2-A [[/reference]] -[[#reference three-two-b.fountain]] +[[reference: three-two-b.fountain]] 3-2-B [[/reference]] -[[#reference three-two-c.fountain]] +[[reference: three-two-c.fountain]] 3-2-C [[/reference]] -[[#reference three-two-d.fountain]] +[[reference: three-two-d.fountain]] 3-2-D [[/reference]] -[[#reference three-two-e.fountain]] +[[reference: three-two-e.fountain]] 3-2-E diff --git a/test/fixtures/simple/manifest.fountain b/test/fixtures/simple/manifest.fountain index d6ecc69..9d1d5a0 100644 --- a/test/fixtures/simple/manifest.fountain +++ b/test/fixtures/simple/manifest.fountain @@ -4,11 +4,11 @@ FADE IN: = Meet the **Hero**. -[[#include intro.fountain]] +[[include: intro.fountain]] ## Inciting Incident -[[#include inciting-incident.fountain]] +[[include: inciting-incident.fountain]] # ACT II @@ -16,7 +16,7 @@ FADE IN: ## Finale -[[#include the-end.fountain]] +[[include: the-end.fountain]] > FADE OUT. diff --git a/test/fixtures/simple/screenplay.fountain b/test/fixtures/simple/screenplay.fountain index f0d5c9e..845e529 100644 --- a/test/fixtures/simple/screenplay.fountain +++ b/test/fixtures/simple/screenplay.fountain @@ -4,7 +4,7 @@ FADE IN: = Meet the **Hero**. -[[#reference intro.fountain]] +[[reference: intro.fountain]] EXT. VAST OPEN SPACE - DAY @@ -22,7 +22,7 @@ We are about to embark on a fantastic voyage. ## Inciting Incident -[[#reference inciting-incident.fountain]] +[[reference: inciting-incident.fountain]] EXT. VAST OPEN SPACE - DAY [LATER] @@ -41,7 +41,7 @@ The world is swallowed up by buckets of torrential rain. ## Finale -[[#reference the-end.fountain]] +[[reference: the-end.fountain]] EXT. VAST OPEN SPACE - DAY [LATER] From 9f9ff7e4295cdbcec58c939713c6d51dff6547a8 Mon Sep 17 00:00:00 2001 From: Michael Russo Date: Sat, 8 Nov 2014 09:25:45 -0500 Subject: [PATCH 2/2] Add Changelog. --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index bc04ef1..6b14ba1 100644 --- a/README.md +++ b/README.md @@ -303,6 +303,23 @@ python setup.py test The tests use fixtures located at `./test/fixtures/`. +## Changelog + +### pending + +- Change directive syntax. `#include` is now `include:`, and `#reference` is + now `reference:`. [#2](https://github.com/mjrusso/mountain/pull/2), + [#4](https://github.com/mjrusso/mountain/pull/4) + +### v0.2.1 + +- Prevent crash when processing directives that expect arguments but do not + include non-whitespace characters. [#1](https://github.com/mjrusso/mountain/pull/1) + +### v0.2.0 + +- Initial release. + ## Copyright Copyright (c) 2014 [Michael Russo](http://mjrusso.com). See LICENSE for details.