Revert unnecessary "fix handling of unicode when counting codeblock lines" + document (#30368)

After merging #30364 I realized why it was unnecessary to fix the code,
and was more efficient before. UTF-8 does not use the standard 0-127
ASCII range for multi-byte chars. So this reverts that change and
documents why the code is valid.

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-05-09 13:38:03 +02:00 committed by GitHub
parent 023a60806a
commit 30f3efe697
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

@ -223,6 +223,7 @@ impl Markdown {
}
pub fn escape(s: &str) -> Cow<str> {
// Valid to use bytes since multi-byte UTF-8 doesn't use ASCII chars.
let count = s
.bytes()
.filter(|c| *c == b'\n' || c.is_ascii_punctuation())

View file

@ -79,9 +79,10 @@ pub fn parse_markdown(
let content_range =
content_range.start + range.start..content_range.end + range.start;
// Valid to use bytes since multi-byte UTF-8 doesn't use ASCII chars.
let line_count = text[content_range.clone()]
.chars()
.filter(|c| *c == '\n')
.bytes()
.filter(|c| *c == b'\n')
.count();
let metadata = CodeBlockMetadata {
content_range,