Skip to main content

code_info_span

Function code_info_span 

Source
pub fn code_info_span(source: &str, block_start: usize) -> Option<Range<usize>>
Expand description

The source range of a fenced code block’s info string — everything on the opening line past the fence (```rust → the rust). block_start is the code block node’s span.start. None for an indented code block, which opens with no fence to carry one. The range is empty for a fence written bare (``` alone), which is exactly where a language would be inserted.

A block inside a quote or a list item starts at its line’s start, with the container’s marker in front of the fence — > ```rust, - ```rust — so the marker is skipped first, and the fence’s three-space indent allowance is measured from where the container’s content begins: past the marker on the fence’s own line, or, on a continuation line, from the content column of the list item above. That is what keeps an indented code block inside a list item answering None.

Shared by the WYSIWYG builder (to label the box) and crate::Doc (to edit the label through a prompt), so the two agree on where the language lives.