pub(crate) mod anchors;
pub(crate) mod cpp;
mod footer;
mod fragments;
mod highlighting;
mod home;
mod html;
mod images;
pub(crate) mod julia;
mod katex_assets;
mod markdown;
mod math;
pub(crate) mod members;
mod navigation;
mod package_metadata;
mod publish;
pub(crate) mod python;
pub(crate) mod r_topics;
pub(crate) mod rust;
mod signatures;
mod sitemap;
mod social;
pub use fragments::{FragmentDocument, FragmentIndex};
pub(crate) use html::render_reported;
pub use html::{render_fragments, render_site};
pub use publish::{RenderedFile, RenderedSite};
use crate::configuration::ExecutionMode;
use crate::execution::{
CellExecutionResult, EffectiveCellOptions, ExecutionFailure, ExecutionOutput, ExecutionPage,
OutputVisibility, PreparedCell, validate_figure_options,
};
use crate::ir::SourceSegment;
pub(crate) fn signature_title(
name: &str,
signature: &crate::ir::Signature,
ecosystem: &str,
) -> String {
signatures::signature(name, signature, ecosystem)
}
pub fn render_preformatted_text(text: &str) -> String {
let mut html = String::from("<pre tabindex=\"0\"><code>");
for ch in text.chars() {
match ch {
'&' => html.push_str("&"),
'<' => html.push_str("<"),
'>' => html.push_str(">"),
'"' => html.push_str("""),
'\'' => html.push_str("'"),
_ => html.push(ch),
}
}
html.push_str("</code></pre>");
html
}
#[derive(Debug, PartialEq, Eq)]
pub struct CellPresentation<'a> {
pub source: Option<&'a [SourceSegment]>,
pub outputs: &'a [ExecutionOutput],
}
pub fn present_prepared_cell(mode: ExecutionMode, cell: &PreparedCell) -> CellPresentation<'_> {
presentation(mode, &cell.cell.source_segments, &cell.options, &[])
}
pub fn present_cell<'a>(
page: &ExecutionPage,
cell: &'a CellExecutionResult,
) -> Result<CellPresentation<'a>, ExecutionFailure> {
validate_figure_options(page, std::slice::from_ref(cell))?;
Ok(presentation(
page.mode,
&cell.source_segments,
&cell.options,
&cell.outputs,
))
}
fn presentation<'a>(
mode: ExecutionMode,
source: &'a [SourceSegment],
options: &EffectiveCellOptions,
outputs: &'a [ExecutionOutput],
) -> CellPresentation<'a> {
if mode == ExecutionMode::Never {
return CellPresentation {
source: Some(source),
outputs: &[],
};
}
let execution = &options.execution;
CellPresentation {
source: (execution.include.value && execution.echo.value).then_some(source),
outputs: if execution.include.value && execution.output.value != OutputVisibility::Hide {
outputs
} else {
&[]
},
}
}