Skip to main content

markdown_code_span

Function markdown_code_span 

Source
pub fn markdown_code_span(content: &str) -> String
Expand description

Wraps content in a Markdown inline code span (backticks included) that safely contains arbitrary untrusted text, regardless of embedded backticks.

Backslash-escaping does not work inside code spans (CommonMark §6.1), so instead this fences with one more backtick than the longest run found in content, and pads with a single space on each side when content starts or ends with a backtick or space (required by CommonMark to keep the fence unambiguous). Control characters (including newlines) are replaced with a space first, since the raw hover string is otherwise free to merge into an adjacent Markdown block.

§Examples

use deps_core::lsp_helpers::markdown_code_span;

assert_eq!(markdown_code_span("1.0.0"), "`1.0.0`");
assert_eq!(markdown_code_span("a`b"), "``a`b``");