<script src="https://cdn.rawgit.com/galaxykate/tracery/master/js/tracery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.0.0/codemirror.min.js"></script>
<div class="col-lg-12">
<h3>Numb3rs Grammar
<small>by <a href="https://adamsmith.as/">Adam Smith</a></small></h3>
<!-- Put your tracery grammar inside this #source textarea!-->
<textarea id="source">
{
"MATH": ["#CHARLIE# devises a mathematical approach to solving the crime and asks for more data.", "#CHARLIE# makes a math-based prediction."],
"GATHER_EVIDENCE": ["#FBI_AGENT# gathers evidence."],
"EVIDENCE_LOOP": ["#GATHER_EVIDENCE#", "#GATHER_EVIDENCE# #MATH#", "#GATHER_EVIDENCE# #MATH# #EVIDENCE_LOOP#"],
"FIGHT_CRIME": ["#CORE_MEET_CRIME# #FAMILY_DOWN# #EVIDENCE_LOOP# #FAMILY_DOWN# #RESOLUTION#"],
"RESOLUTION": ["#FBI_AGENT# and #FBI_AGENT# act on #CHARLIE#'s last prediction to finally discover how the crime really happened.", "#FBI_AGENT# and #FBI_AGENT# act on #CHARLIE#'s last prediction to stop crime before it could happen."],
"FAMILY_MEMBERS": ["#CHARLIE#, #DON#, and #ALAN#"],
"TV": ["the game"],
"DRINK": ["beer", "wine", "sake"],
"FOOD": ["a home cooked meal", "leftovers", "takeout"],
"TOGETHERNESS_ACTIVITY": ["#FOOD#", "#DRINK#", "#TV#"],
"FAMILY_TOGETHERNESS_SCENE": ["#FAMILY_MEMBERS# enjoy #TOGETHERNESS_ACTIVITY# and share kind words of understanding."],
"RESOLVE_FAMILY": ["#FAMILY_UP# #FAMILY_TOGETHERNESS_SCENE#"],
"FAMILY_DOWN": ["There is a scene where the family tension increases."],
"FAMILY_UP": ["There is a scene where part of the family tension is relieved."],
"CHARLIE_MEETS_CRIME": ["#DON# calls #CHARLIE# and informs him of the crime and #FBI_AGENT# provides details."],
"FBI_MEETS_CRIME": ["#FBI_AGENT# receives a tip.", "#FBI_AGENT# talks about ongoing investigation.", "#FBI_AGENT# gets a call."],
"OTHER_CHARACTER":...
var editor = CodeMirror.fromTextArea($('#source')[0], {
lineNumbers: true,
mode: {
name: "javascript",
json: true
}
});
// tracery in action
function generate() {
var source_text = editor.getValue();
var grammar = tracery.createGrammar(JSON.parse(source_text));
var example = grammar.flatten('#origin#');
$('#example').text(example);
}
// when text changes, generate expansion
editor.on('change', generate);
// when button clicked, generate expansion
$("#generate").on('click', generate);
// Tracery takes some time to load. Wait a second, then try to generate
setTimeout(generate, 1000);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.