Adding Syndicate Pages
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
@using System.Text.RegularExpressions
|
||||
@using Microsoft.AspNetCore.Components.Rendering
|
||||
@namespace Chrono.Components
|
||||
|
||||
@if (Card != null)
|
||||
@@ -50,7 +51,9 @@
|
||||
{
|
||||
<div class="detail-field description">
|
||||
<span class="field-label"><i class="bi bi-chat-quote-fill"></i></span>
|
||||
<span class="field-value">@RenderDescription(Card.Description)</span>
|
||||
<div class="markdown-content">
|
||||
@RenderDescription(Card.Description)
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -90,7 +93,7 @@
|
||||
if (target != null)
|
||||
{
|
||||
<button class="inline-card-btn"
|
||||
@onclick="() => Navigate(target)">@targetName</button>
|
||||
@onclick="() => Navigate(targetName)">@targetName</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -111,7 +114,7 @@
|
||||
if (fromCard != null)
|
||||
{
|
||||
<button class="inline-card-btn"
|
||||
@onclick="() => Navigate(fromCard)">@Card.ImmortalizeFrom</button>
|
||||
@onclick="() => Navigate(Card.ImmortalizeFrom)">@Card.ImmortalizeFrom</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -142,7 +145,7 @@
|
||||
@code {
|
||||
[Parameter] public CardData? Card { get; set; }
|
||||
[Parameter] public EventCallback OnClose { get; set; }
|
||||
[Parameter] public EventCallback<CardData> OnNavigate { get; set; }
|
||||
[Parameter] public EventCallback<string> OnNavigate { get; set; }
|
||||
[Parameter] public bool ShowNotes { get; set; }
|
||||
|
||||
[Inject] private HttpClient Http { get; set; } = default!;
|
||||
@@ -203,9 +206,19 @@
|
||||
_ = OnClose.InvokeAsync();
|
||||
}
|
||||
|
||||
private void Navigate(CardData card)
|
||||
private void Navigate(string name)
|
||||
{
|
||||
_ = OnNavigate.InvokeAsync(card);
|
||||
var card = LookupCard(name);
|
||||
if (card != null)
|
||||
{
|
||||
Card = card;
|
||||
_ = LoadNote();
|
||||
StateHasChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = OnNavigate.InvokeAsync(name);
|
||||
}
|
||||
}
|
||||
|
||||
private static CardData? LookupCard(string cardName)
|
||||
@@ -214,68 +227,205 @@
|
||||
string.Equals(c.Name, cardName, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private RenderFragment RenderDescription(string description)
|
||||
private static DocData? LookupDoc(string title)
|
||||
{
|
||||
return DocDatabase.Docs.FirstOrDefault(d =>
|
||||
string.Equals(d.Title, title, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private RenderFragment RenderDescription(string content)
|
||||
{
|
||||
return builder =>
|
||||
{
|
||||
var cardNames = CardDatabase.Cards
|
||||
.Select(c => c.Name)
|
||||
.Where(n => !string.IsNullOrWhiteSpace(n))
|
||||
.OrderByDescending(n => n.Length)
|
||||
.ToList();
|
||||
if (string.IsNullOrWhiteSpace(content)) return;
|
||||
|
||||
var seq = 0;
|
||||
var remaining = description;
|
||||
var lines = content.Split(['\r', '\n'], StringSplitOptions.None);
|
||||
var inList = false;
|
||||
var tableLines = new List<string>();
|
||||
var inTable = false;
|
||||
|
||||
while (!string.IsNullOrEmpty(remaining))
|
||||
for (var i = 0; i < lines.Length; i++)
|
||||
{
|
||||
var bestIdx = -1;
|
||||
string? bestName = null;
|
||||
var line = lines[i];
|
||||
var trimmedLine = line.Trim();
|
||||
|
||||
foreach (var name in cardNames)
|
||||
// Handle Tables
|
||||
if (trimmedLine.StartsWith("|") && trimmedLine.EndsWith("|"))
|
||||
{
|
||||
var pattern = $@"\b{Regex.Escape(name)}\b";
|
||||
var match = Regex.Match(remaining, pattern, RegexOptions.IgnoreCase);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
if (bestIdx == -1 || match.Index < bestIdx)
|
||||
{
|
||||
bestIdx = match.Index;
|
||||
bestName = match.Value;
|
||||
}
|
||||
}
|
||||
inTable = true;
|
||||
tableLines.Add(trimmedLine);
|
||||
continue;
|
||||
}
|
||||
else if (inTable)
|
||||
{
|
||||
RenderTable(builder, ref seq, tableLines);
|
||||
tableLines.Clear();
|
||||
inTable = false;
|
||||
}
|
||||
|
||||
if (bestIdx != -1 && bestName != null)
|
||||
// Handle Lists
|
||||
if (trimmedLine.StartsWith("- ") || trimmedLine.StartsWith("* "))
|
||||
{
|
||||
if (bestIdx > 0)
|
||||
builder.AddContent(seq++, remaining[..bestIdx]);
|
||||
if (!inList)
|
||||
{
|
||||
builder.OpenElement(seq++, "ul");
|
||||
inList = true;
|
||||
}
|
||||
var isCardListItem = trimmedLine.Contains("[[") && trimmedLine.Contains("]]");
|
||||
builder.OpenElement(seq++, "li");
|
||||
RenderInlines(builder, ref seq, trimmedLine[2..], true);
|
||||
builder.CloseElement();
|
||||
continue;
|
||||
}
|
||||
else if (inList)
|
||||
{
|
||||
builder.CloseElement(); // Close ul
|
||||
inList = false;
|
||||
}
|
||||
|
||||
var card = LookupCard(bestName);
|
||||
if (card != null)
|
||||
// Handle Headings
|
||||
if (trimmedLine.StartsWith("### "))
|
||||
{
|
||||
builder.OpenElement(seq++, "h4");
|
||||
RenderInlines(builder, ref seq, trimmedLine[4..], false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (trimmedLine.StartsWith("## "))
|
||||
{
|
||||
builder.OpenElement(seq++, "h3");
|
||||
RenderInlines(builder, ref seq, trimmedLine[3..], false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (trimmedLine.StartsWith("# "))
|
||||
{
|
||||
builder.OpenElement(seq++, "h2");
|
||||
RenderInlines(builder, ref seq, trimmedLine[2..], false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(trimmedLine))
|
||||
{
|
||||
builder.OpenElement(seq++, "p");
|
||||
RenderInlines(builder, ref seq, line, false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
}
|
||||
|
||||
if (inTable) RenderTable(builder, ref seq, tableLines);
|
||||
if (inList) builder.CloseElement();
|
||||
};
|
||||
}
|
||||
|
||||
private void RenderTable(RenderTreeBuilder builder, ref int seq, List<string> lines)
|
||||
{
|
||||
if (lines.Count < 2) return;
|
||||
|
||||
builder.OpenElement(seq++, "div");
|
||||
builder.AddAttribute(seq++, "class", "table-responsive");
|
||||
builder.OpenElement(seq++, "table");
|
||||
builder.AddAttribute(seq++, "class", "markdown-table");
|
||||
|
||||
var hasHeader = lines.Count > 2 && lines[1].Contains("---");
|
||||
var startIdx = 0;
|
||||
|
||||
if (hasHeader)
|
||||
{
|
||||
builder.OpenElement(seq++, "thead");
|
||||
builder.OpenElement(seq++, "tr");
|
||||
var cells = lines[0].Split('|', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var cell in cells)
|
||||
{
|
||||
builder.OpenElement(seq++, "th");
|
||||
RenderInlines(builder, ref seq, cell.Trim(), false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
builder.CloseElement();
|
||||
builder.CloseElement();
|
||||
startIdx = 2;
|
||||
}
|
||||
|
||||
builder.OpenElement(seq++, "tbody");
|
||||
for (var i = startIdx; i < lines.Count; i++)
|
||||
{
|
||||
if (i == 1 && hasHeader) continue;
|
||||
builder.OpenElement(seq++, "tr");
|
||||
var cells = lines[i].Split('|', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var cell in cells)
|
||||
{
|
||||
builder.OpenElement(seq++, "td");
|
||||
RenderInlines(builder, ref seq, cell.Trim(), false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
builder.CloseElement();
|
||||
}
|
||||
builder.CloseElement();
|
||||
builder.CloseElement();
|
||||
builder.CloseElement();
|
||||
}
|
||||
|
||||
private void RenderInlines(RenderTreeBuilder builder, ref int seq, string text, bool renderAsImage)
|
||||
{
|
||||
var remaining = text;
|
||||
|
||||
while (!string.IsNullOrEmpty(remaining))
|
||||
{
|
||||
var boldMatch = Regex.Match(remaining, @"\*\*(.*?)\*\*");
|
||||
var italicMatch = Regex.Match(remaining, @"\*(.*?)\*");
|
||||
var cardMatch = Regex.Match(remaining, @"\[\[(.*?)\]\]");
|
||||
|
||||
var bestIdx = int.MaxValue;
|
||||
Match? bestMatch = null;
|
||||
int matchType = 0; // 1: bold, 2: italic, 3: card
|
||||
|
||||
if (boldMatch.Success && boldMatch.Index < bestIdx) { bestIdx = boldMatch.Index; bestMatch = boldMatch; matchType = 1; }
|
||||
if (italicMatch.Success && italicMatch.Index < bestIdx) { bestIdx = italicMatch.Index; bestMatch = italicMatch; matchType = 2; }
|
||||
if (cardMatch.Success && cardMatch.Index < bestIdx) { bestIdx = cardMatch.Index; bestMatch = cardMatch; matchType = 3; }
|
||||
|
||||
if (bestMatch != null)
|
||||
{
|
||||
if (bestIdx > 0)
|
||||
builder.AddContent(seq++, remaining[..bestIdx]);
|
||||
|
||||
var innerText = bestMatch.Groups[1].Value;
|
||||
|
||||
if (matchType == 1) // Bold
|
||||
{
|
||||
builder.OpenElement(seq++, "strong");
|
||||
builder.AddContent(seq++, innerText);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (matchType == 2) // Italic
|
||||
{
|
||||
builder.OpenElement(seq++, "em");
|
||||
builder.AddContent(seq++, innerText);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (matchType == 3) // Card Link / Doc Link
|
||||
{
|
||||
var card = LookupCard(innerText);
|
||||
var doc = LookupDoc(innerText);
|
||||
if (card != null || doc != null)
|
||||
{
|
||||
builder.OpenElement(seq++, "button");
|
||||
builder.AddAttribute(seq++, "class", "inline-card-btn");
|
||||
builder.AddAttribute(seq++, "onclick",
|
||||
EventCallback.Factory.Create(this, () => Navigate(card)));
|
||||
builder.AddContent(seq++, bestName);
|
||||
builder.AddAttribute(seq++, "onclick", EventCallback.Factory.Create(this, () => Navigate(innerText)));
|
||||
builder.AddContent(seq++, innerText);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.AddContent(seq++, bestName);
|
||||
builder.AddContent(seq++, innerText);
|
||||
}
|
||||
}
|
||||
|
||||
remaining = remaining[(bestIdx + bestName.Length)..];
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.AddContent(seq++, remaining);
|
||||
remaining = "";
|
||||
}
|
||||
remaining = remaining[(bestIdx + bestMatch.Length)..];
|
||||
}
|
||||
};
|
||||
else
|
||||
{
|
||||
builder.AddContent(seq++, remaining);
|
||||
remaining = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.modal-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1040;
|
||||
z-index: 1060;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
backdrop-filter: blur(4px);
|
||||
animation: fade-in 0.2s ease-out;
|
||||
@@ -21,7 +21,7 @@
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
z-index: 1050;
|
||||
z-index: 1070;
|
||||
background: var(--bg-surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 16px;
|
||||
@@ -200,8 +200,55 @@
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.detail-field.description .field-value {
|
||||
.markdown-content {
|
||||
color: var(--text-primary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.markdown-content p {
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.markdown-content ul {
|
||||
margin-bottom: 0.75rem;
|
||||
padding-left: 1.25rem;
|
||||
}
|
||||
|
||||
.markdown-content li {
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.markdown-content h2, .markdown-content h3, .markdown-content h4 {
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 0.75rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.markdown-content h2 { font-size: 1.3rem; }
|
||||
.markdown-content h3 { font-size: 1.2rem; }
|
||||
.markdown-content h4 { font-size: 1rem; }
|
||||
|
||||
.table-responsive {
|
||||
overflow-x: auto;
|
||||
margin-bottom: 1rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.markdown-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.markdown-table th, .markdown-table td {
|
||||
padding: 0.5rem;
|
||||
border: 1px solid var(--border);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.markdown-table th {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.card-detail::-webkit-scrollbar {
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
@using Model
|
||||
@using System.Text.RegularExpressions
|
||||
@using Microsoft.AspNetCore.Components.Rendering
|
||||
@namespace Chrono.Components
|
||||
|
||||
@if (Doc != null)
|
||||
{
|
||||
<div class="modal-backdrop" @onclick="HandleBackdropClick"></div>
|
||||
<div class="generic-detail">
|
||||
<button class="detail-close" @onclick="HandleClose"><i class="bi bi-x-lg"></i></button>
|
||||
<div class="detail-layout">
|
||||
<div class="detail-info">
|
||||
<div class="detail-header">
|
||||
@if (!string.IsNullOrEmpty(Doc.Category))
|
||||
{
|
||||
<span class="category-badge">@Doc.Category</span>
|
||||
}
|
||||
<h2>@Doc.Title</h2>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(Doc.Content))
|
||||
{
|
||||
<div class="detail-field description">
|
||||
<div class="markdown-content">
|
||||
@RenderDescription(Doc.Content)
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public DocData? Doc { get; set; }
|
||||
[Parameter] public EventCallback OnClose { get; set; }
|
||||
|
||||
private void HandleClose() => _ = OnClose.InvokeAsync();
|
||||
private void HandleBackdropClick() => _ = OnClose.InvokeAsync();
|
||||
|
||||
private RenderFragment RenderDescription(string content)
|
||||
{
|
||||
return builder =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(content)) return;
|
||||
|
||||
var seq = 0;
|
||||
var lines = content.Split(['\r', '\n'], StringSplitOptions.None);
|
||||
var inList = false;
|
||||
|
||||
for (var i = 0; i < lines.Length; i++)
|
||||
{
|
||||
var line = lines[i];
|
||||
var trimmedLine = line.Trim();
|
||||
|
||||
// Handle Lists
|
||||
if (trimmedLine.StartsWith("- ") || trimmedLine.StartsWith("* "))
|
||||
{
|
||||
if (!inList)
|
||||
{
|
||||
builder.OpenElement(seq++, "ul");
|
||||
inList = true;
|
||||
}
|
||||
builder.OpenElement(seq++, "li");
|
||||
RenderInlines(builder, ref seq, trimmedLine[2..]);
|
||||
builder.CloseElement();
|
||||
continue;
|
||||
}
|
||||
else if (inList)
|
||||
{
|
||||
builder.CloseElement();
|
||||
inList = false;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(trimmedLine))
|
||||
{
|
||||
builder.OpenElement(seq++, "p");
|
||||
RenderInlines(builder, ref seq, line);
|
||||
builder.CloseElement();
|
||||
}
|
||||
}
|
||||
|
||||
if (inList) builder.CloseElement();
|
||||
};
|
||||
}
|
||||
|
||||
private void RenderInlines(RenderTreeBuilder builder, ref int seq, string text)
|
||||
{
|
||||
var remaining = text;
|
||||
while (!string.IsNullOrEmpty(remaining))
|
||||
{
|
||||
var boldMatch = Regex.Match(remaining, @"\*\*(.*?)\*\*");
|
||||
var italicMatch = Regex.Match(remaining, @"\*(.*?)\*");
|
||||
|
||||
var bestIdx = int.MaxValue;
|
||||
Match? bestMatch = null;
|
||||
int matchType = 0; // 1: bold, 2: italic
|
||||
|
||||
if (boldMatch.Success && boldMatch.Index < bestIdx) { bestIdx = boldMatch.Index; bestMatch = boldMatch; matchType = 1; }
|
||||
if (italicMatch.Success && italicMatch.Index < bestIdx) { bestIdx = italicMatch.Index; bestMatch = italicMatch; matchType = 2; }
|
||||
|
||||
if (bestMatch != null)
|
||||
{
|
||||
if (bestIdx > 0) builder.AddContent(seq++, remaining[..bestIdx]);
|
||||
var innerText = bestMatch.Groups[1].Value;
|
||||
builder.OpenElement(seq++, matchType == 1 ? "strong" : "em");
|
||||
builder.AddContent(seq++, innerText);
|
||||
builder.CloseElement();
|
||||
remaining = remaining[(bestIdx + bestMatch.Length)..];
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.AddContent(seq++, remaining);
|
||||
remaining = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
.modal-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1060;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.generic-detail {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
z-index: 1070;
|
||||
background: var(--bg-surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 20px;
|
||||
padding: 2rem;
|
||||
max-width: 600px;
|
||||
width: 90vw;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.detail-close {
|
||||
position: absolute;
|
||||
top: 1rem;
|
||||
right: 1rem;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
color: var(--text-primary);
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.detail-close:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.detail-header {
|
||||
text-align: center;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.category-badge {
|
||||
display: inline-block;
|
||||
padding: 0.2rem 0.6rem;
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 0.5rem;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.detail-header h2 {
|
||||
margin: 0;
|
||||
font-size: 1.5rem;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.markdown-content {
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.markdown-content p {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
@@ -36,6 +36,11 @@
|
||||
<i class="bi bi-diagram-2-fill nav-icon"></i> Syndicates
|
||||
</NavLink>
|
||||
</div>
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="syndicate-pairings">
|
||||
<i class="bi bi-intersect nav-icon"></i> Pairings
|
||||
</NavLink>
|
||||
</div>
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="docs">
|
||||
<i class="bi bi-book-fill nav-icon"></i> Docs
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
@using System.Text.RegularExpressions
|
||||
@using Microsoft.AspNetCore.Components.Rendering
|
||||
@namespace Chrono.Components
|
||||
|
||||
@if (Doc != null)
|
||||
{
|
||||
<div class="modal-backdrop" @onclick="HandleBackdropClick"></div>
|
||||
<div class="card-detail card-detail-noimg">
|
||||
<button class="detail-close" @onclick="HandleClose"><i class="bi bi-x-lg"></i></button>
|
||||
<div class="detail-layout layout-noimg">
|
||||
<div class="detail-info">
|
||||
<div class="detail-header">
|
||||
<div class="syndicate-badges">
|
||||
<span class="syn-icon @Doc.Title.ToLowerInvariant()" title="@Doc.Title"></span>
|
||||
</div>
|
||||
<h2>@Doc.Title</h2>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(Doc.Content))
|
||||
{
|
||||
<div class="detail-field description">
|
||||
<div class="markdown-content">
|
||||
@RenderDescription(Doc.Content)
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public DocData? Doc { get; set; }
|
||||
[Parameter] public EventCallback OnClose { get; set; }
|
||||
[Parameter] public EventCallback<string> OnNavigate { get; set; }
|
||||
|
||||
private void HandleClose()
|
||||
{
|
||||
_ = OnClose.InvokeAsync();
|
||||
}
|
||||
|
||||
private void HandleBackdropClick()
|
||||
{
|
||||
_ = OnClose.InvokeAsync();
|
||||
}
|
||||
|
||||
private void Navigate(string name)
|
||||
{
|
||||
_ = OnNavigate.InvokeAsync(name);
|
||||
}
|
||||
|
||||
private static CardData? LookupCard(string cardName)
|
||||
{
|
||||
return CardDatabase.Cards.FirstOrDefault(c =>
|
||||
string.Equals(c.Name, cardName, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static DocData? LookupDoc(string title)
|
||||
{
|
||||
return DocDatabase.Docs.FirstOrDefault(d =>
|
||||
string.Equals(d.Title, title, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private RenderFragment RenderDescription(string content)
|
||||
{
|
||||
return builder =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(content)) return;
|
||||
|
||||
var seq = 0;
|
||||
var lines = content.Split(['\r', '\n'], StringSplitOptions.None);
|
||||
var inList = false;
|
||||
var tableLines = new List<string>();
|
||||
var inTable = false;
|
||||
|
||||
for (var i = 0; i < lines.Length; i++)
|
||||
{
|
||||
var line = lines[i];
|
||||
var trimmedLine = line.Trim();
|
||||
|
||||
// Handle Tables
|
||||
if (trimmedLine.StartsWith("|") && trimmedLine.EndsWith("|"))
|
||||
{
|
||||
inTable = true;
|
||||
tableLines.Add(trimmedLine);
|
||||
continue;
|
||||
}
|
||||
else if (inTable)
|
||||
{
|
||||
RenderTable(builder, ref seq, tableLines);
|
||||
tableLines.Clear();
|
||||
inTable = false;
|
||||
}
|
||||
|
||||
// Handle Lists
|
||||
if (trimmedLine.StartsWith("- ") || trimmedLine.StartsWith("* "))
|
||||
{
|
||||
if (!inList)
|
||||
{
|
||||
builder.OpenElement(seq++, "ul");
|
||||
inList = true;
|
||||
}
|
||||
var isCardListItem = trimmedLine.Contains("[[") && trimmedLine.Contains("]]");
|
||||
builder.OpenElement(seq++, "li");
|
||||
RenderInlines(builder, ref seq, trimmedLine[2..], true);
|
||||
builder.CloseElement();
|
||||
continue;
|
||||
}
|
||||
else if (inList)
|
||||
{
|
||||
builder.CloseElement(); // Close ul
|
||||
inList = false;
|
||||
}
|
||||
|
||||
// Handle Headings
|
||||
if (trimmedLine.StartsWith("### "))
|
||||
{
|
||||
builder.OpenElement(seq++, "h4");
|
||||
RenderInlines(builder, ref seq, trimmedLine[4..], false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (trimmedLine.StartsWith("## "))
|
||||
{
|
||||
builder.OpenElement(seq++, "h3");
|
||||
RenderInlines(builder, ref seq, trimmedLine[3..], false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (trimmedLine.StartsWith("# "))
|
||||
{
|
||||
builder.OpenElement(seq++, "h2");
|
||||
RenderInlines(builder, ref seq, trimmedLine[2..], false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(trimmedLine))
|
||||
{
|
||||
builder.OpenElement(seq++, "p");
|
||||
RenderInlines(builder, ref seq, line, false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
}
|
||||
|
||||
if (inTable) RenderTable(builder, ref seq, tableLines);
|
||||
if (inList) builder.CloseElement();
|
||||
};
|
||||
}
|
||||
|
||||
private void RenderTable(RenderTreeBuilder builder, ref int seq, List<string> lines)
|
||||
{
|
||||
if (lines.Count < 2) return;
|
||||
|
||||
builder.OpenElement(seq++, "div");
|
||||
builder.AddAttribute(seq++, "class", "table-responsive");
|
||||
builder.OpenElement(seq++, "table");
|
||||
builder.AddAttribute(seq++, "class", "markdown-table");
|
||||
|
||||
var hasHeader = lines.Count > 2 && lines[1].Contains("---");
|
||||
var startIdx = 0;
|
||||
|
||||
if (hasHeader)
|
||||
{
|
||||
builder.OpenElement(seq++, "thead");
|
||||
builder.OpenElement(seq++, "tr");
|
||||
var cells = lines[0].Split('|', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var cell in cells)
|
||||
{
|
||||
builder.OpenElement(seq++, "th");
|
||||
RenderInlines(builder, ref seq, cell.Trim(), false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
builder.CloseElement();
|
||||
builder.CloseElement();
|
||||
startIdx = 2;
|
||||
}
|
||||
|
||||
builder.OpenElement(seq++, "tbody");
|
||||
for (var i = startIdx; i < lines.Count; i++)
|
||||
{
|
||||
if (i == 1 && hasHeader) continue;
|
||||
builder.OpenElement(seq++, "tr");
|
||||
var cells = lines[i].Split('|', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var cell in cells)
|
||||
{
|
||||
builder.OpenElement(seq++, "td");
|
||||
RenderInlines(builder, ref seq, cell.Trim(), false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
builder.CloseElement();
|
||||
}
|
||||
builder.CloseElement();
|
||||
builder.CloseElement();
|
||||
builder.CloseElement();
|
||||
}
|
||||
|
||||
private void RenderInlines(RenderTreeBuilder builder, ref int seq, string text, bool renderAsImage)
|
||||
{
|
||||
var remaining = text;
|
||||
|
||||
while (!string.IsNullOrEmpty(remaining))
|
||||
{
|
||||
var boldMatch = Regex.Match(remaining, @"\*\*(.*?)\*\*");
|
||||
var italicMatch = Regex.Match(remaining, @"\*(.*?)\*");
|
||||
var cardMatch = Regex.Match(remaining, @"\[\[(.*?)\]\]");
|
||||
|
||||
var bestIdx = int.MaxValue;
|
||||
Match? bestMatch = null;
|
||||
int matchType = 0; // 1: bold, 2: italic, 3: card
|
||||
|
||||
if (boldMatch.Success && boldMatch.Index < bestIdx) { bestIdx = boldMatch.Index; bestMatch = boldMatch; matchType = 1; }
|
||||
if (italicMatch.Success && italicMatch.Index < bestIdx) { bestIdx = italicMatch.Index; bestMatch = italicMatch; matchType = 2; }
|
||||
if (cardMatch.Success && cardMatch.Index < bestIdx) { bestIdx = cardMatch.Index; bestMatch = cardMatch; matchType = 3; }
|
||||
|
||||
if (bestMatch != null)
|
||||
{
|
||||
if (bestIdx > 0)
|
||||
builder.AddContent(seq++, remaining[..bestIdx]);
|
||||
|
||||
var innerText = bestMatch.Groups[1].Value;
|
||||
|
||||
if (matchType == 1) // Bold
|
||||
{
|
||||
builder.OpenElement(seq++, "strong");
|
||||
builder.AddContent(seq++, innerText);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (matchType == 2) // Italic
|
||||
{
|
||||
builder.OpenElement(seq++, "em");
|
||||
builder.AddContent(seq++, innerText);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (matchType == 3) // Card Link / Doc Link
|
||||
{
|
||||
var card = LookupCard(innerText);
|
||||
var doc = LookupDoc(innerText);
|
||||
if (card != null || doc != null)
|
||||
{
|
||||
builder.OpenElement(seq++, "button");
|
||||
builder.AddAttribute(seq++, "class", "inline-card-btn");
|
||||
builder.AddAttribute(seq++, "onclick", EventCallback.Factory.Create(this, () => Navigate(innerText)));
|
||||
builder.AddContent(seq++, innerText);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.AddContent(seq++, innerText);
|
||||
}
|
||||
}
|
||||
|
||||
remaining = remaining[(bestIdx + bestMatch.Length)..];
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.AddContent(seq++, remaining);
|
||||
remaining = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
.modal-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1040;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
backdrop-filter: blur(4px);
|
||||
animation: fade-in 0.2s ease-out;
|
||||
}
|
||||
|
||||
@keyframes fade-in {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
.card-detail {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
z-index: 1050;
|
||||
background: var(--bg-surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 20px;
|
||||
padding: 0;
|
||||
max-width: 1100px;
|
||||
width: 95vw;
|
||||
height: 90vh;
|
||||
max-height: 95vh;
|
||||
overflow-y: auto;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
|
||||
color: var(--text-primary);
|
||||
animation: detail-enter 0.25s ease-out;
|
||||
}
|
||||
|
||||
@keyframes detail-enter {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translate(-50%, -50%) scale(0.95);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translate(-50%, -50%) scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.detail-close {
|
||||
position: absolute;
|
||||
top: 1rem;
|
||||
right: 1rem;
|
||||
z-index: 1;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
color: var(--text-primary);
|
||||
width: 2.2rem;
|
||||
height: 2.2rem;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
transition: all var(--transition);
|
||||
}
|
||||
|
||||
.detail-close:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.detail-layout {
|
||||
display: flex;
|
||||
padding: 2.5rem 2rem 2rem;
|
||||
}
|
||||
|
||||
.detail-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.detail-header {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.syndicate-badges {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.syn-icon {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
background: currentColor;
|
||||
box-shadow: 0 0 15px currentColor;
|
||||
border: 2px solid rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.detail-header h2 {
|
||||
margin: 0 0 0.5rem;
|
||||
font-size: 1.8rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: -0.02em;
|
||||
background: linear-gradient(135deg, #fff 0%, #aaa 100%);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}
|
||||
|
||||
.detail-field {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.detail-field.description {
|
||||
padding: 0;
|
||||
border-radius: 0;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.detail-field.description .field-value {
|
||||
color: var(--text-primary);
|
||||
display: block;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.markdown-content {
|
||||
color: var(--text-primary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.markdown-content p {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.markdown-content ul {
|
||||
margin-bottom: 1rem;
|
||||
padding-left: 1.5rem;
|
||||
}
|
||||
|
||||
.markdown-content li {
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.markdown-content h2, .markdown-content h3, .markdown-content h4 {
|
||||
margin-top: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.markdown-content h2 { font-size: 1.5rem; }
|
||||
.markdown-content h3 { font-size: 1.3rem; }
|
||||
.markdown-content h4 { font-size: 1.1rem; }
|
||||
|
||||
/* Syndicate Colors */
|
||||
.lifeblood { color: #4caf50; }
|
||||
.phasetide { color: #2196f3; }
|
||||
.silence { color: #9c27b0; }
|
||||
.singularity { color: #ffffff; }
|
||||
.splintergleam { color: #f44336; }
|
||||
.sungrace { color: #ff9800; }
|
||||
|
||||
.inline-card-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
font-weight: 600;
|
||||
color: var(--accent);
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 2px;
|
||||
text-decoration-color: rgba(108, 99, 255, 0.3);
|
||||
transition: all var(--transition);
|
||||
}
|
||||
|
||||
.inline-card-btn:hover {
|
||||
color: #7b73ff;
|
||||
text-decoration-color: #7b73ff;
|
||||
}
|
||||
|
||||
.card-detail::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.card-detail::-webkit-scrollbar-thumb {
|
||||
background: var(--border);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.card-detail {
|
||||
width: 95vw;
|
||||
max-height: 90vh;
|
||||
}
|
||||
.detail-layout {
|
||||
padding: 2rem 1.25rem;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
@using System.Text.RegularExpressions
|
||||
@using Microsoft.AspNetCore.Components.Rendering
|
||||
@namespace Chrono.Components
|
||||
|
||||
@if (Doc != null)
|
||||
@@ -24,7 +25,9 @@
|
||||
@if (!string.IsNullOrWhiteSpace(Doc.Content))
|
||||
{
|
||||
<div class="detail-field description">
|
||||
<span class="field-value">@RenderDescription(Doc.Content)</span>
|
||||
<div class="markdown-content">
|
||||
@RenderDescription(Doc.Content)
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -35,7 +38,7 @@
|
||||
@code {
|
||||
[Parameter] public DocData? Doc { get; set; }
|
||||
[Parameter] public EventCallback OnClose { get; set; }
|
||||
[Parameter] public EventCallback<CardData> OnNavigate { get; set; }
|
||||
[Parameter] public EventCallback<string> OnNavigate { get; set; }
|
||||
|
||||
private void HandleClose()
|
||||
{
|
||||
@@ -47,9 +50,9 @@
|
||||
_ = OnClose.InvokeAsync();
|
||||
}
|
||||
|
||||
private void Navigate(CardData card)
|
||||
private void Navigate(string name)
|
||||
{
|
||||
_ = OnNavigate.InvokeAsync(card);
|
||||
_ = OnNavigate.InvokeAsync(name);
|
||||
}
|
||||
|
||||
private static CardData? LookupCard(string cardName)
|
||||
@@ -58,82 +61,205 @@
|
||||
string.Equals(c.Name, cardName, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private RenderFragment RenderDescription(string description)
|
||||
private static DocData? LookupDoc(string title)
|
||||
{
|
||||
return DocDatabase.Docs.FirstOrDefault(d =>
|
||||
string.Equals(d.Title, title, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private RenderFragment RenderDescription(string content)
|
||||
{
|
||||
return builder =>
|
||||
{
|
||||
var cardNames = CardDatabase.Cards
|
||||
.Select(c => c.Name)
|
||||
.Where(n => !string.IsNullOrWhiteSpace(n))
|
||||
.OrderByDescending(n => n.Length)
|
||||
.ToList();
|
||||
if (string.IsNullOrWhiteSpace(content)) return;
|
||||
|
||||
var seq = 0;
|
||||
var remaining = description;
|
||||
var lines = content.Split(['\r', '\n'], StringSplitOptions.None);
|
||||
var inList = false;
|
||||
var tableLines = new List<string>();
|
||||
var inTable = false;
|
||||
|
||||
while (!string.IsNullOrEmpty(remaining))
|
||||
for (var i = 0; i < lines.Length; i++)
|
||||
{
|
||||
var bestIdx = -1;
|
||||
string? bestName = null;
|
||||
var line = lines[i];
|
||||
var trimmedLine = line.Trim();
|
||||
|
||||
foreach (var name in cardNames)
|
||||
// Handle Tables
|
||||
if (trimmedLine.StartsWith("|") && trimmedLine.EndsWith("|"))
|
||||
{
|
||||
var pattern = $@"\b{Regex.Escape(name)}\b";
|
||||
var match = Regex.Match(remaining, pattern, RegexOptions.IgnoreCase);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
if (bestIdx == -1 || match.Index < bestIdx)
|
||||
{
|
||||
bestIdx = match.Index;
|
||||
bestName = match.Value;
|
||||
}
|
||||
}
|
||||
inTable = true;
|
||||
tableLines.Add(trimmedLine);
|
||||
continue;
|
||||
}
|
||||
else if (inTable)
|
||||
{
|
||||
RenderTable(builder, ref seq, tableLines);
|
||||
tableLines.Clear();
|
||||
inTable = false;
|
||||
}
|
||||
|
||||
// Also check for [[Card Name]] format which is common in docs
|
||||
var bracketMatch = Regex.Match(remaining, @"\[\[(.*?)\]\]");
|
||||
if (bracketMatch.Success)
|
||||
// Handle Lists
|
||||
if (trimmedLine.StartsWith("- ") || trimmedLine.StartsWith("* "))
|
||||
{
|
||||
if (bestIdx == -1 || bracketMatch.Index < bestIdx)
|
||||
if (!inList)
|
||||
{
|
||||
bestIdx = bracketMatch.Index;
|
||||
bestName = bracketMatch.Value;
|
||||
builder.OpenElement(seq++, "ul");
|
||||
inList = true;
|
||||
}
|
||||
var isCardListItem = trimmedLine.Contains("[[") && trimmedLine.Contains("]]");
|
||||
builder.OpenElement(seq++, "li");
|
||||
RenderInlines(builder, ref seq, trimmedLine[2..], true);
|
||||
builder.CloseElement();
|
||||
continue;
|
||||
}
|
||||
else if (inList)
|
||||
{
|
||||
builder.CloseElement(); // Close ul
|
||||
inList = false;
|
||||
}
|
||||
|
||||
if (bestIdx != -1 && bestName != null)
|
||||
// Handle Headings
|
||||
if (trimmedLine.StartsWith("### "))
|
||||
{
|
||||
if (bestIdx > 0)
|
||||
builder.AddContent(seq++, remaining[..bestIdx]);
|
||||
builder.OpenElement(seq++, "h4");
|
||||
RenderInlines(builder, ref seq, trimmedLine[4..], false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (trimmedLine.StartsWith("## "))
|
||||
{
|
||||
builder.OpenElement(seq++, "h3");
|
||||
RenderInlines(builder, ref seq, trimmedLine[3..], false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (trimmedLine.StartsWith("# "))
|
||||
{
|
||||
builder.OpenElement(seq++, "h2");
|
||||
RenderInlines(builder, ref seq, trimmedLine[2..], false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(trimmedLine))
|
||||
{
|
||||
builder.OpenElement(seq++, "p");
|
||||
RenderInlines(builder, ref seq, line, false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
}
|
||||
|
||||
var cleanName = bestName.StartsWith("[[") && bestName.EndsWith("]]")
|
||||
? bestName.Substring(2, bestName.Length - 4)
|
||||
: bestName;
|
||||
|
||||
var card = LookupCard(cleanName);
|
||||
if (card != null)
|
||||
if (inTable) RenderTable(builder, ref seq, tableLines);
|
||||
if (inList) builder.CloseElement();
|
||||
};
|
||||
}
|
||||
|
||||
private void RenderTable(RenderTreeBuilder builder, ref int seq, List<string> lines)
|
||||
{
|
||||
if (lines.Count < 2) return;
|
||||
|
||||
builder.OpenElement(seq++, "div");
|
||||
builder.AddAttribute(seq++, "class", "table-responsive");
|
||||
builder.OpenElement(seq++, "table");
|
||||
builder.AddAttribute(seq++, "class", "markdown-table");
|
||||
|
||||
var hasHeader = lines.Count > 2 && lines[1].Contains("---");
|
||||
var startIdx = 0;
|
||||
|
||||
if (hasHeader)
|
||||
{
|
||||
builder.OpenElement(seq++, "thead");
|
||||
builder.OpenElement(seq++, "tr");
|
||||
var cells = lines[0].Split('|', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var cell in cells)
|
||||
{
|
||||
builder.OpenElement(seq++, "th");
|
||||
RenderInlines(builder, ref seq, cell.Trim(), false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
builder.CloseElement();
|
||||
builder.CloseElement();
|
||||
startIdx = 2;
|
||||
}
|
||||
|
||||
builder.OpenElement(seq++, "tbody");
|
||||
for (var i = startIdx; i < lines.Count; i++)
|
||||
{
|
||||
if (i == 1 && hasHeader) continue;
|
||||
builder.OpenElement(seq++, "tr");
|
||||
var cells = lines[i].Split('|', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var cell in cells)
|
||||
{
|
||||
builder.OpenElement(seq++, "td");
|
||||
RenderInlines(builder, ref seq, cell.Trim(), false);
|
||||
builder.CloseElement();
|
||||
}
|
||||
builder.CloseElement();
|
||||
}
|
||||
builder.CloseElement();
|
||||
builder.CloseElement();
|
||||
builder.CloseElement();
|
||||
}
|
||||
|
||||
private void RenderInlines(RenderTreeBuilder builder, ref int seq, string text, bool renderAsImage)
|
||||
{
|
||||
// Simple regex-based inline parser for Bold, Italics, and [[Card Links]]
|
||||
var remaining = text;
|
||||
|
||||
while (!string.IsNullOrEmpty(remaining))
|
||||
{
|
||||
var boldMatch = Regex.Match(remaining, @"\*\*(.*?)\*\*");
|
||||
var italicMatch = Regex.Match(remaining, @"\*(.*?)\*");
|
||||
var cardMatch = Regex.Match(remaining, @"\[\[(.*?)\]\]");
|
||||
|
||||
var bestIdx = int.MaxValue;
|
||||
Match? bestMatch = null;
|
||||
int matchType = 0; // 1: bold, 2: italic, 3: card
|
||||
|
||||
if (boldMatch.Success && boldMatch.Index < bestIdx) { bestIdx = boldMatch.Index; bestMatch = boldMatch; matchType = 1; }
|
||||
if (italicMatch.Success && italicMatch.Index < bestIdx) { bestIdx = italicMatch.Index; bestMatch = italicMatch; matchType = 2; }
|
||||
if (cardMatch.Success && cardMatch.Index < bestIdx) { bestIdx = cardMatch.Index; bestMatch = cardMatch; matchType = 3; }
|
||||
|
||||
if (bestMatch != null)
|
||||
{
|
||||
if (bestIdx > 0)
|
||||
builder.AddContent(seq++, remaining[..bestIdx]);
|
||||
|
||||
var innerText = bestMatch.Groups[1].Value;
|
||||
|
||||
if (matchType == 1) // Bold
|
||||
{
|
||||
builder.OpenElement(seq++, "strong");
|
||||
builder.AddContent(seq++, innerText);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (matchType == 2) // Italic
|
||||
{
|
||||
builder.OpenElement(seq++, "em");
|
||||
builder.AddContent(seq++, innerText);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else if (matchType == 3) // Card Link / Doc Link
|
||||
{
|
||||
var card = LookupCard(innerText);
|
||||
var doc = LookupDoc(innerText);
|
||||
if (card != null || doc != null)
|
||||
{
|
||||
builder.OpenElement(seq++, "button");
|
||||
builder.AddAttribute(seq++, "class", "inline-card-btn");
|
||||
builder.AddAttribute(seq++, "onclick",
|
||||
EventCallback.Factory.Create(this, () => Navigate(card)));
|
||||
builder.AddContent(seq++, cleanName);
|
||||
builder.AddAttribute(seq++, "onclick", EventCallback.Factory.Create(this, () => Navigate(innerText)));
|
||||
builder.AddContent(seq++, innerText);
|
||||
builder.CloseElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.AddContent(seq++, cleanName);
|
||||
builder.AddContent(seq++, innerText);
|
||||
}
|
||||
}
|
||||
|
||||
remaining = remaining[(bestIdx + bestName.Length)..];
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.AddContent(seq++, remaining);
|
||||
remaining = "";
|
||||
}
|
||||
remaining = remaining[(bestIdx + bestMatch.Length)..];
|
||||
}
|
||||
};
|
||||
else
|
||||
{
|
||||
builder.AddContent(seq++, remaining);
|
||||
remaining = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,16 +163,43 @@
|
||||
color: var(--text-primary);
|
||||
display: block;
|
||||
font-size: 1.1rem;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.markdown-content {
|
||||
color: var(--text-primary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.markdown-content p {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.markdown-content ul {
|
||||
margin-bottom: 1rem;
|
||||
padding-left: 1.5rem;
|
||||
}
|
||||
|
||||
.markdown-content li {
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.markdown-content h2, .markdown-content h3, .markdown-content h4 {
|
||||
margin-top: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.markdown-content h2 { font-size: 1.5rem; }
|
||||
.markdown-content h3 { font-size: 1.3rem; }
|
||||
.markdown-content h4 { font-size: 1.1rem; }
|
||||
|
||||
/* Syndicate Colors */
|
||||
.lifeblood { color: #ef5350; }
|
||||
.lifeblood { color: #4caf50; }
|
||||
.phasetide { color: #2196f3; }
|
||||
.silence { color: #9e9e9e; }
|
||||
.silence { color: #9c27b0; }
|
||||
.singularity { color: #ffffff; }
|
||||
.splintergleam { color: #4caf50; }
|
||||
.sungrace { color: #ffeb3b; }
|
||||
.splintergleam { color: #f44336; }
|
||||
.sungrace { color: #ff9800; }
|
||||
|
||||
.inline-card-btn {
|
||||
background: none;
|
||||
|
||||
Reference in New Issue
Block a user