mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-08-02 18:17:30 +08:00
Update emoji support
* Add constants for emojis * Move emoji shortcode rendering to Markup * Add documentation * Add example * Add tests
This commit is contained in:

committed by
Patrik Svensson

parent
090b30f731
commit
eeb3f967b6
@ -17,11 +17,10 @@ namespace Docs.Shortcodes
|
||||
// Get the definition.
|
||||
var colors = context.Outputs
|
||||
.FromPipeline(nameof(ColorsPipeline))
|
||||
.First()
|
||||
.GetChildren(Constants.Colors.Root)
|
||||
.OfType<ObjectDocument<List<Color>>>()
|
||||
.First().Object;
|
||||
|
||||
// Headers
|
||||
var table = new XElement("table", new XAttribute("class", "table"));
|
||||
var header = new XElement("tr", new XAttribute("class", "color-row"));
|
||||
header.Add(new XElement("th", ""));
|
||||
|
45
docs/src/Shortcodes/EmojiTableShortcode.cs
Normal file
45
docs/src/Shortcodes/EmojiTableShortcode.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Statiq.Common;
|
||||
using System.Xml.Linq;
|
||||
using Docs.Pipelines;
|
||||
using Docs.Models;
|
||||
|
||||
namespace Docs.Shortcodes
|
||||
{
|
||||
public class EmojiTableShortcode : SyncShortcode
|
||||
{
|
||||
public override ShortcodeResult Execute(KeyValuePair<string, string>[] args, string content, IDocument document, IExecutionContext context)
|
||||
{
|
||||
var emojis = context.Outputs
|
||||
.FromPipeline(nameof(EmojiPipeline))
|
||||
.OfType<ObjectDocument<List<Emoji>>>()
|
||||
.First().Object;
|
||||
|
||||
// Headers
|
||||
var table = new XElement("table", new XAttribute("class", "table"));
|
||||
var header = new XElement("tr", new XAttribute("class", "emoji-row"));
|
||||
header.Add(new XElement("th", ""));
|
||||
header.Add(new XElement("th", "Markup"));
|
||||
header.Add(new XElement("th", "Constant"));
|
||||
table.Add(header);
|
||||
|
||||
foreach (var emoji in emojis)
|
||||
{
|
||||
var code = emoji.Code.Replace("U+0000", "U+").Replace("U+000", "U+");
|
||||
var icon = string.Format("&#x{0};", emoji.Code.Replace("U+", string.Empty));
|
||||
|
||||
var row = new XElement("tr");
|
||||
row.Add(new XElement("td", icon));
|
||||
row.Add(new XElement("td", new XElement("code", $":{emoji.Id}:")));
|
||||
row.Add(new XElement("td", new XElement("code", emoji.Name)));
|
||||
|
||||
table.Add(row);
|
||||
}
|
||||
|
||||
return table.ToString()
|
||||
.Replace("&#x", "&#x");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user