Skip to content

Commit

Permalink
fix Jupyter metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Oct 19, 2022
1 parent e460eaf commit cc300fb
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ public static InteractiveDocument WithJupyterMetadata(
this InteractiveDocument document,
string language = "C#")
{
var (moniker, langVersion, fileExtension) =
language switch
var (moniker, canonicalLanguageName, langVersion, fileExtension) =
language.ToLowerInvariant() switch
{
"C#" or "csharp" => ("csharp", "10.0", ".cs"),
"F#" or "fsharp" => ("fsharp", "6.0", ".fs"),
"PowerShell" or "pwsh" => ("powershell", "7.0", ".ps1"),
"c#" or "csharp" => ("csharp","C#", "10.0", ".cs"),
"f#" or "fsharp" => ("fsharp","F#", "6.0", ".fs"),
"powershell" or "pwsh" => ("powershell", "PowerShell", "7.0", ".ps1"),
_ => throw new ArgumentException($"Unrecognized language: {language}")
};

document.Metadata.GetOrAdd("kernelspec", _ => new Dictionary<string, object>())
.MergeWith(new Dictionary<string, object>
{
["display_name"] = $".NET ({language})",
["language"] = language,
["display_name"] = $".NET ({canonicalLanguageName})",
["language"] = canonicalLanguageName,
["name"] = $".net-{moniker}"
});

Expand All @@ -35,7 +35,7 @@ public static InteractiveDocument WithJupyterMetadata(
{
["file_extension"] = fileExtension,
["mimetype"] = $"text/x-{moniker}",
["name"] = language,
["name"] = canonicalLanguageName,
["pygments_lexer"] = moniker,
["version"] = langVersion
});
Expand Down

0 comments on commit cc300fb

Please sign in to comment.