private string GetDiffHtml(string text1, string text2) { HtmlDiff.HtmlDiff diffHelper = new HtmlDiff.HtmlDiff(text1, text2); // Lets add a block expression to group blocks we care about (such as dates) diffHelper.AddBlockExpression(new System.Text.RegularExpressions.Regex(@"[\d]{1,2}[\s]*(Jan|Feb)[\s]*[\d]{4}", System.Text.RegularExpressions.RegexOptions.IgnoreCase)); return(diffHelper.Build()); }
public override void Process(object sender, EventArgs e) { try { Item item = Event.ExtractParameter<Item>(e, 0); ItemChanges changes = Event.ExtractParameter<ItemChanges>(e, 1); StringBuilder sb = new StringBuilder("<table><th>Field</th><th>Change</th>"); bool flag = false; foreach (FieldChange fieldChange in changes.FieldChanges) { Field field = item.Fields[fieldChange.FieldID]; if (field.Name != "__Updated" && field.Name != "__Revision" && field.Name != "__Updated by" && fieldChange.OriginalValue != field.Value) { flag = true; sb.Append("<tr><td>"); sb.Append(Cleanse(field.Name)); sb.Append("</td><td>"); HtmlDiff.HtmlDiff diff = new HtmlDiff.HtmlDiff(fieldChange.OriginalValue, field.Value); sb.Append(diff.Build()); sb.Append("</td></tr>"); } } if (!flag) return; sb.Append("</table>"); LogEvent(item, sb.ToString()); } catch (Exception ex) { Log.Error("Problem auditing item save", ex, this); } }
public override void Process(object sender, EventArgs e) { try { Item item = Event.ExtractParameter <Item>(e, 0); ItemChanges changes = Event.ExtractParameter <ItemChanges>(e, 1); StringBuilder sb = new StringBuilder("<table><th>Field</th><th>Change</th>"); bool flag = false; foreach (FieldChange fieldChange in changes.FieldChanges) { Field field = item.Fields[fieldChange.FieldID]; if (field.Name.StartsWith("__") && fieldChange.OriginalValue != field.Value) { flag = true; sb.Append("<tr><td>"); sb.Append(Cleanse(field.Name)); sb.Append("</td><td>"); HtmlDiff.HtmlDiff diff = new HtmlDiff.HtmlDiff(fieldChange.OriginalValue, field.Value); sb.Append(diff.Build()); sb.Append("</td></tr>"); } } if (!flag) { return; } sb.Append("</table>"); LogEvent(item, sb.ToString()); } catch (Exception ex) { Log.Error("Problem auditing item save", ex, this); } }
protected void Page_Load(object sender, EventArgs e) { string oldText = @"<p><i>This is</i> some sample text to <strong>demonstrate</strong> the capability of the <strong>HTML diff tool</strong>.</p> <p>It is based on the <b>Ruby</b> implementation found <a href='http://github.com/myobie/htmldiff'>here</a>. Note how the link has no tooltip</p> <p>What about a number change: 123456?</p> <table cellpadding='0' cellspacing='0'> <tr><td>Some sample text</td><td>Some sample value</td></tr> <tr><td>Data 1 (this row will be removed)</td><td>Data 2</td></tr> </table> Here is a number 2 32 <br><br> This date: 1 Jan 2016 is about to change (note how it is treated as a block change!)"; string newText = @"<p>This is some sample <strong>text to</strong> demonstrate the awesome capabilities of the <strong>HTML <u>diff</u> tool</strong>.</p><br/><br/>Extra spacing here that was not here before. <p>It is <i>based</i> on the Ruby implementation found <a title='Cool tooltip' href='http://github.com/myobie/htmldiff'>here</a>. Note how the link has a tooltip now and the HTML diff algorithm has preserved formatting.</p> <p>What about a number change: 123356?</p> <table cellpadding='0' cellspacing='0'> <tr><td>Some sample <strong>bold text</strong></td><td>Some sample value</td></tr> </table> Here is a number 2 <sup>32</sup> <br><br> This date: 22 Feb 2017 is about to change (note how it is treated as a block change!)"; HtmlDiff.HtmlDiff diffHelper = new HtmlDiff.HtmlDiff(oldText, newText); litOldText.Text = oldText; litNewText.Text = newText; // Lets add a block expression to group blocks we care about (such as dates) diffHelper.AddBlockExpression(new Regex(@"[\d]{1,2}[\s]*(Jan|Feb)[\s]*[\d]{4}", RegexOptions.IgnoreCase)); litDiffText.Text = diffHelper.Build(); }
public ActionResult PushMerge(PostMergeRequestInputDto dto) { if (RedisHelper.Get("code:" + dto.ModifierEmail) != dto.Code) { return(ResultData(null, false, "验证码错误!")); } var post = PostService.GetById(dto.PostId) ?? throw new NotFoundException("文章未找到"); var diff = new HtmlDiff.HtmlDiff(post.Content.RemoveHtmlTag(), dto.Content.RemoveHtmlTag()); if (post.Title.Equals(dto.Title) && !diff.Build().Contains("diffmod")) { return(ResultData(null, false, "内容未被修改!")); } #region 直接合并 if (post.Email.Equals(dto.ModifierEmail)) { var history = post.Mapper <PostHistoryVersion>(); Mapper.Map(dto, post); post.PostHistoryVersion.Add(history); post.ModifyDate = DateTime.Now; return(PostService.SaveChanges() > 0 ? ResultData(null, true, "你是文章原作者,无需审核,文章已自动更新并在首页展示!") : ResultData(null, false, "操作失败!")); } #endregion var merge = post.PostMergeRequests.FirstOrDefault(r => r.Id == dto.Id && r.MergeState != MergeStatus.Merged); if (merge != null) { Mapper.Map(dto, merge); merge.SubmitTime = DateTime.Now; merge.MergeState = MergeStatus.Pending; } else { merge = Mapper.Map <PostMergeRequest>(dto); post.PostMergeRequests.Add(merge); } var b = PostService.SaveChanges() > 0; if (!b) { return(ResultData(null, b, b ? "您的修改请求已提交,已进入审核状态,感谢您的参与!" : "操作失败!")); } RedisHelper.Expire("code:" + dto.ModifierEmail, 1); MessageService.AddEntitySaved(new InternalMessage() { Title = $"来自【{dto.Modifier}】的文章修改合并请求", Content = dto.Title, Link = "#/merge/compare?id=" + merge.Id }); var content = System.IO.File.ReadAllText(HostEnvironment.WebRootPath + "/template/merge-request.html").Replace("{{title}}", post.Title).Replace("{{link}}", Url.Action("Index", "Dashboard", new { }, Request.Scheme) + "#/merge/compare?id=" + merge.Id); BackgroundJob.Enqueue(() => CommonHelper.SendMail("博客文章修改请求:", content, CommonHelper.SystemSettings["ReceiveEmail"])); return(ResultData(null, b, b ? "您的修改请求已提交,已进入审核状态,感谢您的参与!" : "操作失败!")); }
public IActionResult MergeCompare(int mid) { var newer = PostMergeRequestService.GetById(mid) ?? throw new NotFoundException("待合并文章未找到"); var old = newer.Post; var diffHelper = new HtmlDiff.HtmlDiff(old.Content, newer.Content); string diffOutput = diffHelper.Build(); old.Content = Regex.Replace(Regex.Replace(diffOutput, "<ins.+?</ins>", string.Empty), @"<\w+></\w+>", string.Empty); newer.Content = Regex.Replace(Regex.Replace(diffOutput, "<del.+?</del>", string.Empty), @"<\w+></\w+>", string.Empty); return(ResultData(new { old = old.Mapper <PostMergeRequestOutputDto>(), newer = newer.Mapper <PostMergeRequestOutputDto>() })); }
public ActionResult CompareVersion(int id, int v1, int v2) { var main = PostBll.GetById(id).Mapper <PostHistoryVersion>(); var left = v1 <= 0 ? main : PostHistoryVersionBll.GetById(v1); var right = v2 <= 0 ? main : PostHistoryVersionBll.GetById(v2); HtmlDiff.HtmlDiff diffHelper = new HtmlDiff.HtmlDiff(right.Content, left.Content); string diffOutput = diffHelper.Build(); right.Content = Regex.Replace(Regex.Replace(diffOutput, "<ins.+?</ins>", string.Empty), @"<\w+></\w+>", string.Empty); left.Content = Regex.Replace(Regex.Replace(diffOutput, "<del.+?</del>", string.Empty), @"<\w+></\w+>", string.Empty); return(View(new[] { main, left, right })); }
public string GetDifferenceData(int id, string templateVar) { var model = objprmdl.GetDiffData(id, templateVar); if (model.Oldtemplate == null) { model.Oldtemplate = ""; } var diffHelper = new HtmlDiff.HtmlDiff(model.Oldtemplate, model.Newtemplate); var diff = diffHelper.Build(); return(diff); }
public ActionResult CompareVersion(int id, int v1, int v2) { var main = PostService.Get(p => p.Id == id && (p.Status == Status.Pended || CurrentUser.IsAdmin)).Mapper <PostHistoryVersion>() ?? throw new NotFoundException("文章未找到"); var left = v1 <= 0 ? main : PostHistoryVersionService.Get(v => v.Id == v1) ?? throw new NotFoundException("文章未找到"); var right = v2 <= 0 ? main : PostHistoryVersionService.Get(v => v.Id == v2) ?? throw new NotFoundException("文章未找到"); main.Id = id; var diff = new HtmlDiff.HtmlDiff(right.Content, left.Content); var diffOutput = diff.Build(); right.Content = Regex.Replace(Regex.Replace(diffOutput, "<ins.+?</ins>", string.Empty), @"<\w+></\w+>", string.Empty); left.Content = Regex.Replace(Regex.Replace(diffOutput, "<del.+?</del>", string.Empty), @"<\w+></\w+>", string.Empty); return(View(new[] { main, left, right })); }
public async Task <ActionResult> CompareVersion(int id, int v1, int v2) { var main = PostService.Get(p => p.Id == id && (p.Status == Status.Pended || CurrentUser.IsAdmin)).Mapper <PostHistoryVersion>() ?? throw new NotFoundException("文章未找到"); var left = v1 <= 0 ? main : await PostHistoryVersionService.GetAsync(v => v.Id == v1) ?? throw new NotFoundException("文章未找到"); var right = v2 <= 0 ? main : await PostHistoryVersionService.GetAsync(v => v.Id == v2) ?? throw new NotFoundException("文章未找到"); main.Id = id; var diff = new HtmlDiff.HtmlDiff(right.Content, left.Content); var diffOutput = diff.Build(); right.Content = Regex.Replace(Regex.Replace(diffOutput, "<ins.+?</ins>", string.Empty), @"<\w+></\w+>", string.Empty); left.Content = Regex.Replace(Regex.Replace(diffOutput, "<del.+?</del>", string.Empty), @"<\w+></\w+>", string.Empty); ViewBag.Ads = AdsService.GetsByWeightedPrice(2, AdvertiseType.InPage, main.CategoryId); return(View(new[] { main, left, right })); }
public string Diff(ScrapingResult result) { if (result?.Text == null) { return("Target is null"); } if (result?.Text == Text) { return("Defference is not find."); } var diff = new HtmlDiff.HtmlDiff(result?.Text, Text); var html = diff.Build(); return(html); }
public string Index(string version1, string version2, string originalcontenttype) { version1 = HttpUtility.UrlDecode(Encoding.UTF8.GetString(Convert.FromBase64String(version1))); version2 = HttpUtility.UrlDecode(Encoding.UTF8.GetString(Convert.FromBase64String(version2))); HtmlDiff.HtmlDiff diffHelper = new HtmlDiff.HtmlDiff(version1, version2); var diffResult = diffHelper.Build(); string cssLink = $"<link href=\"/{_episerverUiUrlHelper.GetEpiserverSegment()}/VisualCompareMode/ClientResources/Styles/DiffStyles.css\" media=\"all\" rel=\"stylesheet\" />"; diffResult = diffResult.Replace("</head>", cssLink + "</head>"); diffResult = diffResult.Replace("<del class='diffmod'><img", "<del class='diffmod diff-image-deleted'><img"); diffResult = diffResult.Replace("<ins class='diffmod'><img", "<ins class='diffmod diff-image-inserted'><img"); return(diffResult); }
public ActionResult CompareVersion(int id, int v1, int v2) { var main = PostService.GetById(id).Mapper <PostHistoryVersion>(); main.Id = id; var left = v1 <= 0 ? main : PostHistoryVersionService.GetById(v1); var right = v2 <= 0 ? main : PostHistoryVersionService.GetById(v2); if (left is null || right is null) { return(RedirectToAction("History", "Post", new { id })); } var diffHelper = new HtmlDiff.HtmlDiff(right.Content, left.Content); string diffOutput = diffHelper.Build(); right.Content = Regex.Replace(Regex.Replace(diffOutput, "<ins.+?</ins>", string.Empty), @"<\w+></\w+>", string.Empty); left.Content = Regex.Replace(Regex.Replace(diffOutput, "<del.+?</del>", string.Empty), @"<\w+></\w+>", string.Empty); return(View(new[] { main, left, right })); }
public async Task <ActionResult> CompareVersion(int id, int v1, int v2) { var post = await PostService.GetAsync(p => p.Id == id && (p.Status == Status.Published || CurrentUser.IsAdmin)); var main = post.Mapper <PostHistoryVersion>() ?? throw new NotFoundException("文章未找到"); CheckPermission(post); var left = v1 <= 0 ? main : await PostHistoryVersionService.GetAsync(v => v.Id == v1) ?? throw new NotFoundException("文章未找到"); var right = v2 <= 0 ? main : await PostHistoryVersionService.GetAsync(v => v.Id == v2) ?? throw new NotFoundException("文章未找到"); main.Id = id; var diff = new HtmlDiff.HtmlDiff(right.Content, left.Content); var diffOutput = diff.Build(); right.Content = ReplaceVariables(Regex.Replace(Regex.Replace(diffOutput, "<ins.+?</ins>", string.Empty), @"<\w+></\w+>", string.Empty)); right.ModifyDate = right.ModifyDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); left.Content = ReplaceVariables(Regex.Replace(Regex.Replace(diffOutput, "<del.+?</del>", string.Empty), @"<\w+></\w+>", string.Empty)); left.ModifyDate = left.ModifyDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); ViewBag.Ads = AdsService.GetsByWeightedPrice(2, AdvertiseType.InPage, Request.Location(), main.CategoryId); ViewBag.DisableCopy = post.DisableCopy; return(View(new[] { main, left, right })); }
protected void Page_Load(object sender, EventArgs e) { string oldText = @"<p><i>This is</i> some sample text to <strong>demonstrate</strong> the capability of the <strong>HTML diff tool</strong>.</p> <p>It is based on the <b>Ruby</b> implementation found <a href='http://github.com/myobie/htmldiff'>here</a>. Note how the link has no tooltip</p> <p>What about a number change: 123456?</p> <table cellpadding='0' cellspacing='0'> <tr><td>Some sample text</td><td>Some sample value</td></tr> <tr><td>Data 1 (this row will be removed)</td><td>Data 2</td></tr> </table> Here is a number 2 32"; string newText = @"<p>This is some sample <strong>text to</strong> demonstrate the awesome capabilities of the <strong>HTML <u>diff</u> tool</strong>.</p><br/><br/>Extra spacing here that was not here before. <p>It is <i>based</i> on the Ruby implementation found <a title='Cool tooltip' href='http://github.com/myobie/htmldiff'>here</a>. Note how the link has a tooltip now and the HTML diff algorithm has preserved formatting.</p> <p>What about a number change: 123356?</p> <table cellpadding='0' cellspacing='0'> <tr><td>Some sample <strong>bold text</strong></td><td>Some sample value</td></tr> </table> Here is a number 2 <sup>32</sup>"; HtmlDiff.HtmlDiff diffHelper = new HtmlDiff.HtmlDiff(oldText, newText); litOldText.Text = oldText; litNewText.Text = newText; litDiffText.Text = diffHelper.Build(); }
protected void Page_Load(object sender, EventArgs e) { string oldText = @"<p><i>This is</i> some sample text to <strong>demonstrate</strong> the capability of the <strong>HTML diff tool</strong>.</p> <p>It is based on the <b>Ruby</b> implementation found <a href='http://github.com/myobie/htmldiff'>here</a>. Note how the link has no tooltip</p> <p>What about a number change: 123456?</p> <table cellpadding='0' cellspacing='0'> <tr><td>Some sample text</td><td>Some sample value</td></tr> <tr><td>Data 1 (this row will be removed)</td><td>Data 2</td></tr> </table> Here is a number 2 32"; string newText = @"<p>This is some sample <strong>text to</strong> demonstrate the awesome capabilities of the <strong>HTML <u>diff</u> tool</strong>.</p><br/><br/>Extra spacing here that was not here before. <p>It is <i>based</i> on the Ruby implementation found <a title='Cool tooltip' href='http://github.com/myobie/htmldiff'>here</a>. Note how the link has a tooltip now and the HTML diff algorithm has preserved formatting.</p> <p>What about a number change: 123356?</p> <table cellpadding='0' cellspacing='0'> <tr><td>Some sample <strong>bold text</strong></td><td>Some sample value</td></tr> </table> Here is a number 2 <sup>32</sup>"; HtmlDiff.HtmlDiff diffHelper = new HtmlDiff.HtmlDiff(oldText, newText); litOldText.Text = oldText; litNewText.Text = newText; litDiffText.Text = diffHelper.Build(); }
public async Task <IActionResult> OnGetAsync(int textid) { var article = await articleService.GetAsync(textid); var masterForArticle = (await articleService.BrowseAsync(1, null, article.Id, null)).SingleOrDefault(); ArticleDetailsDto masterForArticleDetails; if (masterForArticle.Master != null) { masterForArticleDetails = await articleService.GetAsync(masterForArticle.Master.Id); var diffHelper = new HtmlDiff.HtmlDiff(masterForArticleDetails.Master.Content, article.Master.Content); ContentComparision = diffHelper.Build(); diffHelper = new HtmlDiff.HtmlDiff(masterForArticleDetails.Master.Title, article.Master.Title); TitleComparision = diffHelper.Build(); } if (!httpContextAccessor.HttpContext.User.IsInRole("Read") && article.Master.Status.Id != 1 && article.Master.Author.Id != UserId) { return(Forbid()); } Article = CreateArticle(article); var otherVersions = await articleService.BrowseAsync(null, null, article.Id, null); OtherVersions = new List <ViewModels.Article>(); foreach (var item in otherVersions) { foreach (var text in item.Texts) { var art = new Article { Title = text.Title, }; var tags = new List <TagFilter>(); foreach (var tag in text.Tags) { tags.Add(new TagFilter { Id = tag.Id, Tag = tag.Tag, Checked = true }); } art.ArticleId = item.Id; art.TextId = text.Id; art.Tags = tags; art.Version = text.Version; art.Status = new StatusFilter { Id = text.Status.Id, Status = text.Status.Status, Selected = false }; if (item.Category != null) { art.Category = new CategoryFilter { Id = item.Category.Id, Category = item.Category.Category }; } OtherVersions.Add(art); } } return(Page()); }
private string GetDiffHtml(string text1, string text2) { HtmlDiff.HtmlDiff diffHelper = new HtmlDiff.HtmlDiff(text1, text2); return(diffHelper.Build()); }
public async Task <ActionResult> PushMerge([FromServices] IInternalMessageService messageService, [FromServices] IPostMergeRequestService postMergeRequestService, PostMergeRequestCommand dto) { if (await RedisHelper.GetAsync("code:" + dto.ModifierEmail) != dto.Code) { return(ResultData(null, false, "验证码错误!")); } var post = await PostService.GetByIdAsync(dto.PostId) ?? throw new NotFoundException("文章未找到"); var htmlDiff = new HtmlDiff.HtmlDiff(post.Content.RemoveHtmlTag(), dto.Content.RemoveHtmlTag()); var diff = htmlDiff.Build(); if (post.Title.Equals(dto.Title) && !diff.Contains(new[] { "diffmod", "diffdel", "diffins" })) { return(ResultData(null, false, "内容未被修改!")); } #region 合并验证 if (postMergeRequestService.Any(p => p.ModifierEmail == dto.ModifierEmail && p.MergeState == MergeStatus.Block)) { return(ResultData(null, false, "由于您曾经多次恶意修改文章,已经被标记为黑名单,无法修改任何文章,如有疑问,请联系网站管理员进行处理。")); } if (post.PostMergeRequests.Any(p => p.ModifierEmail == dto.ModifierEmail && p.MergeState == MergeStatus.Pending)) { return(ResultData(null, false, "您已经提交过一次修改请求正在待处理,暂不能继续提交修改请求!")); } #endregion #region 直接合并 if (post.Email.Equals(dto.ModifierEmail)) { var history = post.Mapper <PostHistoryVersion>(); Mapper.Map(dto, post); post.PostHistoryVersion.Add(history); post.ModifyDate = DateTime.Now; return(await PostService.SaveChangesAsync() > 0 ? ResultData(null, true, "你是文章原作者,无需审核,文章已自动更新并在首页展示!") : ResultData(null, false, "操作失败!")); } #endregion var merge = post.PostMergeRequests.FirstOrDefault(r => r.Id == dto.Id && r.MergeState != MergeStatus.Merged); if (merge != null) { Mapper.Map(dto, merge); merge.SubmitTime = DateTime.Now; merge.MergeState = MergeStatus.Pending; } else { merge = Mapper.Map <PostMergeRequest>(dto); merge.SubmitTime = DateTime.Now; post.PostMergeRequests.Add(merge); } var b = await PostService.SaveChangesAsync() > 0; if (!b) { return(ResultData(null, false, "操作失败!")); } await RedisHelper.ExpireAsync("code:" + dto.ModifierEmail, 1); await messageService.AddEntitySavedAsync(new InternalMessage() { Title = $"来自【{dto.Modifier}】对文章《{post.Title}》的修改请求", Content = dto.Title, Link = "#/merge/compare?id=" + merge.Id }); var content = new Template(await System.IO.File.ReadAllTextAsync(HostEnvironment.WebRootPath + "/template/merge-request.html")) .Set("title", post.Title) .Set("link", Url.Action("Index", "Dashboard", new { }, Request.Scheme) + "#/merge/compare?id=" + merge.Id) .Set("diff", diff) .Set("host", "//" + Request.Host) .Set("id", merge.Id.ToString()) .Render(); BackgroundJob.Enqueue(() => CommonHelper.SendMail("博客文章修改请求:", content, CommonHelper.SystemSettings["ReceiveEmail"], ClientIP)); return(ResultData(null, true, "您的修改请求已提交,已进入审核状态,感谢您的参与!")); }