1. Dmitri Nesteruk
  2. TypograFix

Commits

Dmitri Nesteruk  committed 80922a1

started on latex support

  • Participants
  • Parent commits 04169f2
  • Branches intel

Comments (0)

Files changed (8)

File MainWindow.xaml

View file
               <ColumnDefinition Width="*" />
               <ColumnDefinition Width="Auto"/>
             </Grid.ColumnDefinitions>
-            <TextBlock Margin="10,5,5,5" TextWrapping="Wrap" 
+            <TextBlock Margin="10,5,5,5" TextWrapping="WrapWithOverflow" 
                VerticalAlignment="Center"
                Grid.Column="0" HorizontalAlignment="Left">
               <Run FontWeight="Bold">Preview </Run>
                Grid.ColumnSpan="1" VerticalAlignment="Center" Name="InputLinksBlock" >
               <Image Source="/Resources/document.png" Width="16" Height="16"/>
               <Run FontWeight="Bold">Html </Run>
+                <Hyperlink Name="lnkDecreaseFont" Foreground="Gray" Click="OnDecreaseFont">--</Hyperlink>
+                <Hyperlink Name="lnkIncreaseFont" Foreground="Gray" Click="OnIncreaseFont">++</Hyperlink>
                 <Hyperlink Name="lnkPaste" Foreground="White" Click="OnPaste">»paste from clipboard</Hyperlink>
                 <Hyperlink Name="lnkClear" Foreground="White" Click="OnClear">»clear</Hyperlink>
                 <Hyperlink Name="lnkCharmap" Foreground="White" Click="OnCharMap">»charmap</Hyperlink>
               <TabItem.Header>
                 <TextBlock>
             <Image Source="/Resources/html.png" Width="16" Height="16"/>
-            <Run Foreground="Black" BaselineAlignment="Center">Preview</Run>
+              <Run Foreground="Black" BaselineAlignment="Center">Preview</Run>
                 </TextBlock>
               </TabItem.Header>
               <WebBrowser Name="PreviewWebBrowser"/>

File MainWindow.xaml.cs

View file
 
       const string mathjax = @"
 <script type=""text/x-mathjax-config"">
-  MathJax.Hub.Config({tex2jax: {inlineMath: [['$latex','$'], ['\\(','\\)']]}});
+  MathJax.Hub.Config({tex2jax: {inlineMath: [['$latex','$'], ['$','$'], ['\\(','\\)']]}});
 </script>
-<script type=""text/javascript""
-  src=""http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"">
+<script type=""text/javascript"" src=""http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"">
 </script>
 <script type=""text/javascript"">
 function updateMath()
         SavePanel.Children.RemoveRange(1, SavePanel.Children.Count-1);
       }
     }
+
+    private void OnIncreaseFont(object sender, RoutedEventArgs e)
+    {
+      tbIn.FontSize *= 1.2;
+    }
+
+    private void OnDecreaseFont(object sender, RoutedEventArgs e)
+    {
+      tbIn.FontSize /= 1.2;
+    }
   }
 }

File Tests/TransformTests.cs

View file
 using System;
+using DmitriNesteruk.TypograFix;
 using DmitriNesteruk.TypograFix.Common;
 using DmitriNesteruk.TypograFixImpl;
 using NUnit.Framework;
 namespace TypograFix.Tests
 {
   /// <summary>
-  ///   Transformation tests.
+  /// Transformation tests.
   /// </summary>
   [TestFixture]
   public class TransformTests : ParallelizedTestFixture

File TypograFix.Common/Options/PostprocessingOptions.cs

View file
-namespace DmitriNesteruk.TypograFix.Common
+using System.ComponentModel;
+
+namespace DmitriNesteruk.TypograFix
 {
   public enum PostprocessingOptions
   {
     None,
-    HtmlToConfluence
+    HtmlToConfluence,
+    [Description("LaTeX")]
+    HtmlToLaTeX
   }
 }

File TypograFix.sln.DotSettings

View file
+<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
+	<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String>
+	<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String></wpf:ResourceDictionary>

File TypograFixImpl/Generator.cs

View file
           case PostprocessingOptions.HtmlToConfluence:
             result = new HtmlToConfluenceConverter().Convert(result);
             break;
+          case PostprocessingOptions.HtmlToLaTeX:
+            result = new HtmlToLatexConverter().Convert(result);
+            break;
         }
         #endregion
 

File TypograFixImpl/HtmlToLatexConverter.cs

View file
+using System.Collections.Generic;
+using System.Text;
+
+namespace DmitriNesteruk.TypograFixImpl
+{
+  public class HtmlToLatexConverter : IPipelineConverter
+  {
+    private static readonly Dictionary<string, string> replacementDictionary;
+
+    static HtmlToLatexConverter()
+    {
+      replacementDictionary = new Dictionary<string, string>
+      {
+        {"<p>", "\n"},
+        {"</p>", ""},
+
+        {"<br/>", "\n"},
+
+        {"<h1>", "\\section{"},
+        {"</h1>", "}"},
+
+        {"<h2>", "\\subsection{"},
+        {"</h2>", "}"},
+
+        {"<h3>", "\\subsubsection{"},
+        {"</h3>", "}"},
+
+        {"<h4>", "\\subsubsubsection{"},
+        {"</h4>", "}"},
+
+        {"<h5>", "\\subsubsubsubsection{"},
+        {"</h5>", "}"},
+
+        {"<h6>", "\\subsubsubsubsubsection{"}, // ridiculous
+        {"</h6>", "}"},
+
+        {"<em>", "\\textit{"},
+        {"</em>", "}"},
+
+        {"<strong>", "\\textbf{"},
+        {"</strong>", "}"},
+
+        {"<code>", "\\begin{fsharp}"},
+        {"</code>", "\\end{fharp}"}, // dirty hack?
+
+        {"<ul>", "\\begin{compactitem}"},
+        {"</ul>", "\\end{compactitem}"},
+
+        {"<ol>", "\\begin{itemize}"},
+        {"</ol>", "\\end{itemize}"},
+
+        {"<li>\n", "\\item"},
+        {"  <li>", "\\item"},
+        {"<li>", "\\item"},
+        {"</li>", ""}
+      };
+    }
+
+    public string Convert(string source)
+    {
+      var sb = new StringBuilder(source);
+      foreach (var r in replacementDictionary)
+        sb.Replace(r.Key, r.Value);
+      return sb.ToString();
+    }
+  }
+}

File TypograFixImpl/TypograFix.Impl.csproj

View file
     <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="Microsoft.ExceptionMessageBox, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL" />
+    <Reference Include="Microsoft.ExceptionMessageBox, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
+      <HintPath>..\lib\Microsoft.ExceptionMessageBox.dll</HintPath>
+    </Reference>
     <Reference Include="Microsoft.Msagl, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\lib\Microsoft.Msagl.dll</HintPath>
     <Compile Include="Generator.cs" />
     <Compile Include="HtmlManaBuilder2.cs" />
     <Compile Include="HtmlToConfluenceConverter.cs" />
+    <Compile Include="HtmlToLatexConverter.cs" />
     <Compile Include="IManaBuilder.cs" />
     <Compile Include="IPipelineConverter.cs" />
     <Compile Include="ManaSymbolProcessor.cs" />