algolia / algolia/diffable-html

Invalid multiline text node indentation

Đang mở
#60 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
38
Fork
8
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Currently for input:

```


My text
Another line


```

The output is:

```


My text
Another line


```

so first line is properly formatted (indentation corrected), but following lines are not.

This is an issue for me, because we are building HTML using different template strings, helpers etc, so indentation is essentially unpredictable. We use `diffable-html` in tests to compare expected HTML with actual HTML, and both expected and actual are built from template strings. Therefore, we need proper normalization.

I created patch that works for me:

```
diff --git a/dist/diffable-html.js b/dist/diffable-html.js
index c732d9e3eca544b70f1d10c8291881e3a5925c60..c4978caa2cbcc1064e33c65668feb86c22802fb7 100644
--- a/dist/diffable-html.js
+++ b/dist/diffable-html.js
@@ -206,9 +206,17 @@ var format = function(html, ref) {
return;
}

- appendLineBreak();
- appendCurrentIndentation();
- append(trimmed);
+ const splitted = text.split('\n');
+ for (const line of splitted) {
+ const lineTrimmed = line.trim();
+ if (lineTrimmed.length === 0) {
+ continue;
+ }
+
+ appendLineBreak();
+ appendCurrentIndentation();
+ append(lineTrimmed);
+ }
},
onclosetag: function(tagname) {
var isVoidTag = isVoidTagName(tagname);

```

Essentially it uses current logic for `onText` but applies it to each line. It seems it fixed my problem.
Note: this patch removes empty lines in text nodes.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Hành vi được báo cáo được xử lý trong dist/diffable-html.js, tại callback onText; hãy bắt đầu bằng cách đọc handler đó và logic định dạng xung quanh nó. Tái hiện đầu vào nhiều dòng được cung cấp và xác minh cách xử lý dự kiến của từng dòng, bao gồm cả việc các dòng trống có nên được giữ lại hay loại bỏ hay không.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.