Skip to main content

socketry_markdown/mdast/
code.rs

1// Released under the MIT License.
2// Copyright, 2022, by Bernhard Berger.
3// Copyright, 2022-2025, by Titus Wormer.
4// Copyright, 2023, by Kyle McCarthy.
5// Copyright, 2023, by Mia.
6// Copyright, 2023, by Rafael Bachmann.
7// Copyright, 2024, by Harsha Teja Kanna.
8// Copyright, 2026, by Samuel Williams.
9
10use super::CodeFence;
11use crate::unist::Position;
12use alloc::string::String;
13
14/// Code (flow).
15///
16/// ```markdown
17/// > | ~~~
18///     ^^^
19/// > | a
20///     ^
21/// > | ~~~
22///     ^^^
23/// ```
24#[derive(Clone, Debug, Eq, PartialEq)]
25#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
26pub struct Code {
27    // Text.
28    /// Content model.
29    pub value: String,
30    /// Positional info.
31    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
32    pub position: Option<Position>,
33    // Extra.
34    /// The language of computer code being marked up.
35    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
36    pub lang: Option<String>,
37    /// Custom info relating to the node.
38    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
39    pub meta: Option<String>,
40    /// Opening fence metadata, or `None` for indented code or an AST without
41    /// source fence information. This is independent of source positions.
42    /// Markdown serialization chooses its formatting from `MarkdownOptions`.
43    #[cfg_attr(
44        feature = "serde",
45        serde(default, skip_serializing_if = "Option::is_none")
46    )]
47    pub fence: Option<CodeFence>,
48}