pub fn escape_for_docstring(s: &str, context: EscapeContext) -> StringExpand description
Escape a string for use in docstrings or documentation comments.
Docstrings have language-specific delimiters and rules:
- Python: Triple-quoted strings (
""") with different escape patterns - JavaScript/TypeScript:
JSDoccomments with/**and*/ - Ruby: YARD documentation with special comment markers
- PHP:
PHPDoccomments with special markers - Rust: rustdoc with
///or//!
§Arguments
s- The string to escapecontext- The target language context
§Returns
A string escaped for safe embedding in docstrings of the target language
§Examples
use spikard_cli::codegen::common::escaping::{EscapeContext, escape_for_docstring};
// Python docstrings use triple quotes, which must be escaped
let result = escape_for_docstring("Description with \"\"\" in it", EscapeContext::Python);
assert!(!result.contains("\"\"\""));
assert!(result.contains("\\\""));