Skip to content

Commit

Permalink
fix ignoring colors and style when using JSON attributes in formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Apr 20, 2024
1 parent 216dee9 commit fbabaee
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
* fix calling `onCommandChange` when command don't change
* fix sequence of animations in echo without newline [#930](https://github.com/jcubic/jquery.terminal/issues/930)
* fix flash of old dynamic prompt on enter [#926](https://github.com/jcubic/jquery.terminal/issues/926)
* fix ignoring colors and style when using JSON attributes in formatting

## 2.39.3
### Bugfix
Expand Down
8 changes: 7 additions & 1 deletion js/jquery.terminal-src.js
Expand Up @@ -6846,10 +6846,11 @@
return [];
}
// -----------------------------------------------------------------
function attrs_to_string(style, attrs) {
function attrs_to_string(style, attrs, vaid_attrs) {

Check failure on line 6849 in js/jquery.terminal-src.js

View workflow job for this annotation

GitHub Actions / build

'vaid_attrs' is defined but never used
if (attrs) {
var keys = filter_attr_names(Object.keys(attrs));
if (keys.length) {
var style_attrs;
var result = keys.map(function(name) {
if (attrs[name] === null) {
return '';
Expand All @@ -6861,12 +6862,17 @@
if (name === 'style') {
// merge style attr and colors #617
value = value ? style + ';' + value : style;
style_attrs = true;
}
return name + '="' + value + '"';
}).filter(Boolean);
if (!result.length) {
return '';
}
if (!style_attrs) {
// if there are not style attr we need to add style
result.push('style="' + style + '"');
}
return result.join(' ');
}
}
Expand Down
12 changes: 9 additions & 3 deletions js/jquery.terminal.js
Expand Up @@ -41,7 +41,7 @@
*
* broken image by Sophia Bai from the Noun Project (CC-BY)
*
* Date: Sat, 20 Apr 2024 17:30:08 +0000
* Date: Sat, 20 Apr 2024 18:36:45 +0000
*/
/* global define, Map, BigInt */
/* eslint-disable */
Expand Down Expand Up @@ -5308,7 +5308,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Sat, 20 Apr 2024 17:30:08 +0000',
date: 'Sat, 20 Apr 2024 18:36:45 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -6846,10 +6846,11 @@
return [];
}
// -----------------------------------------------------------------
function attrs_to_string(style, attrs) {
function attrs_to_string(style, attrs, vaid_attrs) {
if (attrs) {
var keys = filter_attr_names(Object.keys(attrs));
if (keys.length) {
var style_attrs;
var result = keys.map(function(name) {
if (attrs[name] === null) {
return '';
Expand All @@ -6861,12 +6862,17 @@
if (name === 'style') {
// merge style attr and colors #617
value = value ? style + ';' + value : style;
style_attrs = true;
}
return name + '="' + value + '"';
}).filter(Boolean);
if (!result.length) {
return '';
}
if (!style_attrs) {
// if there are not style attr we need to add style
result.push('style="' + style + '"');
}
return result.join(' ');
}
}
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/jquery.terminal.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/xml_formatting.js
Expand Up @@ -134,7 +134,7 @@
var attrs = {};
if (m[2]) {
var string_attrs = m[2];
var re = /([a-zA-Z]+)\s*=\s*"([^"]+)"/g;
var re = /([\w-]+)\s*=\s*"([^"]+)"/g;
var match;
while (match = re.exec(string_attrs)) {
var attr_name = match[1];
Expand Down

0 comments on commit fbabaee

Please sign in to comment.