Skip to main content

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