@pixui-dev/pixui-richtext-helper 0.1.1-beta.4 → 0.1.1-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -121,15 +121,20 @@ var RichText_Refactor = /** @class */ (function () {
|
|
|
121
121
|
// 重置全局状态
|
|
122
122
|
RichText_Refactor.linkNodes = [];
|
|
123
123
|
RichText_Refactor.hrefIdCnt = 0;
|
|
124
|
+
var $1 = cheerio.load(str, null, false);
|
|
125
|
+
//检查html,如果有text节点,说明是转换过的,直接返回
|
|
126
|
+
if ($1("text").length > 0) {
|
|
127
|
+
return str;
|
|
128
|
+
}
|
|
124
129
|
// ---------- 第 1 步:段落分割(基础实现:根节点切分) ----------
|
|
125
|
-
var segments = RichText_Refactor.splitIntoSegments(
|
|
130
|
+
var segments = RichText_Refactor.splitIntoSegments($1);
|
|
126
131
|
// ---------- 第 2/3 步:遍历 + 展平 ----------
|
|
127
132
|
// 为保证兼容性,我们直接对 HTML 进行逐段处理并在内部构建 PixUI 结构。
|
|
128
133
|
// 这样既保持分段概念,又可复用旧逻辑的稳定性。
|
|
129
134
|
var processedSegments = segments.map(function (seg) { return RichText_Refactor.processSegment(seg, config); });
|
|
130
135
|
// ---------- 第 4 步:拼装 ----------
|
|
131
136
|
var Result = processedSegments.join("");
|
|
132
|
-
console.log(Result);
|
|
137
|
+
// console.log(Result);
|
|
133
138
|
return Result;
|
|
134
139
|
};
|
|
135
140
|
/**
|
|
@@ -159,8 +164,7 @@ var RichText_Refactor = /** @class */ (function () {
|
|
|
159
164
|
* 将 HTML 切分为基础段落片段。
|
|
160
165
|
* 简易实现:以顶级节点为粒度切分,再根据最外层列表节点进行分割。
|
|
161
166
|
*/
|
|
162
|
-
RichText_Refactor.splitIntoSegments = function (
|
|
163
|
-
var $ = cheerio.load(html, null, false);
|
|
167
|
+
RichText_Refactor.splitIntoSegments = function ($) {
|
|
164
168
|
var segments = [];
|
|
165
169
|
// 如果有 body,取其直接子节点;否则取根节点下的直接子节点
|
|
166
170
|
var roots = $("body").length > 0 ? $("body").children() : $.root().children();
|
|
@@ -201,7 +205,7 @@ var RichText_Refactor = /** @class */ (function () {
|
|
|
201
205
|
});
|
|
202
206
|
// fallback:原样返回
|
|
203
207
|
if (segments.length === 0)
|
|
204
|
-
segments.push(html);
|
|
208
|
+
segments.push($.html());
|
|
205
209
|
return segments;
|
|
206
210
|
};
|
|
207
211
|
/**
|
|
@@ -377,17 +381,7 @@ var RichText_Refactor = /** @class */ (function () {
|
|
|
377
381
|
if (href) {
|
|
378
382
|
self.linkNodes.push({ type: LinkNodeType.DIV, href: href, id: id });
|
|
379
383
|
}
|
|
380
|
-
|
|
381
|
-
var $parent = $(this).parent();
|
|
382
|
-
var isInText = $parent.is("text") || $parent.closest("text").length > 0;
|
|
383
|
-
if (isInText) {
|
|
384
|
-
// 如果已经在text内,直接替换为div
|
|
385
|
-
$(this).replaceWith("<div style=\"".concat(finalStyle, "\" id=\"").concat(id, "\" class=\"PA_RichTextHref_ATag\">").concat(textContent, "</div>"));
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
// 如果不在text内,需要确保在正确的层级
|
|
389
|
-
$(this).replaceWith("<div style=\"".concat(finalStyle, "\" id=\"").concat(id, "\" class=\"PA_RichTextHref_ATag\">").concat(textContent, "</div>"));
|
|
390
|
-
}
|
|
384
|
+
$(this).replaceWith("<div style=\"".concat(finalStyle, "\" id=\"").concat(id, "\" class=\"PA_RichTextHref_ATag\">").concat(textContent, "</div>"));
|
|
391
385
|
});
|
|
392
386
|
};
|
|
393
387
|
/** 用 text 标签包裹纯文本节点 */
|