实现加载md文档内容

This commit is contained in:
hogan 2019-01-10 16:42:20 +08:00
parent 676c0f07a7
commit d9c0ba52fa
15 changed files with 605 additions and 53 deletions

View File

@ -0,0 +1,42 @@
//using FreeSql.Site.Entity;
using FreeSql.Site.Entity;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
namespace FreeSql.Site.DAL
{
public class DocumentContentDAL
{
public long Insert(DocumentContent model)
{
return Db.mysql.Insert<DocumentContent>(model).ExecuteIdentity();
}
public bool Update(DocumentContent model)
{
return Db.mysql.Update<DocumentContent>(model.ID).ExecuteUpdated().Count > 0;
}
public bool Delete(long id)
{
return Db.mysql.Delete<DocumentContent>(id).ExecuteDeleted().Count > 0;
}
public DocumentContent GetByOne(Expression<Func<DocumentContent, bool>> where)
{
return Db.mysql.Select<DocumentContent>()
.Where(where).ToOne();
}
public List<DocumentContent> Query(Expression<Func<DocumentContent, bool>> where,
Expression<Func<DocumentContent, DocumentContent>> orderby = null)
{
var list = Db.mysql.Select<DocumentContent>()
.Where(where);
if (orderby != null) list = list.OrderBy(b => b.CreateDt);
return list.ToList();
}
}
}

View File

