/*
OpenCollective - http://www.netbrick.net/ -- Version 0.73
Copyright (c) 2004
by Tyler Jensen ( tylerj@netbrick.net ) of NetBrick Inc. ( http://www.netbrick.net )
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
*/
using System;
using System.Text;
using System.Collections;
using System.Text.RegularExpressions;
using System.Web;
namespace OpenCollective.Engine
{
/// <summary>
/// Summary description for WikiConverter.
/// </summary>
public class WikiConverter
{
public WikiConverter()
{
//
// TODO: Add constructor logic here
//
}
private static string ReplaceNonBreakingSpaces(string link)
{
return Regex.Replace(link, " ", " ", RegexOptions.Compiled|RegexOptions.IgnoreCase);
}
public static string FormatHtmlToLines(string html)
{
html = html.Replace("\r", "");
html = html.Replace("\n", "");
//replace editor inserted hard space with soft space in links
MatchCollection links = Regex.Matches(html, @"(\[\[.*?\]\])", RegexOptions.Compiled|RegexOptions.IgnoreCase);
foreach(Match m in links)
{
string mc = m.ToString();
string nc = ReplaceNonBreakingSpaces(mc);
if(mc != nc)
html = html.Replace(mc, nc);
}
//insert line breaks for diff purposes
html = Regex.Replace(html, @"(<)(DIV|TD|P|TABLE|TR|HR|BR)(.*?>)", "\n$1$2$3", RegexOptions.Compiled|RegexOptions.IgnoreCase);
if(html.StartsWith("\n")) html = html.Substring(1, html.Length - 1);
/*
* <DIV><TD><P><TABLE><TR><HR><BR>
*
//Characters other than . $ ^ { [ ( | ) * + ? \ match themselves.
//first remove all new line elements
//<DIV><DIV class=hd1>Header Text </DIV></DIV><DIV> </DIV><DIV><DIV class=hd2>Header Text </DIV></DIV><DIV><DIV class=hd3>Header Text </DIV></DIV>
//replace headers
html = Regex.Replace(html, @"(<DIV><DIV class=hd1>)(.*?)(</DIV></DIV>)", "\n== $2 ==\n", RegexOptions.Compiled);
html = Regex.Replace(html, @"(<DIV><DIV class=hd2>)(.*?)(</DIV></DIV>)", "\n=== $2 ===\n", RegexOptions.Compiled);
html = Regex.Replace(html, @"(<DIV><DIV class=hd3>)(.*?)(</DIV></DIV>)", "\n==== $2 ====\n", RegexOptions.Compiled);
//do blank lines <DIV> </DIV>
html = Regex.Replace(html, @"(<DIV> </DIV>)", "\n \n", RegexOptions.Compiled);
//replace all divs as simple lines <DIV>[[mailto:user@domain.com|link caption]] </DIV>
html = Regex.Replace(html, @"(<DIV>)(.*?)(</DIV>)", "\n$2\n", RegexOptions.Compiled);
MatchCollection wTables = Regex.Matches(html, @"<TABLE.*?><TBODY>.*?</TBODY></TABLE>", RegexOptions.Compiled);
foreach (Match m in wTables)
{
string htmlTable = m.ToString();
string wikiTable = GetWikiTable(htmlTable);
html = html.Replace(htmlTable, wikiTable);
}
*/
return html;
}
private static string GetWikiTable(string htmlTable)
{
return "";
}
}
}