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

Commit

Permalink
fix stackoverflow
Browse files Browse the repository at this point in the history
  • Loading branch information
OpportunityLiu committed May 30, 2020
1 parent 7a4fd86 commit 5ed5ea7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
15 changes: 10 additions & 5 deletions EhTagClient/MarkdigExt/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions EhTagClient/MarkdigExt/Html/CodeInlineRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class CodeInlineRenderer : HtmlObjectRenderer<CodeInline>
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("<ruby>");
if (tag != null)
{
renderer.WriteEscape(tag.Name.Text);
renderer.WriteEscape(tag);
if (renderer.EnableHtmlForInline)
{
renderer.Write("<rp>(</rp><rt>");
Expand Down
4 changes: 2 additions & 2 deletions EhTagClient/MarkdigExt/Json/JsonRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ sealed class CodeInlineRenderer : JsonObjectRenderer<CodeInline>
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
{
Expand Down
36 changes: 24 additions & 12 deletions EhTagClient/RecordDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using KVP = System.Collections.Generic.KeyValuePair<string, EhTagClient.Record>;

namespace EhTagClient
{
[DebuggerDisplay(@"Namespace={Namespace} Count={Count}")]
public class RecordDictionary
{
public RecordDictionary(Namespace ns, RepoClient repoClient)
Expand Down Expand Up @@ -38,7 +40,7 @@ public struct DataDic : IReadOnlyDictionary<string, Record>

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<string> Keys
{
Expand Down Expand Up @@ -66,7 +68,7 @@ public IEnumerable<Record> Values

public bool TryGetValue(string key, out Record value)
{
value = _Parent.Find(key);
value = _Parent.Find(key, false);
return !(value is null);

}
Expand Down Expand Up @@ -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;
Expand All @@ -123,19 +126,22 @@ public void Load()
else
continue;
case 1:
prefix.AppendLine(line);
prefix.Append(line);
prefix.Append('\n');
if (line == sep)
{
state = 2;
continue;
}
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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -168,7 +176,8 @@ public void Load()
continue;
}
default:
suffix.AppendLine(line);
suffix.Append(line);
suffix.Append('\n');
continue;
}
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 5ed5ea7

Please sign in to comment.