1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Fixed formatting of blog/vault editors.

Fixed paste output not working correctly in <pre><code>
This commit is contained in:
Uncled1023 2018-06-20 21:36:05 -07:00
parent f356e35b03
commit b674590b8c
11 changed files with 92 additions and 49 deletions

View File

@ -25,21 +25,23 @@
<!form class="form" action="@Url.SubRouteUrl("blog", "Blog.Action", new { action = "EditPost" })" method="post" id="newPost"> <!form class="form" action="@Url.SubRouteUrl("blog", "Blog.Action", new { action = "EditPost" })" method="post" id="newPost">
<input name="PostID" id="postID" type="hidden" value="@Model.PostId" /> <input name="PostID" id="postID" type="hidden" value="@Model.PostId" />
<div class="row"> <div class="row">
<div class="col-sm-12"> <div class="col-sm-10 col-sm-offset-1">
<label for="title"><h4>Title</h4></label> <label for="title"><h4>Title</h4></label>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-sm-5 col-sm-offset-1">
<input class="form-control" name="Title" id="title" placeholder="generic click bait" title="enter a title for your post." type="text" value="@Model.Title" /> <input class="form-control" name="Title" id="title" placeholder="generic click bait" title="enter a title for your post." type="text" value="@Model.Title" />
</div> </div>
<div class="col-sm-1 col-sm-offset-1 pull-right"> <div class="col-sm-5">
<button type="submit" class="btn btn-primary" id="submit">Save</button> <button type="submit" class="btn btn-primary pull-right" id="submit">Save</button>
</div>
<div class="col-sm-1">
</div> </div>
</div> </div>
<br /> <br />
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-sm-10 col-sm-offset-1">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Article</div> <div class="panel-heading">Article</div>
<div class="panel-body"> <div class="panel-body">
@ -48,7 +50,9 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-sm-6"> </div>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Preview</div> <div class="panel-heading">Preview</div>
<div class="panel-body"> <div class="panel-body">

View File

@ -25,21 +25,23 @@
<!form class="form" action="@Url.SubRouteUrl("blog", "Blog.Action", new { action = "CreatePost" })" method="post" id="newPost"> <!form class="form" action="@Url.SubRouteUrl("blog", "Blog.Action", new { action = "CreatePost" })" method="post" id="newPost">
<input name="BlogID" id="blogID" type="hidden" value="@Model.BlogId" /> <input name="BlogID" id="blogID" type="hidden" value="@Model.BlogId" />
<div class="row"> <div class="row">
<div class="col-sm-12"> <div class="col-sm-10 col-sm-offset-1">
<label for="title"><h4>Title</h4></label> <label for="title"><h4>Title</h4></label>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-sm-5 col-sm-offset-1">
<input class="form-control" name="Title" id="title" placeholder="generic click bait" title="enter a title for your post." type="text" /> <input class="form-control" name="Title" id="title" placeholder="generic click bait" title="enter a title for your post." type="text" />
</div> </div>
<div class="col-sm-1 col-sm-offset-1 pull-right"> <div class="col-sm-5">
<button type="submit" class="btn btn-primary" id="submit">Create Post</button> <button type="submit" class="btn btn-primary pull-right" id="submit">Create Post</button>
</div>
<div class="col-sm-1">
</div> </div>
</div> </div>
<br /> <br />
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-sm-10 col-sm-offset-1">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Article</div> <div class="panel-heading">Article</div>
<div class="panel-body"> <div class="panel-body">
@ -48,7 +50,9 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-sm-6"> </div>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Preview</div> <div class="panel-heading">Preview</div>
<div class="panel-body"> <div class="panel-body">

View File

