Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit 5ed5ea7

Browse files
fix stackoverflow
1 parent 7a4fd86 commit 5ed5ea7

4 files changed

Lines changed: 38 additions & 21 deletions

File tree

EhTagClient/MarkdigExt/Extension.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,26 @@ public static (string url, string title, string isNsfw) GetData(this LinkInline
3838

3939
return (url, title, null);
4040
}
41-
public static Record GetTag(string tag, Namespace ns)
41+
public static string GetTagName(string tag, Namespace ns)
4242
{
4343
var table = Context.Database[ns];
44-
return table.Data[tag];
44+
var record = table.Find(tag, true);
45+
if (record == null)
46+
return null;
47+
if (record.Name.Text == null)
48+
record.Name.Render();
49+
return record.Name.Text;
4550
}
4651

47-
public static Record GetTag(string tag)
52+
public static string GetTagName(string tag)
4853
{
49-
var record = GetTag(tag, Context.Namespace);
54+
var record = GetTagName(tag, Context.Namespace);
5055
if (record != null) return record;
5156
foreach (var item in Context.Database.Keys)
5257
{
5358
if (item != Context.Namespace)
5459
{
55-
record = GetTag(tag, item);
60+
record = GetTagName(tag, item);
5661
if (record != null) return record;
5762
}
5863
}

EhTagClient/MarkdigExt/Html/CodeInlineRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ class CodeInlineRenderer : HtmlObjectRenderer<CodeInline>
1010
protected override void Write(HtmlRenderer renderer, CodeInline obj)
1111
{
1212
var content = obj.Content;
13-
var tag = Extension.GetTag(content);
13+
var tag = Extension.GetTagName(content);
1414
if (renderer.EnableHtmlForInline)
1515
renderer.Write("<ruby>");
1616
if (tag != null)
1717
{
18-
renderer.WriteEscape(tag.Name.Text);
18+
renderer.WriteEscape(tag);
1919
if (renderer.EnableHtmlForInline)
2020
{
2121
renderer.Write("<rp>(</rp><rt>");

EhTagClient/MarkdigExt/Json/JsonRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ sealed class CodeInlineRenderer : JsonObjectRenderer<CodeInline>
152152
protected override void WriteContent(JsonRenderer renderer, CodeInline obj)
153153
{
154154
var content = obj.Content;
155-
var tag = Extension.GetTag(content);
155+
var tag = Extension.GetTagName(content);
156156
if (tag != null)
157157
{
158158
renderer.WriteProperty("tag", content);
159-
renderer.WriteProperty("text", tag.Name.Text);
159+
renderer.WriteProperty("text", tag);
160160
}
161161
else
162162
{

EhTagClient/RecordDictionary.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
using System;
33
using System.Collections;
44
using System.Collections.Generic;
5+
using System.Diagnostics;
56
using System.IO;
67
using System.Linq;
78
using System.Text;
89
using KVP = System.Collections.Generic.KeyValuePair<string, EhTagClient.Record>;
910

1011
namespace EhTagClient
1112
{
13+
[DebuggerDisplay(@"Namespace={Namespace} Count={Count}")]
1214
public class RecordDictionary
1315
{
1416
public RecordDictionary(Namespace ns, RepoClient repoClient)
@@ -38,7 +40,7 @@ public struct DataDic : IReadOnlyDictionary<string, Record>
3840

3941
internal DataDic(RecordDictionary parent) => _Parent = parent;
4042

41-
public Record this[string key] => _Parent.Find(key);
43+
public Record this[string key] => _Parent.Find(key, false);
4244

4345
public IEnumerable<string> Keys
4446
{
@@ -66,7 +68,7 @@ public IEnumerable<Record> Values
6668

6769
public bool TryGetValue(string key, out Record value)
6870
{
69-
value = _Parent.Find(key);
71+
value = _Parent.Find(key, false);
7072
return !(value is null);
7173

7274
}
@@ -108,7 +110,8 @@ public void Load()
108110
switch (state)
109111
{
110112
case 0:
111-
prefix.AppendLine(line);
113+
prefix.Append(line);
114+
prefix.Append('\n');
112115
if (record.Key != null)
113116
{
114117
state = 1;
@@ -123,19 +126,22 @@ public void Load()
123126
else
124127
continue;
125128
case 1:
126-
prefix.AppendLine(line);
129+
prefix.Append(line);
130+
prefix.Append('\n');
127131
if (line == sep)
128132
{
129133
state = 2;
130134
continue;
131135
}
132136
else
133137
{
134-
frontMatters.AppendLine(line);
138+
frontMatters.Append(line);
139+
frontMatters.Append('\n');
135140
continue;
136141
}
137142
case 2:
138-
prefix.AppendLine(line);
143+
prefix.Append(line);
144+
prefix.Append('\n');
139145
if (record.Key != null)
140146
{
141147
state = 3;
@@ -144,7 +150,8 @@ public void Load()
144150
else
145151
continue;
146152
case 3:
147-
prefix.AppendLine(line);
153+
prefix.Append(line);
154+
prefix.Append('\n');
148155
if (record.Key is null)
149156
{
150157
state = 2;
@@ -158,7 +165,8 @@ public void Load()
158165
case 4:
159166
if (record.Key is null)
160167
{
161-
suffix.AppendLine(line);
168+
suffix.Append(line);
169+
suffix.Append('\n');
162170
state = 5;
163171
continue;
164172
}
@@ -168,7 +176,8 @@ public void Load()
168176
continue;
169177
}
170178
default:
171-
suffix.AppendLine(line);
179+
suffix.Append(line);
180+
suffix.Append('\n');
172181
continue;
173182
}
174183
}
@@ -216,13 +225,16 @@ public void Save()
216225
}
217226
}
218227

219-
public Record Find(string key)
228+
public Record Find(string key, bool skipRender)
220229
{
221230
if (!MapData.TryGetValue(key, out var index))
222231
return null;
223-
Context.Namespace = Namespace;
224232
var record = RawData[index].Value;
225-
record.Render(key);
233+
if (!skipRender)
234+
{
235+
Context.Namespace = Namespace;
236+
record.Render(key);
237+
}
226238
return record;
227239
}
228240

0 commit comments

Comments
 (0)