qubit_json/decode/markdown_fence_policy.rs
1// =============================================================================
2// Copyright (c) 2025 - 2026 Haixing Hu.
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6// Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Defines the lenient Markdown fence normalization policy.
9
10use super::MarkdownFenceClosing;
11
12/// Controls whether and how one outer Markdown code fence is stripped.
13///
14/// The policy combines fence-language acceptance and closing-fence requirements
15/// so callers cannot configure contradictory combinations of independent flags.
16///
17/// # Examples
18///
19/// ```
20/// use qubit_json::decode::MarkdownFenceClosing;
21/// use qubit_json::decode::MarkdownFencePolicy;
22/// use qubit_json::decode::NormalizingJsonDecodePolicyBuilder;
23///
24/// let policy = NormalizingJsonDecodePolicyBuilder::new()
25/// .markdown_fence_policy(MarkdownFencePolicy::JsonOnly {
26/// closing: MarkdownFenceClosing::Required,
27/// })
28/// .build();
29/// assert_eq!(
30/// policy.markdown_fence_policy(),
31/// &MarkdownFencePolicy::JsonOnly {
32/// closing: MarkdownFenceClosing::Required,
33/// }
34/// );
35/// ```
36#[derive(Debug, Clone, PartialEq, Eq, Hash)]
37pub enum MarkdownFencePolicy {
38 /// Leaves Markdown code fences unchanged.
39 Disabled,
40 /// Strips a fence with any info-string language tag.
41 Any {
42 /// Controls whether the opening fence needs a matching closing fence.
43 closing: MarkdownFenceClosing,
44 },
45 /// Strips only fences with an empty, `json`, or `jsonc` first info token.
46 ///
47 /// The `jsonc` token is accepted only as a fence label; fenced content must
48 /// still be standard JSON without comments or trailing commas.
49 JsonOnly {
50 /// Controls whether the opening fence needs a matching closing fence.
51 closing: MarkdownFenceClosing,
52 },
53}