@ -0,0 +1,58 @@
//using FreeSql.DataAnnotations;
using FreeSql.DataAnnotations;
using System;
namespace FreeSql.Site.Entity
{
public class DocumentComment
{
[Column(IsIdentity = true, IsPrimary = true)]
public int ID { get; set; }
/// <summary>
/// 功能类型(文章、模板、示例等)
/// </summary>
public int FunctionType { get; set; }
/// <summary>
/// 功能ID 文章、模板、示例等
/// </summary>
public int FunctionID { get; set; }
/// <summary>
/// 是否匿名访问
/// </summary>
public int IsAnonymous { get; set; }
/// <summary>
/// 评论人
/// </summary>
public string Commentator { get; set; }
/// <summary>
/// 评论者IP
/// </summary>
public string CommentatorIp { get; set; }
/// <summary>
/// 回复评论编号
/// </summary>
public int ReplyID { get; set; }
/// <summary>
/// 评论内容
/// </summary>
public string CommentContent { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? CreateDt { get; set; }
/// <summary>
/// 创建人
/// </summary>
public string CreateBy { get; set; }
}
}

View File

@ -0,0 +1,67 @@
//using FreeSql.DataAnnotations;
using FreeSql.DataAnnotations;
using System;
namespace FreeSql.Site.Entity
{
public class DocumentContent
{
[Column(IsIdentity = true, IsPrimary = true)]
public int ID { get; set; }
/// <summary>
/// 类型编号
/// </summary>
public int TypeID { get; set; }
/// <summary>
/// 标题
/// </summary>
public string DocTitle { get; set; }
/// <summary>
/// 摘要
/// </summary>
public string DocAbstract { get; set; }
/// <summary>
/// 文档内容
/// </summary>
public string DocContent { get; set; }
/// <summary>
/// 状态
/// </summary>
public int Status { get; set; }
/// <summary>
/// 查看次数
/// </summary>
public int WatchCount { get; set; }
/// <summary>
/// Star统计
/// </summary>
public int StarCount { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? CreateDt { get; set; }
/// <summary>
/// 创建人
/// </summary>
public string CreateBy { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public DateTime? UpdateDt { get; set; }
/// <summary>
/// 修改人
/// </summary>
public string UpdateBy { get; set; }
}
}

View File

@ -13,6 +13,11 @@ namespace FreeSql.Site.Entity
public int? UpID { get; set; } public int? UpID { get; set; }
/// <summary>
/// 状态
/// </summary>
public int Status { get; set; }
public DateTime? CreateDt { get; set; } public DateTime? CreateDt { get; set; }
public string CreateBy { get; set; } public string CreateBy { get; set; }

View File

@ -0,0 +1,59 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Text;
namespace FreeSql.Site.Entity
{
/// <summary>
/// 模板示例
/// </summary>
public class TemplateExample
{
[Column(IsIdentity = true, IsPrimary = true)]
public int ID { get; set; }
/// <summary>
/// 模板图片
/// </summary>
public string TemplateImg { get; set; }
/// <summary>
/// 模板名称
/// </summary>
public string TempateName { get; set; }
/// <summary>
/// 模板路径
/// </summary>
public string TemplatePath { get; set; }
/// <summary>
/// 查看次数
/// </summary>
public int WatchCount { get; set; }
/// <summary>
/// 下载统计
/// </summary>
public int DownloadCount { get; set; }
/// <summary>
/// Star统计
/// </summary>
public int StarCount { get; set; }
/// <summary>
/// 状态
/// </summary>
public int Status { get; set; }
public DateTime? CreateDt { get; set; }
public string CreateBy { get; set; }
public DateTime? UpdateDt { get; set; }
public string UpdateBy { get; set; }
}
}

View File

@ -2,7 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using FreeSql.Site.DAL;
using FreeSql.Site.Entity;
using FreeSql.Site.UI.Controllers; using FreeSql.Site.UI.Controllers;
using FreeSql.Site.UI.Models;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -11,17 +14,49 @@ namespace FreeSql.Site.UI.Areas.Doc.Controllers
[Area("Doc")] [Area("Doc")]
public class DocumentsController : BaseController public class DocumentsController : BaseController
{ {
// GET: Documents public DocumentTypeDAL DocumentTypeDAL { get; set; }
public IActionResult Index()
public DocumentContentDAL DocumentContentDAL { get; set; }
public DocumentsController()
{ {
ViewBag.DocumentList = new FreeSql.Site.DAL.DocumentTypeDAL().Query(d => d.ID != 0); this.DocumentTypeDAL = new DocumentTypeDAL();
this.DocumentContentDAL = new DocumentContentDAL();
}
// GET: Documents
public IActionResult Index(int id = 1)
{
var typeList = DocumentTypeDAL.Query(d => d.ID != 0);
var contentlist = DocumentContentDAL.Query(d => d.Status == 1);
//适应两层结构即可
var query = (from p in typeList
where p.UpID == null || p.UpID == 0
select new TreeData(p, typeList).AddChildrens(GetContentTreeData(p.ID, contentlist), (tid) => GetContentTreeData(tid, contentlist))).ToList();
ViewBag.DocumentList = query;
ViewBag.DocID = id;
return View(); return View();
} }
private List<TreeData> GetContentTreeData(int id, List<DocumentContent> contentlist)
{
return contentlist.Where(w => w.TypeID == id).Select(s => new TreeData
{
id = s.ID,
text = s.DocTitle,
datatype = 1
}).ToList();
}
// GET: Documents/Details/5 // GET: Documents/Details/5
public ActionResult Details(int id) public ActionResult Details(int id)
{ {
return View(); ViewBag.DocumentID = id;
var doc = this.DocumentContentDAL.GetByOne(w => w.ID == id);
ViewBag.DocumentInfo = doc;
return this.PartialView();
} }
// GET: Documents/Create // GET: Documents/Create

View File

@ -0,0 +1,71 @@
@{
Layout = null;
var documentinfo = (FreeSql.Site.Entity.DocumentContent)ViewBag.DocumentInfo;
}
@if (ViewBag.DocumentInfo == null)
{
<span style="font-size:20px; color:red;">
编号: @ViewBag.DocumentID
</span>
<span>测试没有</span>
}
else
{
<h1 class="site-h1">@*开始使用 - 入门指南*@@documentinfo.DocTitle</h1>
<div id="details_content" >
@*<markdown>@documentinfo.DocContent</markdown>*@
@documentinfo.DocContent
@*<blockquote class="layui-elem-quote">
lFreeSql 是轻量化、可扩展和跨平台版的 .NETStandard 数据访问技术实现。<br />
FreeSql 可用作对象关系映射程序 (O/RM),以便于开发人员能够使用 .NETStandard 对象来处理数据库,不必经常编写大部分数据访问代码。<br />
FreeSql 支持 MySql/SqlServer/PostgreSQL 数据库技术实现。<br />
FreeSql 打造 .NETCore 最方便的 ORMdbfirst codefirst混合使用codefirst模式下的开发阶段建好实体不用执行任何操作就能创建表和修改字段dbfirst模式下提供api+模板自定义生成代码作者提供了3种模板。<br />
FreeSql 目前仍处在测试阶段您可以持续关注或者参与给出宝贵意见QQ群4336577
</blockquote>
<fieldset class="layui-elem-field layui-field-title site-title">
<legend><a name="compatibility">兼容性和面向场景</a></legend>
</fieldset>
<div class="site-text">
<p>1. 官网首页下载</p>
<blockquote class="layui-elem-quote layui-quote-nm">
您可以通过 <a href="#">Github</a> 下载到FreeSql的最新版
</blockquote>
<pre class="layui-code layui-box layui-code-view"><h3 class="layui-code-h3">code<a href="#" target="_blank">FreeSql</a></h3><ol class="layui-code-ol"><li> ├─css //css目录</li><li> │ │─modules //模块css目录一般如果模块相对较大我们会单独提取比如下面三个</li><li> │ │ ├─laydate</li><li> │ │ ├─layer</li><li> │ │ └─layim</li><li> │ └─layui.css //核心样式文件</li><li> ├─font //字体图标目录</li><li> ├─images //图片资源目录目前只有layim和编辑器用到的GIF表情</li><li> │─lay //模块核心目录</li><li> │ └─modules //各模块组件</li><li> │─layui.js //基础核心库</li><li> └─layui.all.js //包含layui.js和所有模块的合并文件</li><li> </li></ol></pre>
<p>2. Git 仓库下载</p>
<blockquote class="layui-elem-quote layui-quote-nm">
你也可以通过 <a href="https://github.com/2881099/FreeSql/" target="_blank">GitHub</a> 或 <a href="https://gitee.com/sentsin/layui" target="_blank">码云</a> 得到 FreeSql 的完整开发包,以便于你进行二次开发,或者 Fork FreeSql 为我们贡献方案
<br><br>
<iframe src="//ghbtns.com/github-btn.html?user=2881099&amp;repo=FreeSql&amp;type=watch&amp;count=true&amp;size=large" allowtransparency="true" frameborder="0" scrolling="0" width="156px" height="30px"></iframe>
<iframe src="//ghbtns.com/github-btn.html?user=2881099&amp;repo=FreeSql&amp;type=fork&amp;count=true&amp;size=large" allowtransparency="true" frameborder="0" scrolling="0" width="156px" height="30px"></iframe>
</blockquote>
<p>3. npm 安装</p>
<pre class="layui-code layui-box layui-code-view layui-code-notepad" lay-skin="notepad"><h3 class="layui-code-h3">code<a href="#" target="_blank">FreeSql</a></h3><ol class="layui-code-ol"><li> </li><li>Install-Package FreeSql </li><li> </li></ol></pre>
<p>一般用于 WebPack 管理</p>
</div>
<fieldset class="layui-elem-field layui-field-title site-title">
<legend><a name="quickstart">快速上手</a></legend>
</fieldset>
<div class="site-text">
<p>1. 官网首页下载</p>
<blockquote class="layui-elem-quote layui-quote-nm">
你可以在我们的 <a href="http://www.layui.com/">官网首页</a> 下载到 layui 的最新版,它经过了自动化构建,更适合用于生产环境。目录结构如下:
</blockquote>
<pre class="layui-code layui-box layui-code-view"><h3 class="layui-code-h3">code<a href="#" target="_blank">FreeSql</a></h3><ol class="layui-code-ol"><li> ├─css //css目录</li><li> │ │─modules //模块css目录一般如果模块相对较大我们会单独提取比如下面三个</li><li> │ │ ├─laydate</li><li> │ │ ├─layer</li><li> │ │ └─layim</li><li> │ └─layui.css //核心样式文件</li><li> ├─font //字体图标目录</li><li> ├─images //图片资源目录目前只有layim和编辑器用到的GIF表情</li><li> │─lay //模块核心目录</li><li> │ └─modules //各模块组件</li><li> │─layui.js //基础核心库</li><li> └─layui.all.js //包含layui.js和所有模块的合并文件</li><li> </li></ol></pre>
</div>*@
</div>
<script>
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: true,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false,
});
document.getElementById('details_content').innerHTML =
marked($("#details_content").html());
$("#details_content").show();
</script>
}

View File

@ -1,61 +1,62 @@
@{ @{
//ViewBag.Title = Model.ResultInfo.CurrentType.TypeName + "-" + Model.ResultInfo.Master.MasterName + PubConst.SitePrefix;
} }
<div class="layui-main site-inline"> <div class="layui-main site-inline">
<div class="site-tree"> <div class="site-tree">
<ul class="layui-tree"> <ul class="layui-tree">
<li><h2>基础说明</h2></li> @foreach (var item in (List<FreeSql.Site.UI.Models.TreeData>)ViewBag.DocumentList)
@foreach (var item in (List<FreeSql.Site.Entity.DocumentType>)ViewBag.DocumentList)
{ {
<li class="site-tree-noicon"> <li><h2>@item.text</h2></li>
<a href="#1"><cite>@item.TypeName</cite></a> foreach (var children in item.children)
</li> {
if (children.datatype == 1)
{
<li class="site-tree-noicon">
<a href="?id=@(children.id)"><cite>@children.text</cite></a>
</li>
}
else
{
<li class="site-tree-noicon">
<a href="#@(children.id)"><cite>&gt;&nbsp;@children.text</cite></a>
</li>
foreach (var children2 in children.children)
{
<li class="site-tree-noicon">
<a href="?id=@(children2.id)"><cite>&nbsp;&nbsp;&nbsp;&nbsp;@children2.text</cite></a>
</li>
}
}
}
} }
</ul> </ul>
</div> </div>
<div class="site-content"> <div class="site-content">
<h1 class="site-h1">开始使用 - 入门指南</h1> @Html.Action("Details", new RouteValueDictionary { { "id", ViewBag.DocID } })
<div>
<blockquote class="layui-elem-quote">
lFreeSql 是轻量化、可扩展和跨平台版的 .NETStandard 数据访问技术实现。<br />
FreeSql 可用作对象关系映射程序 (O/RM),以便于开发人员能够使用 .NETStandard 对象来处理数据库,不必经常编写大部分数据访问代码。<br />
FreeSql 支持 MySql/SqlServer/PostgreSQL 数据库技术实现。<br />
FreeSql 打造 .NETCore 最方便的 ORMdbfirst codefirst混合使用codefirst模式下的开发阶段建好实体不用执行任何操作就能创建表和修改字段dbfirst模式下提供api+模板自定义生成代码作者提供了3种模板。<br />
FreeSql 目前仍处在测试阶段您可以持续关注或者参与给出宝贵意见QQ群4336577
</blockquote>
<fieldset class="layui-elem-field layui-field-title site-title">
<legend><a name="compatibility">兼容性和面向场景</a></legend>
</fieldset>
<div class="site-text">
<p>1. 官网首页下载</p>
<blockquote class="layui-elem-quote layui-quote-nm">
您可以通过 <a href="#">Github</a> 下载到FreeSql的最新版
</blockquote>
<pre class="layui-code layui-box layui-code-view"><h3 class="layui-code-h3">code<a href="#" target="_blank">FreeSql</a></h3><ol class="layui-code-ol"><li> ├─css //css目录</li><li> │ │─modules //模块css目录一般如果模块相对较大我们会单独提取比如下面三个</li><li> │ │ ├─laydate</li><li> │ │ ├─layer</li><li> │ │ └─layim</li><li> │ └─layui.css //核心样式文件</li><li> ├─font //字体图标目录</li><li> ├─images //图片资源目录目前只有layim和编辑器用到的GIF表情</li><li> │─lay //模块核心目录</li><li> │ └─modules //各模块组件</li><li> │─layui.js //基础核心库</li><li> └─layui.all.js //包含layui.js和所有模块的合并文件</li><li> </li></ol></pre>
<p>2. Git 仓库下载</p>
<blockquote class="layui-elem-quote layui-quote-nm">
你也可以通过 <a href="https://github.com/2881099/FreeSql/" target="_blank">GitHub</a> 或 <a href="https://gitee.com/sentsin/layui" target="_blank">码云</a> 得到 FreeSql 的完整开发包,以便于你进行二次开发,或者 Fork FreeSql 为我们贡献方案
<br><br>
<iframe src="//ghbtns.com/github-btn.html?user=2881099&amp;repo=FreeSql&amp;type=watch&amp;count=true&amp;size=large" allowtransparency="true" frameborder="0" scrolling="0" width="156px" height="30px"></iframe>
<iframe src="//ghbtns.com/github-btn.html?user=2881099&amp;repo=FreeSql&amp;type=fork&amp;count=true&amp;size=large" allowtransparency="true" frameborder="0" scrolling="0" width="156px" height="30px"></iframe>
</blockquote>
<p>3. npm 安装</p>
<pre class="layui-code layui-box layui-code-view layui-code-notepad" lay-skin="notepad"><h3 class="layui-code-h3">code<a href="#" target="_blank">FreeSql</a></h3><ol class="layui-code-ol"><li> </li><li>Install-Package FreeSql </li><li> </li></ol></pre>
<p>一般用于 WebPack 管理</p>
</div>
<fieldset class="layui-elem-field layui-field-title site-title">
<legend><a name="quickstart">快速上手</a></legend>
</fieldset>
<div class="site-text">
<p>1. 官网首页下载</p>
<blockquote class="layui-elem-quote layui-quote-nm">
你可以在我们的 <a href="http://www.layui.com/">官网首页</a> 下载到 layui 的最新版,它经过了自动化构建,更适合用于生产环境。目录结构如下:
</blockquote>
<pre class="layui-code layui-box layui-code-view"><h3 class="layui-code-h3">code<a href="#" target="_blank">FreeSql</a></h3><ol class="layui-code-ol"><li> ├─css //css目录</li><li> │ │─modules //模块css目录一般如果模块相对较大我们会单独提取比如下面三个</li><li> │ │ ├─laydate</li><li> │ │ ├─layer</li><li> │ │ └─layim</li><li> │ └─layui.css //核心样式文件</li><li> ├─font //字体图标目录</li><li> ├─images //图片资源目录目前只有layim和编辑器用到的GIF表情</li><li> │─lay //模块核心目录</li><li> │ └─modules //各模块组件</li><li> │─layui.js //基础核心库</li><li> └─layui.all.js //包含layui.js和所有模块的合并文件</li><li> </li></ol></pre>
</div>
</div>
</div> </div>
</div> </div>
<div class="site-tree-mobile layui-hide"> <div class="site-tree-mobile layui-hide">
<i class="layui-icon"></i> <i class="layui-icon"></i>
</div> </div>
<script>
//window.onhashchange = function () {
// var hash = location.hash;
// if (hash.search(/^#C\d+$/g) == 0) {
// var docid = hash.replace('C', '');
// $(".site-content").load("/Doc/Documents/Details", { id: docid }, function () {
// alert(1);
// });
// //$.ajax({
// // type: "GET",
// // url: "/Doc/Documents/Details",
// // data: { id: docid },
// // dataType: "html",
// // success: function (data) {
// // $(".site-content").html(data);
// // }
// //});
// }
//}
</script>

View File

@ -0,0 +1,7 @@
@using FreeSql.Site.UI;
@using FreeSql.Site.UI.Models;
@using FreeSql.Site.UI.Common;
@using Microsoft.AspNetCore.Routing;
@using Microsoft.AspNetCore.Mvc;
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper "FreeSql.Site.UI.Common.TagHelpers.MarkdownTagHelper, FreeSql.Site.UI"

View File

@ -0,0 +1,101 @@
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using System;
using Microsoft.AspNetCore.Routing;
using System.IO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace FreeSql.Site.UI.Common
{
public static class HtmlHelperViewExtensions
{
public static IHtmlContent Action(this IHtmlHelper helper, string action, object parameters = null)
{
var controller = (string)helper.ViewContext.RouteData.Values["controller"];
return Action(helper, action, controller, parameters);
}
public static IHtmlContent Action(this IHtmlHelper helper, string action, string controller, object parameters = null)
{
var area = (string)helper.ViewContext.RouteData.Values["area"];
return Action(helper, action, controller, area, parameters);
}
public static IHtmlContent Action(this IHtmlHelper helper, string action, string controller, string area, object parameters = null)
{
if (action == null)
throw new ArgumentNullException("action");
if (controller == null)
throw new ArgumentNullException("controller");
var task = RenderActionAsync(helper, action, controller, area, parameters);
return task.Result;
}
private static async Task<IHtmlContent> RenderActionAsync(this IHtmlHelper helper, string action, string controller, string area, object parameters = null)
{
// fetching required services for invocation
var serviceProvider = helper.ViewContext.HttpContext.RequestServices;
var actionContextAccessor = helper.ViewContext.HttpContext.RequestServices.GetRequiredService<IActionContextAccessor>();
var httpContextAccessor = helper.ViewContext.HttpContext.RequestServices.GetRequiredService<IHttpContextAccessor>();
var actionSelector = serviceProvider.GetRequiredService<IActionSelector>();
// creating new action invocation context
var routeData = new RouteData();
foreach (var router in helper.ViewContext.RouteData.Routers)
{
routeData.PushState(router, null, null);
}
routeData.PushState(null, new RouteValueDictionary(new { controller = controller, action = action, area = area }), null);
routeData.PushState(null, new RouteValueDictionary(parameters ?? new { }), null);
//get the actiondescriptor
RouteContext routeContext = new RouteContext(helper.ViewContext.HttpContext) { RouteData = routeData };
var candidates = actionSelector.SelectCandidates(routeContext);
var actionDescriptor = actionSelector.SelectBestCandidate(routeContext, candidates);
var originalActionContext = actionContextAccessor.ActionContext;
var originalhttpContext = httpContextAccessor.HttpContext;
try
{
var newHttpContext = serviceProvider.GetRequiredService<IHttpContextFactory>().Create(helper.ViewContext.HttpContext.Features);
if (newHttpContext.Items.ContainsKey(typeof(IUrlHelper)))
{
newHttpContext.Items.Remove(typeof(IUrlHelper));
}
newHttpContext.Response.Body = new MemoryStream();
var actionContext = new ActionContext(newHttpContext, routeData, actionDescriptor);
actionContextAccessor.ActionContext = actionContext;
var invoker = serviceProvider.GetRequiredService<IActionInvokerFactory>().CreateInvoker(actionContext);
await invoker.InvokeAsync();
newHttpContext.Response.Body.Position = 0;
using (var reader = new StreamReader(newHttpContext.Response.Body))
{
return new HtmlString(reader.ReadToEnd());
}
}
catch (Exception ex)
{
return new HtmlString(ex.Message);
}
finally
{
actionContextAccessor.ActionContext = originalActionContext;
httpContextAccessor.HttpContext = originalhttpContext;
if (helper.ViewContext.HttpContext.Items.ContainsKey(typeof(IUrlHelper)))
{
helper.ViewContext.HttpContext.Items.Remove(typeof(IUrlHelper));
}
}
}
}
}

View File

@ -0,0 +1,40 @@
using CommonMark;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System.Net;
using System.Threading.Tasks;
namespace FreeSql.Site.UI.Common.TagHelpers
{
[HtmlTargetElement("markdown", TagStructure = TagStructure.NormalOrSelfClosing)]
[HtmlTargetElement(Attributes = "markdown")]
public class MarkdownTagHelper : TagHelper
{
public MarkdownTagHelper()
{
}
public ModelExpression Content { get; set; }
public async override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
if (output.TagName == "markdown")
{
output.TagName = null;
}
output.Attributes.RemoveAll("markdown");
var content = await GetContent(output);
var markdown = WebUtility.HtmlEncode(WebUtility.HtmlDecode(content));
var html = CommonMarkConverter.Convert(markdown);
output.Content.SetHtmlContent(html ?? "");
}
private async Task<string> GetContent(TagHelperOutput output)
{
if (Content == null)
return (await output.GetChildContentAsync()).GetContent();
return Content.Model?.ToString();
}
}
}

View File

@ -5,6 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommonMark.NET" Version="0.15.1" />
<PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FreeSql.Site.Entity;
namespace FreeSql.Site.UI.Models
{
public class TreeData
{
public TreeData() { }
public TreeData(DocumentType type)
{
this.id = type.ID;
this.text = type.TypeName;
}
public TreeData(DocumentType type, List<DocumentType> list)
{
this.id = type.ID;
this.text = type.TypeName;
this.children = (from l in list where l.UpID == type.ID select new TreeData(l, list)).ToList();
}
/// <summary>
/// 唯一编号
/// </summary>
public int id { get; set; }
/// <summary>
/// 标题
/// </summary>
public string text { get; set; }
/// <summary>
/// 类型 =0 表示类型 =1 表示内容
/// </summary>
public int datatype { get; set; } = 0;
public List<TreeData> children { get; set; }
public TreeData AddChildrens(List<TreeData> list, Func<int, List<TreeData>> bind = null)
{
if (this.children != null && bind != null)
{
this.children.ForEach(f =>
{
f.children = bind(f.id);
});
}
this.children?.AddRange(list);
return this;
}
}
}

View File

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
@ -32,6 +33,9 @@ namespace FreeSql.Site.UI
options.MinimumSameSitePolicy = SameSiteMode.None; options.MinimumSameSitePolicy = SameSiteMode.None;
}); });
//设置Action方法
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1) services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
//设置返回内容得大小写格式 //设置返回内容得大小写格式

View File

@ -8,12 +8,19 @@
<environment include="Development"> <environment include="Development">
<link href="~/layui/css/layui.css" rel="stylesheet" /> <link href="~/layui/css/layui.css" rel="stylesheet" />
<link rel="stylesheet" href="~/css/site.css" /> <link rel="stylesheet" href="~/css/site.css" />
<link rel="stylesheet" href="https://cdn.bootcss.com/highlight.js/9.11.0/styles/github.min.css" />
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.13.1/highlight.min.js"></script>
</environment> </environment>
<environment exclude="Development"> <environment exclude="Development">
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css" <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css" asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" /> asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" /> <link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment> </environment>
</head> </head>
<body class="site-home" id="LAY_home" style="background-color: #fff;" data-date="12-27"> <body class="site-home" id="LAY_home" style="background-color: #fff;" data-date="12-27">
@ -155,8 +162,6 @@
</div> </div>
<environment include="Development"> <environment include="Development">
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
@*<script src="~/js/site.js" asp-append-version="true"></script>*@ @*<script src="~/js/site.js" asp-append-version="true"></script>*@
<script src="~/layui/layui.js"></script> <script src="~/layui/layui.js"></script>
<script> <script>