Browse Source

added simple markdown parser to create html and text file. uses Markdown.NET and HtmlAgilityPack

Signed-off-by: Marcus Cuda <marcus@cuda.net>
pull/2/head
Marcus Cuda 17 years ago
parent
commit
440a41b8bd
  1. 4
      tools/MarkdownParser/.gitignore
  2. BIN
      tools/MarkdownParser/HtmlAgilityPack20/Html2Txt.dll
  3. BIN
      tools/MarkdownParser/HtmlAgilityPack20/HtmlAgilityPack.dll
  4. 33
      tools/MarkdownParser/HtmlAgilityPack20/License.txt
  5. 30
      tools/MarkdownParser/Markdown.NET/License.text
  6. BIN
      tools/MarkdownParser/Markdown.NET/anrControls.Markdown.NET.dll
  7. 8
      tools/MarkdownParser/Markdown.NET/readme.txt
  8. 71
      tools/MarkdownParser/MarkdownParser.csproj
  9. 20
      tools/MarkdownParser/MarkdownParser.sln
  10. 39
      tools/MarkdownParser/Program.cs
  11. 36
      tools/MarkdownParser/Properties/AssemblyInfo.cs

4
tools/MarkdownParser/.gitignore

@ -0,0 +1,4 @@
bin
obj
*.user
*.suo

BIN
tools/MarkdownParser/HtmlAgilityPack20/Html2Txt.dll

Binary file not shown.

BIN
tools/MarkdownParser/HtmlAgilityPack20/HtmlAgilityPack.dll

Binary file not shown.

33
tools/MarkdownParser/HtmlAgilityPack20/License.txt

@ -0,0 +1,33 @@
Copyright 2005-2007 Simon Mourier <simon underscore mourier at hotmail dot com>
Microsoft Public License (Ms-PL)
This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
A "contribution" is the original software, or any additions or changes to the software.
A "contributor" is any person that distributes its contribution under this license.
"Licensed patents" are a contributor's patent claims that read directly on its contribution.
2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
3. Conditions and Limitations
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.

30
tools/MarkdownParser/Markdown.NET/License.text

@ -0,0 +1,30 @@
Copyright (c) 2004, John Gruber
<http://daringfireball.net/>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name "Markdown" nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
This software is provided by the copyright holders and contributors "as
is" and any express or implied warranties, including, but not limited
to, the implied warranties of merchantability and fitness for a
particular purpose are disclaimed. In no event shall the copyright owner
or contributors be liable for any direct, indirect, incidental, special,
exemplary, or consequential damages (including, but not limited to,
procurement of substitute goods or services; loss of use, data, or
profits; or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.

BIN
tools/MarkdownParser/Markdown.NET/anrControls.Markdown.NET.dll

Binary file not shown.

8
tools/MarkdownParser/Markdown.NET/readme.txt

@ -0,0 +1,8 @@
========================================================
Markdown.NET --- a C# port of the original Markdown code
========================================================
ver 0.2.0.0 - Initial release
ver 1.0.1.7 - Code fixes to sync up with ver. 1.0.1b7 of the original Markdown
ver 1.0.1 - Code fixes to sync up with ver. 1.0.1 of the original Markdown. Also
from now on the code and binaries comes with a BSD license.

71
tools/MarkdownParser/MarkdownParser.csproj

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{4E991FAD-190C-4B19-BF9F-25783E9EC6C0}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MarkdownParser</RootNamespace>
<AssemblyName>MarkdownParser</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="anrControls.Markdown.NET, Version=1.0.1.1, Culture=neutral">
<SpecificVersion>False</SpecificVersion>
<HintPath>Markdown.NET\anrControls.Markdown.NET.dll</HintPath>
</Reference>
<Reference Include="Html2Txt, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>HtmlAgilityPack20\Html2Txt.dll</HintPath>
</Reference>
<Reference Include="HtmlAgilityPack, Version=1.3.0.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>HtmlAgilityPack20\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

20
tools/MarkdownParser/MarkdownParser.sln

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarkdownParser", "MarkdownParser.csproj", "{4E991FAD-190C-4B19-BF9F-25783E9EC6C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4E991FAD-190C-4B19-BF9F-25783E9EC6C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E991FAD-190C-4B19-BF9F-25783E9EC6C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E991FAD-190C-4B19-BF9F-25783E9EC6C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E991FAD-190C-4B19-BF9F-25783E9EC6C0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

39
tools/MarkdownParser/Program.cs

@ -0,0 +1,39 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using anrControls;
using HtmlAgilityPack.Samples;
namespace MarkdownParser
{
internal class Program
{
private static void Main(string[] args)
{
if (args.Length < 3)
{
Console.WriteLine("usage: MarkdownParser input_file html_output_file text_output_file");
Environment.Exit(-1);
}
if (!File.Exists(args[0]))
{
Console.WriteLine("{0} does not exist.", args[0]);
Environment.Exit(-1);
}
//convert markdown to html
var markdownSource = File.ReadAllText(args[0]);
var htmlSource = new Markdown().Transform(markdownSource);
File.WriteAllText(args[1], htmlSource);
//convert html to txt
var html2txt = new HtmlToText();
var text = html2txt.Convert(args[1]);
//use OS newlines
text = Regex.Replace(text, "(?<!\r)\n", Environment.NewLine);
Console.WriteLine(text);
File.WriteAllText(args[2], text);
}
}
}

36
tools/MarkdownParser/Properties/AssemblyInfo.cs

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MarkdownParser")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Math.NET")]
[assembly: AssemblyProduct("Math.NET Numerics")]
[assembly: AssemblyCopyright("Copyright © Math.NET 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("408b760e-5ee4-433c-a964-a644e765f217")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading…
Cancel
Save