function main(state) {
	
    try {
        var options = {};
        if (state.text.trim().toLowerCase() === "help"){
            state.fullText = getHelpText();
        } else if (state.fullText.trim() === ""){
            state.fullText = JSON.stringify(getDefaultParameters());
        } else {
            options = JSON.parse(state.text);

            var indexEntries = "0ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            var header = getHeader();
            var sectionTemplate = getSectionTemplate();
            var sampleEntries = getSampleEntries();

            var index = "\r\n";
            var body = "";
            for (var x = 0; x < indexEntries.length; x++)
            {
                var c = indexEntries.charAt(x);

                // Build Index
                index = index + "[" + c + "](#" + c.toLowerCase() + ") "
                if (c === "H" || c === "Q" || c === "Z") index = index + "\r\n";

                // Build Sections
                var section = sectionTemplate.replace("{idx}", c)
                if (c === "E" && options.includeSamples){
                    section = section.replace("{samples}", sampleEntries);
                } else {
                    section = section.replace("{samples}", "");
                }
                body = body + section
            }

            // Put it all together
            var glossary = header + index + body;
            
            state.fullText = glossary.replace("{projectName}", options.projectName);
        }
	}
	catch(error) {
        options = getDefaultParameters();
        options.error = error.toString();
        state.fullText = JSON.stringify(options);
        //state.text = error.toString()
		state.postError(error.toString())
	}
	
}
{
		"api":1,
		"name":"Create Project Glossary Markdown File",
		"description":"Type 'help' and run this script for instructions.",
		"author":"Terry L. Lewis",
		"icon":"colosseum",
        "tags":"markdown,glossary",
        "bias":0.0
	}