1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
21 using Castle
.MonoRail
.Framework
;
24 /// Post process the request via Markdown
26 public class MarkdownTransformFilter
: TransformFilter
29 /// Constructor of the MarkdownTransformFilter
31 /// <param name="baseStream">output stream</param>
32 public MarkdownTransformFilter(Stream baseStream
) : base(baseStream
)
37 /// Pulls the http stream through the Markdown filter.
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
);