commented/
lib.rs

1//! This crate contains the [`comment`] function, which turns the passed input
2//! into a comment for the given file type
3//!
4//! Enabling the `glob` feature will *slightly* improve accuracy of the comment heuristics.
5
6use std::path::Path;
7
8mod generated;
9
10/// Turn the given `content` into a comment for the given `path`
11///
12/// # Examples
13///
14/// ```
15/// use commented::comment;
16///
17/// assert_eq!(comment("hello, world!", "index.html"), "<!-- hello, world! -->");
18/// assert_eq!(comment("hello, world!", "main.rs"), "/* hello, world! */");
19/// assert_eq!(comment("hello, world!", "script.lua"), "--[[ hello, world! --]]");
20/// // fallback to `#`, as that's the most common comment tokens for
21/// // files without an extension
22/// assert_eq!(comment("hello, world!", "123456789"), "# hello, world!");
23/// ```
24pub fn comment<S: ToString, P: AsRef<Path>>(content: S, path: P) -> String {
25    generated::comment(content, path)
26}