-
Notifications
You must be signed in to change notification settings - Fork 369
/
TabularDataFormatterSource.cs
32 lines (28 loc) · 1.15 KB
/
TabularDataFormatterSource.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Html;
using static Microsoft.DotNet.Interactive.Formatting.PocketViewTags;
namespace Microsoft.DotNet.Interactive.Formatting.TabularData
{
internal class TabularDataFormatterSource : ITypeFormatterSource
{
public IEnumerable<ITypeFormatter> CreateTypeFormatters()
{
yield return new HtmlFormatter<TabularDataResource>((value, context) =>
{
IReadOnlyList<IHtmlContent> headers =
value.Schema
.Fields
.Select(f => (IHtmlContent) td(span(f.Name)))
.ToArray();
IReadOnlyList<IHtmlContent> rows =
value.Data
.Select(d => (IHtmlContent) tr(d.Values.Select(v => td(v))))
.ToArray();
Html.Table(headers, rows).WriteTo(context);
});
}
}
}