Add helper for smart indentation of documentation
@@ -249,3 +249,17 @@ pub fn strip_indent(mut chunks: Vec<StrChunk<RichTerm>>) -> Vec<StrChunk<RichTer
chunks
}
+
+/// Strip the indentation of a documentation metavalue. Wrap it as a literal string chunk and call
+/// [`strip_indent`](./fn.strip_indent.html).
+pub fn strip_indent_doc(doc: String) -> String {
+ let chunk = vec![StrChunk::Literal(doc)];
+ strip_indent(chunk)
+ .into_iter()
+ .map(|chunk| match chunk {
+ StrChunk::Literal(s) => s,
+ _ => panic!("expected literal string after indentation of documentation"),
+ })
+ .next()
+ .expect("expected non-empty chunks after indentation of documentation")
+}
