Coder Social home page Coder Social logo

bryancostanich / fountainsharp Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 4.0 1.22 MB

An F# based Fountain Markdown processor that's based on the FSharp.Formatting library.

License: Apache License 2.0

F# 86.10% C# 7.93% PowerShell 3.55% Shell 2.42%

fountainsharp's Introduction

FountainSharp

Build Status

An F# based Fountain Markdown processor for use via .NET/Xamarin projects. FoutainSharp parses Fountain-formatted scripts and loads them into model that can be transformed or used for WYSIWYG editing.

It ships with a sample transformation engine that transforms Fountain markdown into HTML:

Image of a parsed script formatted in HTML

FountainSharp fully supports the entirety of the Fountain syntax and includes unit tests for all elements.

Consuming FountainSharp

FountainSharp is published as a NuGet package and can be added from the Package Manager Console:

Install-Package FountainSharp -Pre

Usage

FountainSharp can operate on an entire script, or just a portion and expects a string as an input and will output an in-memory representation as a FountainDocument. A convenience method that takes a Fountain-formatted string and outputs an HTML string is also provided.

Parsing a Script

To parse an entire script, simply call Fountain.Parse and pass a string:

var fountainDoc = FountainSharp.Parse.Fountain.Parse(script);

You can also just parse a snippet, which can be useful if you're writing an editor and only want to process changes:

var fountainDoc = FountainSharp.Parse.Fountain.Parse(script, (TODO));

You can also transform text straight to HTML. For example, the following code from the TestProjects/Fountainsharp.Editor project reads a file in and then updates a WebView with the html output:

var scriptResource = "FountainSharp.Editor.Scripts.SimpleTest.fountain";
string script;

using (var stream = Resource.FromPath (scriptResource)) {
	if (stream != null) {
		using (var reader = new System.IO.StreamReader (stream)) {
			script = reader.ReadToEnd ();

			this.MainTextView.Value = script;
			this.UpdateHtml ();

		}
	} else {
		Console.WriteLine ("Couldn't load " + scriptResource);
	}

}

protected void UpdateHtml ()
{
	System.Threading.Tasks.Task.Run (() => {

		InvokeOnMainThread (()=>{
			this.MainWebView.MainFrame.LoadHtmlString (HtmlFormatter.TransformHtml (this.MainTextView.Value), NSUrl.FromString (""));
		});
	});
}

Understanding a FountainDocument

A FountainDocument is an in-memory representation of a parsed fountain document and is represented as a List<FountainBlockElement>. A block represents a (possibly) multi-line element of a fountain document. Blocks include:

  • Action
  • Character
  • Dialogue
  • Parenthetical
  • Section
  • Synopses
  • Lyrics
  • SceneHeading
  • PageBreak
  • Transition
  • Centered
  • Boneyard
  • DualDialogue
  • TitlePage

Most blocks contain a List<FountainSpanElement> which represent inline formatting inside a block. This can be literal (with text), various formattings such as:

  • Literal
  • Bold
  • Italic
  • Underline
  • Note
  • HardLineBreak

Note that many FountainSpanElement objects can actually contain span elements.

TODO

This project is a work in progress. For a detailed list of outstanding tasks, see the TODO, however, in general the following major items are outstanding:

  • Custom HTML CSS - HTML transformation is largely done, but custom CSS templates should be allowed.

Contributing

For contributing, please see the Source Documentation. I <3 well documented pull requests. :)

License

FountainSharp is made available via the MIT License.

People

FountainSharp is based on the FSharp.Formatting library by Tomas Petricek.

Author

Bryan Costanich

Contributors

Gabor Nemeth

Thanks

Special thanks to Frank Krueger for tirelessly answering my F# questions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.