Fixe la génération du code LaTeX
This commit is contained in:
@ -10,6 +10,59 @@ using Microsoft.AspNet.Mvc.ViewFeatures;
|
||||
|
||||
namespace Yavsc.Helpers
|
||||
{
|
||||
public class TeXString {
|
||||
|
||||
public class Replacement {
|
||||
string target;
|
||||
string replacement;
|
||||
public Replacement(string target, string replacement){
|
||||
this.target=target;
|
||||
this.replacement=replacement;
|
||||
}
|
||||
public string Execute(string source)
|
||||
{
|
||||
return source.Replace(target,replacement);
|
||||
}
|
||||
}
|
||||
|
||||
public readonly static Replacement[] SpecialCharsToCommands =
|
||||
{
|
||||
new Replacement("<","\\textless"),
|
||||
new Replacement(">","\\textgreater"),
|
||||
new Replacement("©","\\copyright"),
|
||||
new Replacement("®","\\textregistered"),
|
||||
new Replacement("\\","\\textbackslash"),
|
||||
new Replacement("™","\\texttrademark"),
|
||||
new Replacement("¶","\\P"),
|
||||
new Replacement("|","\\textbar"),
|
||||
new Replacement("%","\\%"),
|
||||
new Replacement("{","\\{"),
|
||||
new Replacement("}","\\}"),
|
||||
new Replacement("_","\\_"),
|
||||
new Replacement("#","\\#"),
|
||||
new Replacement("$","\\$"),
|
||||
new Replacement("_","\\_"),
|
||||
new Replacement("¿","\\textquestiondown"),
|
||||
new Replacement("§","\\S"),
|
||||
new Replacement("£","\\pounds"),
|
||||
new Replacement("&","\\&"),
|
||||
new Replacement("¡","\\textexclamdown"),
|
||||
new Replacement("†","\\dag"),
|
||||
new Replacement("–","\\textendash")
|
||||
};
|
||||
string data;
|
||||
public TeXString(string str) {
|
||||
data = str;
|
||||
foreach (var r in SpecialCharsToCommands) {
|
||||
data = r.Execute(data);
|
||||
}
|
||||
}
|
||||
|
||||
override public string ToString()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
}
|
||||
public static class TeXHelpers
|
||||
{
|
||||
public static string NewLinesWith(this string target, string separator)
|
||||
@ -19,6 +72,13 @@ namespace Yavsc.Helpers
|
||||
|
||||
return string.Join(separator, items);
|
||||
}
|
||||
|
||||
public static TeXString ToTeX(string target, string lineSeparator="\n\\\\")
|
||||
{
|
||||
if (target==null) return null;
|
||||
return new TeXString(target.NewLinesWith(lineSeparator));
|
||||
}
|
||||
|
||||
public static string RenderViewToString(
|
||||
this Controller controller, IViewEngine engine,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
|
Reference in New Issue
Block a user