2022-08-24 13:08:10 +02:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
2022-12-18 14:27:14 +01:00
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
2022-08-24 13:08:10 +02:00
|
|
|
|
namespace Microsoft.PowerToys.PreviewHandler.Monaco.Formatters
|
|
|
|
|
|
{
|
|
|
|
|
|
public class JsonFormatter : IFormatter
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public string LangSet => "json";
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public string Format(string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
using (var jDocument = JsonDocument.Parse(value, new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip }))
|
|
|
|
|
|
{
|
|
|
|
|
|
return JsonSerializer.Serialize(jDocument, new JsonSerializerOptions { WriteIndented = true });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|