Skip to main content

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::MarkdownFencePolicy;
21///
22/// let fence_policy = MarkdownFencePolicy::Disabled;
23/// assert_eq!(fence_policy, MarkdownFencePolicy::Disabled);
24/// ```
25#[derive(Debug, Clone, PartialEq, Eq, Hash)]
26pub enum MarkdownFencePolicy {
27    /// Leaves Markdown code fences unchanged.
28    Disabled,
29    /// Strips a fence with any info-string language tag.
30    Any {
31        /// Controls whether the opening fence needs a matching closing fence.
32        closing: MarkdownFenceClosing,
33    },
34    /// Strips only fences with an empty, `json`, or `jsonc` first info token.
35    ///
36    /// The `jsonc` token is accepted only as a fence label; fenced content must
37    /// still be standard JSON without comments or trailing commas.
38    JsonOnly {
39        /// Controls whether the opening fence needs a matching closing fence.
40        closing: MarkdownFenceClosing,
41    },
42}