Dmitri Nesteruk avatar Dmitri Nesteruk committed 941dff9

mathjax support including wordpress $latex notation

Comments (0)

Files changed (9)

      Startup="ApplicationStartup" Exit="ApplicationExit" StartupUri="MainWindow.xaml">
   <Application.Resources>
   </Application.Resources>
-</Application>
+</Application>

MainWindow.xaml.cs

-using ContainerControlledLifetimeManager = Microsoft.Practices.Unity.ContainerControlledLifetimeManager;
+using mshtml;
+using ContainerControlledLifetimeManager = Microsoft.Practices.Unity.ContainerControlledLifetimeManager;
 
 namespace DmitriNesteruk.TypograFix
 {
 margin-top: 1.929em;
 margin-bottom: 0.643em; }" +
                            "</style>";
-      const string template = "<html><head>{0}{1}</head><body scroll='auto'></body></html>";
-      string everything = template.ƒ(encoding, style);
+      const string mathjax = @"
+<script type=""text/x-mathjax-config"">
+  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>
+<script type=""text/javascript"">
+function updateMath()
+{
+  MathJax.Hub.Queue([""Typeset"",MathJax.Hub]);
+}
+</script>";
+      const string template = "<html><head>{0}{1}{2}</head><body scroll='auto'></body></html>";
+      string everything = template.ƒ(encoding, mathjax, style);
       PreviewWebBrowser.NavigateToString(everything);
     }
 
                                        ConversionMessage = message;
                                        tbOut.Text = processedHtml;
 
-                                       //PreviewWebBrowser.NavigateToString(previewHtml);
-                                       dynamic doc = PreviewWebBrowser.Document;
+                                       //PreviewWebBrowser.NavigateToString(processedHtml);
+                                       dynamic doc = PreviewWebBrowser.Document as HTMLDocument;
                                        doc.body.innerHTML = processedHtml;
-
+                                       PreviewWebBrowser.InvokeScript("updateMath");
 
                                        PrintableDocument = Generator.Transform(tbIn.Text, App.PrintOptions, 5000);
                                        SymbolCount = SymbolCounter.CountNumberOfSymbols(processedHtml);
 		{BD49323F-FBCC-406E-9582-ECF054EAF7B0}.Release|Any CPU.ActiveCfg = Release|x64
 		{BD49323F-FBCC-406E-9582-ECF054EAF7B0}.Release|Mixed Platforms.ActiveCfg = Release|x64
 		{BD49323F-FBCC-406E-9582-ECF054EAF7B0}.Release|Mixed Platforms.Build.0 = Release|x64
-		{BD49323F-FBCC-406E-9582-ECF054EAF7B0}.Release|Win32.ActiveCfg = Release|Win32
-		{BD49323F-FBCC-406E-9582-ECF054EAF7B0}.Release|Win32.Build.0 = Release|Win32
+		{BD49323F-FBCC-406E-9582-ECF054EAF7B0}.Release|Win32.ActiveCfg = Release|x64
+		{BD49323F-FBCC-406E-9582-ECF054EAF7B0}.Release|Win32.Build.0 = Release|x64
 		{BD49323F-FBCC-406E-9582-ECF054EAF7B0}.Release|x64.ActiveCfg = Release|x64
 		{BD49323F-FBCC-406E-9582-ECF054EAF7B0}.Release|x64.Build.0 = Release|x64
 	EndGlobalSection
 		HideSolutionNode = FALSE
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
+		VisualSVNWorkingCopyRoot = 
 		EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.0\lib\NET35
-		VisualSVNWorkingCopyRoot = 
 	EndGlobalSection
 	GlobalSection(SpecExplorer.ActivityCompletionStatus) = preSolution
 		SpecExplorer.ActivityCompletionStatus = 

TypograFixImpl/Generator.cs

