/// <summary> /// The main application page used to preview transform results. /// </summary> /// <param name="language">The code highlight language to preview.</param> /// <returns>The Index view.</returns> public ActionResult Index(string language) { if (string.IsNullOrEmpty(language)) { language = DefaultLanguage; } string sourcePath = Server.MapPath( Path.Combine(InputPath, string.Format(InputFormat, language))); string destPath = Server.MapPath(Path.Combine(OutputPath, string.Format(OutputFormat, language))); Options options = new Options() { DebugInfo = true, }; string transformFileName = string.Format(TransformFormat, language); string transformResult = new Highlighter(Server.MapPath(InputPath), options) .Transform(System.IO.File.ReadAllText(sourcePath), language); System.IO.File.WriteAllText(destPath, transformResult); ViewBag.Title = language; ViewBag.HighlightOutput = new HtmlString(transformResult); ViewBag.TransformDefinition = TransformDefinitionFactory.Load( InputPath, language, options); ViewBag.TransformPath = string.Format( TransformRequestFormat, transformFileName); return(this.View()); }
/// <summary> /// Transform the code by adding highlight markup and styles to recognized tokens. /// </summary> /// <param name="code">The code block to transform.</param> /// <param name="type">The code block type.</param> /// <returns>The transformed block.</returns> public string Transform(string code, string type) { this.transformDefinition = TransformDefinitionFactory.Load( this.transformPath, type, this.options); this.buffer = new Buffer( code, this.transformDefinition.Patterns[SeparatorsPattern], this.options); while (!this.buffer.Eof) { if (!this.transformDefinition.Apply(this.buffer)) { this.buffer.SkipToken(); } this.buffer.NextToken(); } return(this.buffer.Data); }