@ -98,6 +98,13 @@ namespace Teknik.Areas.Paste.Controllers
PasswordViewModel passModel = new PasswordViewModel(); PasswordViewModel passModel = new PasswordViewModel();
passModel.Url = url; passModel.Url = url;
passModel.Type = type; passModel.Type = type;
if (!string.IsNullOrEmpty(password) && hash != paste.HashedPassword)
{
passModel.Error = true;
passModel.ErrorMessage = "Invalid Password";
}
// Redirect them to the password request page // Redirect them to the password request page
return View("~/Areas/Paste/Views/Paste/PasswordNeeded.cshtml", passModel); return View("~/Areas/Paste/Views/Paste/PasswordNeeded.cshtml", passModel);
} }
@ -110,18 +117,6 @@ namespace Teknik.Areas.Paste.Controllers
model.Content = Encoding.Unicode.GetString(data); model.Content = Encoding.Unicode.GetString(data);
} }
if (type.ToLower() == "full" || type.ToLower() == "simple")
{
// Transform content into HTML
//if (!Highlighter.Lexers.ToList().Exists(l => l.Aliases.Contains(model.Syntax)))
//{
// model.Syntax = "text";
//}
//Highlighter highlighter = new Highlighter();
// Add a space in front of the content due to bug with pygment (No idea why yet)
model.Content = model.Content;//highlighter.HighlightToHtml(" " + model.Content, model.Syntax, _config.PasteConfig.SyntaxVisualStyle, generateInlineStyles: true, fragment: true);
}
switch (type.ToLower()) switch (type.ToLower())
{ {
case "full": case "full":
@ -134,7 +129,7 @@ namespace Teknik.Areas.Paste.Controllers
//Create File //Create File
var cd = new System.Net.Mime.ContentDisposition var cd = new System.Net.Mime.ContentDisposition
{ {
FileName = url, FileName = url + ".txt",
Inline = true Inline = true
}; };

View File

@ -68,7 +68,7 @@
<br /> <br />
<div class="row"> <div class="row">
<div class="col-sm-12"> <div class="col-sm-12">
<pre><code id="code">@Html.Raw(Model.Content)</code></pre> <pre><code id="code">@Model.Content</code></pre>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,10 +1,20 @@
@model Teknik.Areas.Paste.ViewModels.PasswordViewModel @model Teknik.Areas.Paste.ViewModels.PasswordViewModel
<div class="container"> <div class="container">
@if (Model.Error)
{
<div class="row">
<div class="col-xs-12 text-center">
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>@Model.ErrorMessage
</div>
</div>
</div>
}
<div class="row text-center"> <div class="row text-center">
<div class="col-sm-6 col-sm-offset-3"> <div class="col-sm-6 col-sm-offset-3">
<!form class="form-inline" method="post" action="@Url.SubRouteUrl("paste", "Paste.View")"> <!form class="form-inline" method="post" action="@Url.SubRouteUrl("paste", "Paste.View")">
<h3><span class="glyphicon glyphicon-warning-sign"></span> This paste is password protected.</h3> <h3>This paste is password protected</h3>
<input type="hidden" name="type" value="@Model.Type"> <input type="hidden" name="type" value="@Model.Type">
<input type="hidden" name="url" value="@Model.Url"> <input type="hidden" name="url" value="@Model.Url">
<div class="well no-padding"> <div class="well no-padding">

View File

@ -48,7 +48,7 @@
var highlightSrc = '@Url.FullURL("~/js/highlight.min.js")'; var highlightSrc = '@Url.FullURL("~/js/highlight.min.js")';
</script> </script>
<pre><code id="code">@Html.Raw(Model.Content)</code></pre> <pre><code id="code">@Model.Content</code></pre>
<bundle src="js/common.min.js" append-version="true"></bundle> <bundle src="js/common.min.js" append-version="true"></bundle>
<bundle src="js/paste.view.min.js" append-version="true"></bundle> <bundle src="js/paste.view.min.js" append-version="true"></bundle>

View File

@ -127,22 +127,24 @@
<div class="row"> <div class="row">
<div class="col-sm-10"> <div class="col-sm-10">
<div class="row"> <div class="row">
<div class="form-group col-sm-12"> <div class="form-group col-sm-10 col-sm-offset-1">
<label for="title"><h4>Title</h4></label> <label for="title"><h4>Title</h4></label>
<input class="form-control" name="title" id="title" placeholder="Collection of items" title="enter a title for your vault." type="text" value="@Model.title" /> <input class="form-control" name="title" id="title" placeholder="Collection of items" title="enter a title for your vault." type="text" value="@Model.title" />
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-sm-10 col-sm-offset-1">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Description</div> <div class="panel-heading">Description</div>
<div class="panel-body"> <div class="panel-body">
<div class="mdd_toolbar"></div> <div class="mdd_toolbar"></div>
<textarea class="form-control mdd_editor" name="description" id="description" placeholder="This is a cool collection of uploads and pastes" title="enter the description for this vault" data-provide="markdown" rows="5">@Model.description</textarea> <textarea class="form-control mdd_editor" name="description" id="description" placeholder="This is a cool collection of uploads and pastes" title="enter the description for this vault" data-provide="markdown" rows="15">@Model.description</textarea>
</div> </div>
</div> </div>
</div> </div>
<div class="col-sm-6"> </div>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Preview</div> <div class="panel-heading">Preview</div>
<div class="panel-body"> <div class="panel-body">

View File

@ -54,7 +54,7 @@
} }
else else
{ {
<pre><code id="code_@(Model.Paste.PasteId)">@Html.Raw(Model.Paste.Content)</code></pre> <pre><code id="code_@(Model.Paste.PasteId)">@Model.Paste.Content</code></pre>
} }
</div> </div>
<div class="show-more" id="show-more-bottom-@Model.VaultItemId"> <div class="show-more" id="show-more-bottom-@Model.VaultItemId">