-using DmitriNesteruk.TypograFix;
-using DmitriNesteruk.TypograFixImpl.Generators;
-
-namespace DmitriNesteruk.TypograFixImpl
+namespace DmitriNesteruk.TypograFixImpl
 {
   using System;
   using System.Collections.Generic;
   using TypograFix.Common;
   using Microsoft.Practices.Unity;
   using System.Net;
+  using TypograFix;
+  using Generators;
 
   /// <summary>
   /// Beautifies HTML, adding all sorts of typographic embellishments.
     /// </summary>
     private readonly string[] codeTags = { "code", "pre" };
 	
-	// todo: ought to completely deprecate this - wastes CPU cycles
+	  // todo: ought to completely deprecate this - wastes CPU cycles
     private readonly IUnityContainer container;
     /// <summary>
     /// This stack stores a list of tags we're in.
                   string formatted = CodeFormat(theCode, languageMarker, options);
                   if (options.RasterizeCode)
                   {
-                    string converted = SourceCodeMarkupConverter.Convert(formatted)
+                    string converted = HtmlEncodedSourceCodeToMarkupConverter.Convert(formatted)
                       .Replace("<insertionpoint>", string.Empty);
                     string markup = string.Format("[{0}][{1}]{2}",
                       options.RasterizationFont, options.FreeformFontSize, converted);

TypograFixImpl/HtmlEncodedSourceCodeToMarkupConverter.cs

+namespace DmitriNesteruk.TypograFixImpl
+{
+  using System.Text.RegularExpressions;
+  using System.Net;
+
+  public class HtmlEncodedSourceCodeToMarkupConverter
+  {
+    /// <summary>
+		/// Converts html markup into renderable markup.
+		/// </summary>
+		/// <param name="html">Input HTML.</param>
+		/// <returns>You know what it returns ;)</returns>
+    public static string Convert(string html)
+    {
+      string result = html.Replace("[", @"\[")
+        .Replace("]", @"\]")
+        .Replace("<br/>", string.Empty); // original line breaks are enough :)
+      const string regex = "<font color=\\\".(......)\">";
+      result = Regex.Replace(result, regex,
+        m => m.Groups[1].Value.ToExpandedColor());
+      result = Regex.Replace(result, "<font ([^>])+>", string.Empty);
+      result = Regex.Replace(result, 
+        "<(/?)(pre|code|blockquote)>", string.Empty);
+      result = result.Replace("</font>", "[#000000000]");
+      result = result.Replace("<em>", "[i]").Replace("</em>", "[/i]");
+      return WebUtility.HtmlDecode(result);
+    }
+  }
+}

TypograFixImpl/HtmlManaBuilder2.cs

+using System.Globalization;
+
 namespace DmitriNesteruk.TypograFixImpl
 {
   using System.Text;
 
   public class HtmlManaBuilder2 : IManaBuilder
   {
+    private const string manaSpecialSymbols = "TSNX";
     private const string symbolsRootPath = "<img src=\"http://forums.mtgsalvation.com/images/smilies/mana{0}.gif\" alt=\"\"/>";
 
     public void AppendFromBuffer(string spec, StringBuilder sb)
 
     public bool HasSpecialSymbol(char symbol)
     {
-      return "TSNX".Contains(char.ToUpper(symbol).ToString());
+      return manaSpecialSymbols.Contains(char.ToUpper(symbol).ToString(CultureInfo.InvariantCulture));
     }
   }
 }

TypograFixImpl/SourceCodeMarkupConverter.cs

-namespace DmitriNesteruk.TypograFixImpl
-{
-  using System.Text.RegularExpressions;
-  using System.Net;
-
-  public class SourceCodeMarkupConverter
-  {
-    /// <summary>
-		/// Converts html markup into renderable markup.
-		/// </summary>
-		/// <param name="html">Input HTML.</param>
-		/// <returns>You know what it returns ;)</returns>
-    public static string Convert(string html)
-    {
-      string result = html.Replace("[", @"\[")
-        .Replace("]", @"\]")
-        .Replace("<br/>", string.Empty); // original line breaks are enough :)
-      const string regex = "<font color=\\\".(......)\">";
-      result = Regex.Replace(result, regex,
-        m => m.Groups[1].Value.ToExpandedColor());
-      result = Regex.Replace(result, "<font ([^>])+>", string.Empty);
-      result = Regex.Replace(result, 
-        "<(/?)(pre|code|blockquote)>", string.Empty);
-      result = result.Replace("</font>", "[#000000000]");
-      return WebUtility.HtmlDecode(result);
-    }
-  }
-}

TypograFixImpl/TypograFix.Impl.csproj

     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="RECT.cs" />
     <Compile Include="ShorthandManaBuilder.cs" />
-    <Compile Include="SourceCodeMarkupConverter.cs" />
+    <Compile Include="HtmlEncodedSourceCodeToMarkupConverter.cs" />
     <Compile Include="Generators\TableOfContentsGenerator.cs" />
     <Compile Include="Util.cs" />
   </ItemGroup>

Typografix.Bitmap/Typografix.Bitmap.vcxproj

     <UseOfAtl>Dynamic</UseOfAtl>
     <CharacterSet>Unicode</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
-    <PlatformToolset>Intel C++ Compiler XE 12.1</PlatformToolset>
+    <PlatformToolset>Intel C++ Compiler XE 12.0</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release no C++|Win32'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseOfAtl>Dynamic</UseOfAtl>
     <CharacterSet>Unicode</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
-    <PlatformToolset>Intel C++ Compiler XE 12.1</PlatformToolset>
+    <PlatformToolset>Intel C++ Compiler XE 12.0</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseOfAtl>Dynamic</UseOfAtl>
     <CharacterSet>Unicode</CharacterSet>
     <CLRSupport>true</CLRSupport>
-    <PlatformToolset>Intel C++ Compiler XE 12.1</PlatformToolset>
+    <PlatformToolset>Intel C++ Compiler XE 12.0</PlatformToolset>
+    <InterproceduralOptimization>false</InterproceduralOptimization>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug no C++|Win32'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseOfAtl>Dynamic</UseOfAtl>
     <CharacterSet>Unicode</CharacterSet>
     <CLRSupport>true</CLRSupport>
-    <PlatformToolset>Intel C++ Compiler XE 12.1</PlatformToolset>
+    <PlatformToolset>Intel C++ Compiler XE 12.0</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
     <WholeProgramOptimization>false</WholeProgramOptimization>
-    <PlatformToolset>Intel C++ Compiler XE 12.1</PlatformToolset>
+    <PlatformToolset>Intel C++ Compiler XE 12.0</PlatformToolset>
     <UseIntelIPP>true</UseIntelIPP>
     <UseIntelTBB>true</UseIntelTBB>
     <UseIntelMKL>Parallel</UseIntelMKL>
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
     <WholeProgramOptimization>false</WholeProgramOptimization>
-    <PlatformToolset>Intel C++ Compiler XE 12.1</PlatformToolset>
+    <PlatformToolset>Intel C++ Compiler XE 12.0</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
-    <PlatformToolset>Intel C++ Compiler XE 12.1</PlatformToolset>
+    <PlatformToolset>Intel C++ Compiler XE 12.0</PlatformToolset>
     <UseIntelIPP>true</UseIntelIPP>
     <UseIntelTBB>true</UseIntelTBB>
     <UseIntelMKL>Parallel</UseIntelMKL>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug no C++|x64'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <CharacterSet>Unicode</CharacterSet>
-    <PlatformToolset>Intel C++ Compiler XE 12.1</PlatformToolset>
+    <PlatformToolset>Intel C++ Compiler XE 12.0</PlatformToolset>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.