mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Changed paste to use backend syntax highlighting by pygments instead of a JS method.
This commit is contained in:
parent
e1ed311880
commit
04c2e657ab
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
|
@ -6,6 +6,7 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using FearTheCowboy.Pygments;
|
||||
using Teknik.Areas.Error.Controllers;
|
||||
using Teknik.Areas.Paste.ViewModels;
|
||||
using Teknik.Areas.Users.Utility;
|
||||
@ -97,6 +98,17 @@ namespace Teknik.Areas.Paste.Controllers
|
||||
model.Content = Encoding.Unicode.GetString(data);
|
||||
}
|
||||
|
||||
if (type.ToLower() == "full" || type.ToLower() == "simple")
|
||||
{
|
||||
// Transform content into HTML
|
||||
if (Highlighter.Lexers.ToList().Exists(l => l.Name == model.Syntax))
|
||||
{
|
||||
Highlighter highlighter = new Highlighter();
|
||||
// Add a space in front of the content due to bug with pygment (No idea why yet)
|
||||
model.Content = highlighter.HighlightToHtml(" " + model.Content, model.Syntax, Config.PasteConfig.SyntaxVisualStyle, generateInlineStyles: true, fragment: true);
|
||||
}
|
||||
}
|
||||
|
||||
switch (type.ToLower())
|
||||
{
|
||||
case "full":
|
||||
|
@ -1,5 +0,0 @@
|
||||
onmessage = function (event) {
|
||||
importScripts(event.data.script);
|
||||
var result = self.hljs.highlightAuto(event.data.code);
|
||||
postMessage(result);
|
||||
}
|
@ -30,26 +30,6 @@
|
||||
</div>
|
||||
<br />
|
||||
<div class="row">
|
||||
<div class="col-sm-10 col-sm-offset-1">
|
||||
<pre><code class="@syntax" id="code">@Model.Content</code></pre>
|
||||
<div class="col-sm-10 col-sm-offset-1">@Html.Raw(Model.Content)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
addEventListener('load', function () {
|
||||
var code = document.querySelector('#code');
|
||||
var language = document.querySelector('#syntaxLanguage');
|
||||
var worker = new Worker(GenerateBlobURL('@Scripts.Url("~/bundles/syntaxWorker")'));
|
||||
worker.onmessage = function (event) {
|
||||
code.innerHTML = event.data.value;
|
||||
language.innerText = event.data.language;
|
||||
}
|
||||
var scriptBlob = GenerateBlobURL('@Scripts.Url("~/bundles/highlight")');
|
||||
var obj = {
|
||||
script: scriptBlob,
|
||||
code: code.textContent
|
||||
};
|
||||
worker.postMessage(obj);
|
||||
})
|
||||
</script>
|
@ -1,6 +1,7 @@
|
||||
@model Teknik.Areas.Paste.ViewModels.PasteCreateViewModel
|
||||
|
||||
@using Teknik.Helpers
|
||||
@using FearTheCowboy.Pygments
|
||||
|
||||
@Styles.Render("~/Content/paste")
|
||||
@Scripts.Render("~/bundles/paste")
|
||||
@ -32,10 +33,12 @@
|
||||
<label for="syntax" class="col-sm-2 col-sm-offset-1 control-label">Syntax</label>
|
||||
<div class="col-sm-4">
|
||||
<select class="form-control" name="Syntax" id="syntax">
|
||||
<option value="auto-detect">Auto Detect</option>
|
||||
@foreach (KeyValuePair<string, string> format in Constants.HIGHLIGHTFORMATS)
|
||||
<option value="Text only">Text only</option>
|
||||
@{
|
||||
foreach (Highlighter.Lexer format in Highlighter.Lexers.OrderBy(l => l.Name))
|
||||
{
|
||||
<option value="@format.Value">@format.Key</option>
|
||||
<option value="@format.Name">@format.Name</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
@ -23,22 +23,8 @@
|
||||
|
||||
</head>
|
||||
<body data-twttr-rendered="true">
|
||||
<pre><code class="@syntax" id="code">@Model.Content</code></pre>
|
||||
@Html.Raw(Model.Content)
|
||||
<script>
|
||||
addEventListener('load', function () {
|
||||
var code = document.querySelector('#code');
|
||||
var worker = new Worker(GenerateBlobURL('@Scripts.Url("~/bundles/syntaxWorker")'));
|
||||
worker.onmessage = function (event) {
|
||||
code.innerHTML = event.data.value;
|
||||
}
|
||||
var scriptBlob = GenerateBlobURL('@Scripts.Url("~/bundles/highlight")');
|
||||
var obj = {
|
||||
script: '@Scripts.Url("~/bundles/highlight")',
|
||||
code: code.textContent
|
||||
};
|
||||
worker.postMessage(obj);
|
||||
})
|
||||
|
||||
function pageloadStopTimer() { }
|
||||
</script>
|
||||
</body>
|
||||
|
@ -12,6 +12,7 @@ namespace Teknik.Configuration
|
||||
public int UrlLength { get; set; }
|
||||
public int KeySize { get; set; }
|
||||
public int BlockSize { get; set; }
|
||||
public string SyntaxVisualStyle { get; set; }
|
||||
|
||||
public PasteConfig()
|
||||
{
|
||||
@ -19,6 +20,7 @@ namespace Teknik.Configuration
|
||||
UrlLength = 5;
|
||||
KeySize = 256;
|
||||
BlockSize = 128;
|
||||
SyntaxVisualStyle = "vs";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,144 +13,5 @@ namespace Teknik.Helpers
|
||||
public const string TRUSTEDDEVICECOOKIE = "TeknikTrustedDevice";
|
||||
public const string LOGO_PATH = "~/Images/logo-black.svg";
|
||||
public const string FAVICON_PATH = "~/Images/favicon.ico";
|
||||
|
||||
// Paste Constants
|
||||
public static Dictionary<string, string> HIGHLIGHTFORMATS = new Dictionary<string, string>()
|
||||
{
|
||||
{ "1C", "1c" },
|
||||
{ "Access logs", "accesslog" },
|
||||
{ "ARM assembler", "armasm" },
|
||||
{ "AVR assembler", "avrasm" },
|
||||
{ "ActionScript", "actionscript" },
|
||||
{ "Apache", "apache" },
|
||||
{ "AppleScript", "applescript" },
|
||||
{ "AsciiDoc", "asciidoc" },
|
||||
{ "AspectJ", "aspectj" },
|
||||
{ "AutoHotkey", "autohotkey" },
|
||||
{ "AutoIt", "autoit" },
|
||||
{ "Axapta", "axapta" },
|
||||
{ "Bash", "bash" },
|
||||
{ "Basic", "basic" },
|
||||
{ "Brainfuck", "brainfuck" },
|
||||
{ "C#", "cs" },
|
||||
{ "C++", "cpp" },
|
||||
{ "C/AL", "cal" },
|
||||
{ "Cache Object Script", "cos" },
|
||||
{ "CMake", "cmake" },
|
||||
{ "CSS", "css" },
|
||||
{ "Cap’n Proto", "capnproto" },
|
||||
{ "Clojure", "clojure" },
|
||||
{ "CoffeeScript", "coffeescript" },
|
||||
{ "Crmsh", "crmsh" },
|
||||
{ "Crystal", "crystal" },
|
||||
{ "D", "d" },
|
||||
{ "DNS Zone file", "dns" },
|
||||
{ "DOS", "dos" },
|
||||
{ "Dart", "dart" },
|
||||
{ "Delphi", "delphi" },
|
||||
{ "Diff", "diff" },
|
||||
{ "Django", "django" },
|
||||
{ "Dockerfile", "dockerfile" },
|
||||
{ "DTS (Device Tree)", "dts" },
|
||||
{ "Dust", "dust" },
|
||||
{ "Elixir", "elixir" },
|
||||
{ "Elm", "elm" },
|
||||
{ "Erlang", "erlang" },
|
||||
{ "F#", "fsharp" },
|
||||
{ "FIX", "fix" },
|
||||
{ "Fortran", "fortran" },
|
||||
{ "G-Code", "gcode" },
|
||||
{ "Gams", "gams" },
|
||||
{ "GAUSS", "gauss" },
|
||||
{ "Gherkin", "gherkin" },
|
||||
{ "Go", "go" },
|
||||
{ "Golo", "golo" },
|
||||
{ "Gradle", "gradle" },
|
||||
{ "Groovy", "groovy" },
|
||||
{ "HTML, XML", "xml" },
|
||||
{ "HTTP", "http" },
|
||||
{ "Haml", "haml" },
|
||||
{ "Handlebars", "handlebars" },
|
||||
{ "Haskell", "haskell" },
|
||||
{ "Haxe", "haxe" },
|
||||
{ "Ini", "ini" },
|
||||
{ "Inform7", "inform7" },
|
||||
{ "IRPF90", "irpf90" },
|
||||
{ "JSON", "json" },
|
||||
{ "Java", "java" },
|
||||
{ "JavaScript", "javascript" },
|
||||
{ "Lasso", "lasso" },
|
||||
{ "Less", "less" },
|
||||
{ "Lisp", "lisp" },
|
||||
{ "LiveCode Server", "livecodeserver" },
|
||||
{ "LiveScript", "livescript" },
|
||||
{ "Lua", "lua" },
|
||||
{ "Makefile", "makefile" },
|
||||
{ "Markdown", "markdown" },
|
||||
{ "Mathematica", "mathematica" },
|
||||
{ "Matlab", "matlab" },
|
||||
{ "Maya Embedded Language", "mel" },
|
||||
{ "Mercury", "mercury" },
|
||||
{ "Mizar", "mizar" },
|
||||
{ "Mojolicious", "mojolicious" },
|
||||
{ "Monkey", "monkey" },
|
||||
{ "NSIS", "nsis" },
|
||||
{ "Nginx", "nginx" },
|
||||
{ "Nimrod", "nimrod" },
|
||||
{ "Nix", "nix" },
|
||||
{ "OCaml", "ocaml" },
|
||||
{ "Objective C", "objectivec" },
|
||||
{ "OpenGL Shading Language", "glsl" },
|
||||
{ "OpenSCAD", "openscad" },
|
||||
{ "Oracle Rules Language", "ruleslanguage" },
|
||||
{ "Oxygene", "oxygene" },
|
||||
{ "PF", "pf" },
|
||||
{ "PHP", "php" },
|
||||
{ "Parser3", "parser3" },
|
||||
{ "Perl", "perl" },
|
||||
{ "PowerShell", "powershell" },
|
||||
{ "Processing", "processing" },
|
||||
{ "Prolog", "prolog" },
|
||||
{ "Protocol Buffers", "protobuf" },
|
||||
{ "Puppet", "puppet" },
|
||||
{ "Python", "python" },
|
||||
{ "Python profiler results", "profile" },
|
||||
{ "Q", "k" },
|
||||
{ "QML", "qml" },
|
||||
{ "R", "r" },
|
||||
{ "RenderMan RIB", "rib" },
|
||||
{ "RenderMan RSL", "rsl" },
|
||||
{ "Roboconf", "graph" },
|
||||
{ "Ruby", "ruby" },
|
||||
{ "Rust", "rust" },
|
||||
{ "SCSS", "scss" },
|
||||
{ "SQL", "sql" },
|
||||
{ "STEP Part 21", "p21" },
|
||||
{ "Scala", "scala" },
|
||||
{ "Scheme", "scheme" },
|
||||
{ "Scilab", "scilab" },
|
||||
{ "Smali", "smali" },
|
||||
{ "Smalltalk", "smalltalk" },
|
||||
{ "Stan", "stan" },
|
||||
{ "Stata", "stata" },
|
||||
{ "Stylus", "stylus" },
|
||||
{ "Swift", "swift" },
|
||||
{ "Tcl", "tcl" },
|
||||
{ "TeX", "tex" },
|
||||
{ "Thrift", "thrift" },
|
||||
{ "TP", "tp" },
|
||||
{ "Twig", "twig" },
|
||||
{ "TypeScript", "typescript" },
|
||||
{ "VB.Net", "vbnet" },
|
||||
{ "VBScript", "vbscript" },
|
||||
{ "VHDL", "vhdl" },
|
||||
{ "Vala", "vala" },
|
||||
{ "Verilog", "verilog" },
|
||||
{ "Vim Script", "vim" },
|
||||
{ "x86 Assembly", "x86asm" },
|
||||
{ "XL", "xl" },
|
||||
{ "XQuery", "xpath" },
|
||||
{ "Zephir", "zephir" }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -61,6 +61,10 @@
|
||||
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="FearTheCowboy.Pygments, Version=2.0.2.2, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FearTheCowboy.Pygments.2.0.2.2\lib\net40\FearTheCowboy.Pygments.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="MarkdownDeep, Version=1.5.4615.26275, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MarkdownDeep.NET.1.5\lib\.NetFramework 3.5\MarkdownDeep.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@ -342,7 +346,6 @@
|
||||
<Content Include="Areas\Home\Scripts\Home.js" />
|
||||
<Content Include="Areas\Paste\Content\Paste.css" />
|
||||
<Content Include="Areas\Paste\Scripts\Paste.js" />
|
||||
<Content Include="Areas\Paste\Scripts\SyntaxWorker.js" />
|
||||
<Content Include="Areas\Podcast\Content\Podcast.css" />
|
||||
<Content Include="Areas\Podcast\Scripts\Podcast.js" />
|
||||
<Content Include="Areas\Transparency\Scripts\Transparency.js" />
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
For more information on how to configure your ASP.NET application, please visit
|
||||
http://go.microsoft.com/fwlink/?LinkId=301880
|
||||
|
@ -6,6 +6,7 @@
|
||||
<package id="Bootstrap.Switch" version="3.3.2.1" targetFramework="net452" />
|
||||
<package id="BouncyCastle" version="1.8.1" targetFramework="net452" />
|
||||
<package id="EntityFramework" version="6.1.3" targetFramework="net452" userInstalled="true" />
|
||||
<package id="FearTheCowboy.Pygments" version="2.0.2.2" targetFramework="net462" />
|
||||
<package id="FontAwesome" version="4.6.3" targetFramework="net452" userInstalled="true" />
|
||||
<package id="GitVersionTask" version="3.6.4" targetFramework="net452" developmentDependency="true" />
|
||||
<package id="Inferno" version="1.4.0" targetFramework="net452" userInstalled="true" />
|
||||
|
Loading…
Reference in New Issue
Block a user