View File

@ -400,21 +400,21 @@ namespace Teknik
name: "Paste.Simple", name: "Paste.Simple",
domains: new List<string>() { config.Host }, domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" }, subDomains: new List<string>() { "paste", "p" },
template: "Simple/{url}", template: "Simple/{url}/{password?}",
defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Simple" } defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Simple" }
); );
routes.MapSubdomainRoute( routes.MapSubdomainRoute(
name: "Paste.Raw", name: "Paste.Raw",
domains: new List<string>() { config.Host }, domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" }, subDomains: new List<string>() { "paste", "p" },
template: "Raw/{url}", template: "Raw/{url}/{password?}",
defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Raw" } defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Raw" }
); );
routes.MapSubdomainRoute( routes.MapSubdomainRoute(
name: "Paste.Download", name: "Paste.Download",
domains: new List<string>() { config.Host }, domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" }, subDomains: new List<string>() { "paste", "p" },
template: "Download/{url}", template: "Download/{url}/{password?}",
defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Download" } defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Download" }
); );
routes.MapSubdomainRoute( routes.MapSubdomainRoute(
@ -428,7 +428,7 @@ namespace Teknik
name: "Paste.View", name: "Paste.View",
domains: new List<string>() { config.Host }, domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" }, subDomains: new List<string>() { "paste", "p" },
template: "{url}", template: "{url}/{password?}",
defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Full" } defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Full" }
); );
} }

40
Utilities/HtmlHelper.cs Normal file
View File

@ -0,0 +1,40 @@
using Ganss.XSS;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
using System.Text;
namespace Teknik.Utilities
{
public static class HtmlHelper
{
/// <summary>
/// Transforms a string of Markdown into HTML.
/// </summary>
/// <param name="helper">HtmlHelper - Not used, but required to make this an extension method.</param>
/// <param name="text">The Markdown that should be transformed.</param>
/// <returns>The HTML representation of the supplied Markdown.</returns>
public static HtmlString Markdown(this IHtmlHelper helper, string text)
{
// Just call the other one, to avoid having two copies (we don't use the HtmlHelper).
return MarkdownHelper.Markdown(text);
}
/// <summary>
/// Sanitizes a string from HTML.
/// </summary>
/// <param name="helper">HtmlHelper - Not used, but required to make this an extension method.</param>
/// <param name="text">The Markdown that should be transformed.</param>
/// <returns>The HTML representation of the supplied Markdown.</returns>
public static HtmlString Sanitize(this IHtmlHelper helper, string text)
{
// Sanitize Text
var sanitizer = new HtmlSanitizer();
var sanText = sanitizer.Sanitize(text);
// Wrap the html in an MvcHtmlString otherwise it'll be HtmlEncoded and displayed to the user as HTML :(
return new HtmlString(sanText);
}
}
}

View File

@ -29,18 +29,6 @@ namespace Teknik.Utilities
return new HtmlString(html); return new HtmlString(html);
} }
/// <summary>
/// Transforms a string of Markdown into HTML.
/// </summary>
/// <param name="helper">HtmlHelper - Not used, but required to make this an extension method.</param>
/// <param name="text">The Markdown that should be transformed.</param>
/// <returns>The HTML representation of the supplied Markdown.</returns>
public static HtmlString Markdown(this IHtmlHelper helper, string text)
{
// Just call the other one, to avoid having two copies (we don't use the HtmlHelper).
return Markdown(text);
}
public static MarkdownPipeline BuildPipeline() public static MarkdownPipeline BuildPipeline()
{ {
return new MarkdownPipelineBuilder() // Use similar to advanced extension without auto-identifier return new MarkdownPipelineBuilder() // Use similar to advanced extension without auto-identifier