gemrendr 0.3.1

Turns Gemtext into idiomatic HTML
Documentation
//! Structures that deal with deserialized Gemtext documents.

// gemrendr   Turns Gemtext into idiomatic HTML.
// Copyright (C) 2025  AverageHelper
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

use alloc::{string::String, vec::Vec};

/// Represents a Gemtext document.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Document {
	/// The blocks that comprise the Gemtext document.
	pub contents: Vec<GemtextContentBlock>,
}

impl Document {
	/// Parses the given text document as Gemtext.
	pub fn parse_from_gemtext(document: &str) -> Self {
		document.parse().expect("infallible")
	}
}

/// A block of Gemtext content.
///
/// Each case generally corresponds to a text line (e.g. `Text`
/// or `Link`) but may sometimes consist of multiple lines
/// (e.g. `List` or `Pre`).
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GemtextContentBlock {
	Text {
		/// The text.
		content: String,
	},
	Link {
		/// The URI where the link points.
		target: String,

		/// The user-facing text of the link, if given.
		label: Option<String>,
	},
	Heading {
		/// The heading level.
		level: HeadingLevel,

		/// The heading text.
		content: String,
	},
	List {
		/// Elements of the list.
		items: Vec<String>,
	},
	Quote {
		/// The text being quoted.
		content: String,
	},
	Pre {
		/// Text that describes the pre-formatted text block.
		alt_text: Option<String>,

		/// The content of the pre-formatted text block.
		content: String,
	},
}

/// One of the three levels of a Gemtext heading.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum HeadingLevel {
	/// Represents a top-level heading.
	One,

	/// Represents a subheading.
	Two,

	/// Represents a sub-subheading.
	Three,
}