Skip to content

Commit e6421e0

Browse files
authored
fix: handle links going multi to single line when single line length under lineWidth / 2 (#69)
1 parent 313eafe commit e6421e0

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/generation/cmark/parse_cmark_ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'a> EventIterator<'a> {
5555

5656
fn move_iterator_next(&mut self) -> Option<(Event<'a>, Range)> {
5757
let next = self.iterator.next();
58-
// println!("Raw event: {:?}", next);
58+
// eprintln!("Raw event: {:?}", next);
5959

6060
match next {
6161
Some((Event::Start(Tag::Table(_)), _)) => self.in_table_count += 1,

src/generation/gen_types.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use dprint_core::plugins::FormatResult;
22
use regex::Regex;
33

44
use super::utils::*;
5-
use crate::{configuration::Configuration, format_text};
5+
use crate::configuration::Configuration;
6+
use crate::format_text;
67

78
pub struct Context<'a> {
89
pub file_text: &'a str,
@@ -65,10 +66,10 @@ impl<'a> Context<'a> {
6566
let line_width = std::cmp::max(10, self.configuration.line_width as i32 - self.indent_level as i32) as u32;
6667

6768
match tag {
68-
"markdown" | "md" => format_text(text, self.configuration, |tag, file_text, line_width | {
69+
"markdown" | "md" => format_text(text, self.configuration, |tag, file_text, line_width| {
6970
(self.format_code_block_text)(tag, file_text, line_width)
7071
}),
71-
_ => (self.format_code_block_text)(tag, text, line_width)
72+
_ => (self.format_code_block_text)(tag, text, line_width),
7273
}
7374
}
7475

src/generation/generate.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,19 @@ fn get_newline_wrapping_based_on_config(context: &Context) -> PrintItems {
908908
match context.configuration.text_wrap {
909909
TextWrap::Always => Signal::SpaceOrNewLine.into(),
910910
TextWrap::Never => " ".into(),
911-
TextWrap::Maintain => Signal::NewLine.into(),
911+
TextWrap::Maintain => {
912+
if context.is_text_wrap_disabled() {
913+
if_true_or(
914+
"newLineOrSpaceIfNewlinesDisabled",
915+
condition_resolvers::is_forcing_no_newlines(),
916+
" ".into(),
917+
Signal::NewLine.into(),
918+
)
919+
.into()
920+
} else {
921+
Signal::NewLine.into()
922+
}
923+
}
912924
}
913925
}
914926

tests/specs/Links/Links_All.txt

+7
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,10 @@ Testing <https://google.com> this.
6262

6363
[expect]
6464
[![CI](image.svg)](https://github.com)
65+
66+
!! should handle going multi-line to single line within a link !!
67+
Test [this
68+
out](/test) test
69+
70+
[expect]
71+
Test [this out](/test) test

0 commit comments

Comments
 (0)