Add Newtonsoft.Json to the references of TestSiteBrail
[castle.git] / MonoRail / Castle.MonoRail.TransformFilters / MarkdownTransformFilter.cs
blob8bfb1af172ace529e4250b8a066b5a91bb7de46d
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.TransformFilters
17 using System;
18 using System.IO;
19 using System.Text;
20 using anrControls;
21 using Castle.MonoRail.Framework;
23 /// <summary>
24 /// Post process the request via Markdown
25 /// </summary>
26 public class MarkdownTransformFilter : TransformFilter
28 /// <summary>
29 /// Constructor of the MarkdownTransformFilter
30 /// </summary>
31 /// <param name="baseStream">output stream</param>
32 public MarkdownTransformFilter(Stream baseStream) : base(baseStream)
36 /// <summary>
37 /// Pulls the http stream through the Markdown filter.
38 /// </summary>
39 /// <param name="buffer">The content stream</param>
40 /// <param name="offset">Start of the stream</param>
41 /// <param name="count">Lenght of the stream</param>
42 public override void Write(byte[] buffer, int offset, int count)
44 if (Closed) throw new ObjectDisposedException("MarkdownTransformFilter");
46 string content = Encoding.Default.GetString(buffer, offset, count);
48 Markdown markdown = new Markdown();
49 content = markdown.Transform(content);
51 byte[] output = Encoding.Default.GetBytes(content);
52 BaseStream.Write(output,0, output.Length);