pub mod google;
pub mod numpy;
pub mod sphinx;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[non_exhaustive]
pub struct EmitOptions {
pub base_indent: usize,
}
impl EmitOptions {
#[must_use]
pub fn with_base_indent(mut self, base_indent: usize) -> Self {
self.base_indent = base_indent;
self
}
}
pub(crate) fn emit_multiline_with_indentation(out: &mut String, text: &str, indent: usize) {
let prefix = " ".repeat(indent);
let mut lines = text.lines();
if let Some(first) = lines.next() {
out.push_str(first);
for line in lines {
out.push('\n');
if !line.is_empty() {
out.push_str(&prefix);
out.push_str(line);
}
}
}
}
pub(crate) fn emit_directive(out: &mut String, directive: &crate::model::Directive) {
out.push_str(".. ");
out.push_str(&directive.name);
out.push_str("::");
if let Some(ref argument) = directive.argument {
out.push(' ');
out.push_str(argument);
}
out.push('\n');
if let Some(ref desc) = directive.description {
for line in desc.lines() {
if !line.is_empty() {
out.push_str(" ");
out.push_str(line);
}
out.push('\n');
}
}
}
pub(crate) fn indent_lines(text: &str, base_indent: usize) -> String {
let indent: String = " ".repeat(base_indent);
let mut result = String::new();
for line in text.lines() {
if !line.is_empty() {
result.push_str(&indent);
}
result.push_str(line);
result.push('\n');
}
result
}