diff --git a/EhTagClient/MarkdigExt/Extension.cs b/EhTagClient/MarkdigExt/Extension.cs index 64bc1e9..5dc5f0e 100644 --- a/EhTagClient/MarkdigExt/Extension.cs +++ b/EhTagClient/MarkdigExt/Extension.cs @@ -38,21 +38,26 @@ public static (string url, string title, string isNsfw) GetData(this LinkInline return (url, title, null); } - public static Record GetTag(string tag, Namespace ns) + public static string GetTagName(string tag, Namespace ns) { var table = Context.Database[ns]; - return table.Data[tag]; + var record = table.Find(tag, true); + if (record == null) + return null; + if (record.Name.Text == null) + record.Name.Render(); + return record.Name.Text; } - public static Record GetTag(string tag) + public static string GetTagName(string tag) { - var record = GetTag(tag, Context.Namespace); + var record = GetTagName(tag, Context.Namespace); if (record != null) return record; foreach (var item in Context.Database.Keys) { if (item != Context.Namespace) { - record = GetTag(tag, item); + record = GetTagName(tag, item); if (record != null) return record; } } diff --git a/EhTagClient/MarkdigExt/Html/CodeInlineRenderer.cs b/EhTagClient/MarkdigExt/Html/CodeInlineRenderer.cs index 8918f93..76459de 100644 --- a/EhTagClient/MarkdigExt/Html/CodeInlineRenderer.cs +++ b/EhTagClient/MarkdigExt/Html/CodeInlineRenderer.cs @@ -10,12 +10,12 @@ class CodeInlineRenderer : HtmlObjectRenderer protected override void Write(HtmlRenderer renderer, CodeInline obj) { var content = obj.Content; - var tag = Extension.GetTag(content); + var tag = Extension.GetTagName(content); if (renderer.EnableHtmlForInline) renderer.Write(""); if (tag != null) { - renderer.WriteEscape(tag.Name.Text); + renderer.WriteEscape(tag); if (renderer.EnableHtmlForInline) { renderer.Write("("); diff --git a/EhTagClient/MarkdigExt/Json/JsonRenderer.cs b/EhTagClient/MarkdigExt/Json/JsonRenderer.cs index 449308c..c8532d2 100644 --- a/EhTagClient/MarkdigExt/Json/JsonRenderer.cs +++ b/EhTagClient/MarkdigExt/Json/JsonRenderer.cs @@ -152,11 +152,11 @@ sealed class CodeInlineRenderer : JsonObjectRenderer protected override void WriteContent(JsonRenderer renderer, CodeInline obj) { var content = obj.Content; - var tag = Extension.GetTag(content); + var tag = Extension.GetTagName(content); if (tag != null) { renderer.WriteProperty("tag", content); - renderer.WriteProperty("text", tag.Name.Text); + renderer.WriteProperty("text", tag); } else { diff --git a/EhTagClient/RecordDictionary.cs b/EhTagClient/RecordDictionary.cs index 3cd00c2..33dfee8 100644 --- a/EhTagClient/RecordDictionary.cs +++ b/EhTagClient/RecordDictionary.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -9,6 +10,7 @@ namespace EhTagClient { + [DebuggerDisplay(@"Namespace={Namespace} Count={Count}")] public class RecordDictionary { public RecordDictionary(Namespace ns, RepoClient repoClient) @@ -38,7 +40,7 @@ public struct DataDic : IReadOnlyDictionary internal DataDic(RecordDictionary parent) => _Parent = parent; - public Record this[string key] => _Parent.Find(key); + public Record this[string key] => _Parent.Find(key, false); public IEnumerable Keys { @@ -66,7 +68,7 @@ public IEnumerable Values public bool TryGetValue(string key, out Record value) { - value = _Parent.Find(key); + value = _Parent.Find(key, false); return !(value is null); } @@ -108,7 +110,8 @@ public void Load() switch (state) { case 0: - prefix.AppendLine(line); + prefix.Append(line); + prefix.Append('\n'); if (record.Key != null) { state = 1; @@ -123,7 +126,8 @@ public void Load() else continue; case 1: - prefix.AppendLine(line); + prefix.Append(line); + prefix.Append('\n'); if (line == sep) { state = 2; @@ -131,11 +135,13 @@ public void Load() } else { - frontMatters.AppendLine(line); + frontMatters.Append(line); + frontMatters.Append('\n'); continue; } case 2: - prefix.AppendLine(line); + prefix.Append(line); + prefix.Append('\n'); if (record.Key != null) { state = 3; @@ -144,7 +150,8 @@ public void Load() else continue; case 3: - prefix.AppendLine(line); + prefix.Append(line); + prefix.Append('\n'); if (record.Key is null) { state = 2; @@ -158,7 +165,8 @@ public void Load() case 4: if (record.Key is null) { - suffix.AppendLine(line); + suffix.Append(line); + suffix.Append('\n'); state = 5; continue; } @@ -168,7 +176,8 @@ public void Load() continue; } default: - suffix.AppendLine(line); + suffix.Append(line); + suffix.Append('\n'); continue; } } @@ -216,13 +225,16 @@ public void Save() } } - public Record Find(string key) + public Record Find(string key, bool skipRender) { if (!MapData.TryGetValue(key, out var index)) return null; - Context.Namespace = Namespace; var record = RawData[index].Value; - record.Render(key); + if (!skipRender) + { + Context.Namespace = Namespace; + record.Render(key); + } return record; }