Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/ansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,13 @@ static void clic__html_start(struct html_data *data) {
static void clic__html_end(struct html_data *data) {

struct cli_buffer *buffer = &data->buffer;
if (data->had_tags) EMITS("</span>");
if (data->had_tags) {
EMITS("</span>");
/* Reset old state after closing tags, so the next text segment
correctly detects that it needs to open a new span, even if
the same style was reset and re-applied (issue #752). */
memset(&data->state.old, 0, sizeof(data->state.old));
}
if (data->is_link) EMITS("</a>");
}

Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-ansi-html.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,16 @@ test_that("ansi_html_style", {
ansi_html_style(colors = 256, palette = "ubuntu")
)
})

# https://github.com/r-lib/cli/issues/752
test_that("consecutive strings with the same style pasted together", {
x <- "\033[91mR\033[39m\033[91mR\033[39m"
expect_equal(
ansi_html(x),
"<span class=\"ansi ansi-color-1\">R</span><span class=\"ansi ansi-color-1\">R</span>"
)
expect_equal(
ansi_html(ansi_simplify(x)),
"<span class=\"ansi ansi-color-1\">RR</span>"
)
})
Loading