1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// This file is part of helpers4.
// Copyright (C) 2025 baxyz
// SPDX-License-Identifier: LGPL-3.0-or-later
/// Wraps `text` in a Markdown code span, using enough backticks for the text to show literally.
///
/// The fence is one backtick longer than the longest run of backticks inside, so text with a
/// single backtick gets a two-backtick fence, text with two gets three, and so on. When the text
/// starts or ends with a backtick, or starts *and* ends with a space, one space of padding is
/// added on each side (Markdown strips exactly that) so nothing is lost. Line breaks are not
/// handled: Markdown turns them into spaces.
///
/// # Arguments
///
/// - `text` - The text to show as code.
///
/// # Returns
///
/// The code span, such as `` `cargo test` ``.
///
/// # Examples
///
/// ```
/// use helpers4::markdown::inline_code;
///
/// assert_eq!(inline_code("cargo test"), "`cargo test`");
/// assert_eq!(inline_code("a`b"), "``a`b``");
/// assert_eq!(inline_code("`tick`"), "`` `tick` ``");
/// ```
/// The length of the longest run of consecutive backticks in `text`.