algolia / algolia/diffable-html
Invalid multiline text node indentation
- 主要言語
- JavaScript
- スター
- 38
- フォーク
- 8
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
報告された動作は dist/diffable-html.js の onText callback で処理されています。まずその handler と周辺のフォーマット処理を読んでください。提示された複数行の入力を再現し、各行が意図どおりに扱われていることを確認してください。空行を保持するべきか削除するべきかも含めて確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100