[Monaco]Fix Json format preview setting (#36867)
This commit is contained in:
Родитель
80461c0241
Коммит
3a10facb36
|
@ -7,7 +7,6 @@ using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.FilePreviewCommon.Monaco.Formatters;
|
namespace Microsoft.PowerToys.FilePreviewCommon.Monaco.Formatters;
|
||||||
|
|
||||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
|
||||||
[JsonSerializable(typeof(JsonDocument))]
|
[JsonSerializable(typeof(JsonDocument))]
|
||||||
internal sealed partial class FilePreviewJsonSerializerContext : JsonSerializerContext
|
internal sealed partial class FilePreviewJsonSerializerContext : JsonSerializerContext
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,9 +14,12 @@ namespace Microsoft.PowerToys.FilePreviewCommon.Monaco.Formatters
|
||||||
|
|
||||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
|
WriteIndented = true,
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static readonly FilePreviewJsonSerializerContext _filePreviewJsonSerializerContext = new(_serializerOptions);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public string Format(string value)
|
public string Format(string value)
|
||||||
{
|
{
|
||||||
|
@ -27,8 +30,7 @@ namespace Microsoft.PowerToys.FilePreviewCommon.Monaco.Formatters
|
||||||
|
|
||||||
using (var jDocument = JsonDocument.Parse(value, new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip }))
|
using (var jDocument = JsonDocument.Parse(value, new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip }))
|
||||||
{
|
{
|
||||||
FilePreviewJsonSerializerContext context = new(_serializerOptions);
|
return JsonSerializer.Serialize(jDocument, _filePreviewJsonSerializerContext.JsonDocument);
|
||||||
return JsonSerializer.Serialize(jDocument, context.JsonDocument);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче