diff options
author | crupest <crupest@outlook.com> | 2021-04-25 21:20:04 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-04-25 21:20:04 +0800 |
commit | 657fb589137099794e58fbd35beb7d942b376965 (patch) | |
tree | 7ab03d970f4c556b0a005f94da2e0752e9d7ce99 /BackEnd/Timeline/Services/MarkdownProcessor.cs | |
parent | b64806226723df9a9deb64e80defc93860896f50 (diff) | |
download | timeline-657fb589137099794e58fbd35beb7d942b376965.tar.gz timeline-657fb589137099794e58fbd35beb7d942b376965.tar.bz2 timeline-657fb589137099794e58fbd35beb7d942b376965.zip |
...
Diffstat (limited to 'BackEnd/Timeline/Services/MarkdownProcessor.cs')
-rw-r--r-- | BackEnd/Timeline/Services/MarkdownProcessor.cs | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/BackEnd/Timeline/Services/MarkdownProcessor.cs b/BackEnd/Timeline/Services/MarkdownProcessor.cs deleted file mode 100644 index f34432cd..00000000 --- a/BackEnd/Timeline/Services/MarkdownProcessor.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System;
-using System.IO;
-using System.Linq;
-using System.Text;
-using Markdig;
-using Markdig.Renderers.Normalize;
-using Markdig.Syntax;
-using Markdig.Syntax.Inlines;
-using Microsoft.AspNetCore.Mvc;
-using Timeline.Controllers;
-
-namespace Timeline.Services
-{
- public class MarkdownProcessor
- {
- public string Process(string text, Func<long, string> urlGenerator)
- {
- MarkdownDocument markdown = Markdown.Parse(text);
- foreach (var link in markdown.Descendants().Where(e => e is LinkInline).Cast<LinkInline>())
- {
- if (int.TryParse(link.Url, out var dataIndex))
- {
- link.Url = urlGenerator(dataIndex);
- }
- }
-
- var writer = new StringWriter();
- NormalizeRenderer renderer = new NormalizeRenderer(writer);
- renderer.Render(markdown);
-
- return writer.ToString();
- }
-
- /// <summary>Convert data url to true url with post id.</summary>
- public string Process(string text, IUrlHelper url, string timeline, long post)
- {
- return Process(
- text,
- dataIndex => url.ActionLink(
- nameof(TimelinePostController.DataGet),
- nameof(TimelinePostController)[0..^nameof(Controller).Length],
- new { timeline, post, data_index = dataIndex }
- )
- );
- }
-
- public byte[] Process(byte[] data, IUrlHelper url, string timeline, long post)
- {
- return Encoding.UTF8.GetBytes(Process(Encoding.UTF8.GetString(data), url, timeline, post));
- }
- }
-}
|