diff --git a/README.md b/README.md index 578649e..b229e40 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,14 @@ const d = new Diagram("foo", new Choice(0, "bar", "baz")); // Or use the functions that call the constructors for you import rr from "./railroad.js"; const d = rr.Diagram("foo", rr.Choice(0, "bar", "baz")); + +// Or use the JSON serialization of the diagram +import {Diagram} from "./railroad.js"; +const d = Diagram.fromJSON([ + { type: 'Terminal', text: 'foo' }. + { type: 'Choice', normalIndex: 0, options: [ + { type: 'Terminal', text: 'bar' }, { type: 'Terminal', text: 'baz' } + ] } ]); ``` Alternately, you can call ComplexDiagram(); @@ -55,7 +63,6 @@ The Diagram class also has a few methods: * `.toSVG()` outputs the diagram as an actual `` DOM element, ready for appending into a document. * `.addTo(parent?)` directly appends the diagram, as an `` element, to the specified parent element. If you omit the parent element, it instead appends to the script element it's being called from, so you can easily insert a diagram into your document by just dropping a tiny inline `