Skip to content

Commit

Permalink
[Monaco]Fix Json format preview setting (#36867)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimecbernardo authored Jan 14, 2025
1 parent 80461c0 commit 3a10fac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Microsoft.PowerToys.FilePreviewCommon.Monaco.Formatters;

[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(JsonDocument))]
internal sealed partial class FilePreviewJsonSerializerContext : JsonSerializerContext
{
Expand Down
6 changes: 4 additions & 2 deletions src/common/FilePreviewCommon/Formatters/JsonFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ public class JsonFormatter : IFormatter

private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
};

private static readonly FilePreviewJsonSerializerContext _filePreviewJsonSerializerContext = new(_serializerOptions);

/// <inheritdoc/>
public string Format(string value)
{
Expand All @@ -27,8 +30,7 @@ public string Format(string value)

using (var jDocument = JsonDocument.Parse(value, new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip }))
{
FilePreviewJsonSerializerContext context = new(_serializerOptions);
return JsonSerializer.Serialize(jDocument, context.JsonDocument);
return JsonSerializer.Serialize(jDocument, _filePreviewJsonSerializerContext.JsonDocument);
}
}
}
Expand Down

0 comments on commit 3a10fac

Please sign in to comment.