//! Machine text in a line of reading, described. //! //! The Askama entry point for an inline [`quasi_router::Node::Code`]: a clone //! URL, a DNS record, a backup code, a license key, a file path. Not a widget //! (`super::widgets`) but a primitive with an entry point, which is why it sits //! here beside `rich_field.rs` and `export_act.rs` rather than in that //! directory. `super::widgets`'s header states the rule. //! //! # Why 26 templates go through one function //! //! `19d7602d` ruled that a description carries code as pre-classified runs. //! Most of the tree's `` is not source and has no lexer behind it: it is //! one plain run, said once here rather than as a hand-written element in every //! template that has a value a reader is meant to copy. //! //! What that buys beyond tidiness is the escaping. Each of these sites wrote //! `{{ value }}`, so the element was the template's and the //! escaping was Askama's; through here both are the renderer's, which is the //! same seam the file view and the diff now use. //! //! A template that keeps its own `` is a template whose content is not a //! value: a `
` holding a worked example belongs to the prose around it.

use quasi_router::Node;
use quasi_router::screen::Lexeme;

/// One run of machine text, as markup for a template to drop in.
///
/// Inline, because these all sit in a line of reading. A block of source is
/// `crate::quasi::git_browse`, which has a lexer behind it and line numbers
/// beside it.
#[must_use]
pub fn html(text: &str) -> String {
    use quasi_axum::Serves as _;

    // No shell: this lands inside a document Askama already built, which is
    // what `fragment` is for.
    quasi_webview::Webview::new().fragment(&Node::Code {
        runs: vec![Lexeme::plain(text)],
        language: None,
        inline: true,
    })
}

/// The same, from parts a template has in hand.
///
/// Askama rewrites the identifiers in an expression it parses and cannot reach
/// inside a `format!` it does not, so a template building a clone URL out of
/// three of its own fields writes them as a list rather than as a format
/// string. That is the whole of why this exists beside [`html`].
///
/// The array is taken by reference and the call site writes it without one:
/// Askama adds the `&` itself when it passes an argument.
#[must_use]
pub fn of(parts: &[&str; N]) -> String {
    html(&parts.concat())
}

#[cfg(test)]
mod tests {
    use super::*;

    /// The value arrives as the value, in the element the renderer picks.
    #[test]
    fn a_literal_is_the_text_it_carries() {
        let html = html("git clone https://makenot.work/git/ada/engine.git");

        assert!(html.contains("alert(1)");

        assert!(!html.contains("