@lyhue1991/wxgzh 0.2.1 → 0.2.2
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.
- package/README.md +6 -0
- package/dist/core/converter.js +52 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/core/converter.js
CHANGED
|
@@ -478,12 +478,30 @@ function normalizeListItems($) {
|
|
|
478
478
|
});
|
|
479
479
|
const firstChild = childElements[0];
|
|
480
480
|
if (!hasBlockChild && isTagNode(firstChild, 'span') && childElements.length === 1) {
|
|
481
|
+
$(firstChild).attr('data-wxgzh', 'li-inline');
|
|
481
482
|
return;
|
|
482
483
|
}
|
|
483
484
|
if (hasBlockChild) {
|
|
485
|
+
const inlineNodes = [];
|
|
486
|
+
for (const node of childElements) {
|
|
487
|
+
if (node.type === 'tag') {
|
|
488
|
+
const tagName = node.tagName.toLowerCase();
|
|
489
|
+
if (['p', 'ul', 'ol', 'section', 'blockquote', 'pre', 'table'].includes(tagName)) {
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
inlineNodes.push(node);
|
|
494
|
+
}
|
|
495
|
+
if (inlineNodes.length > 0) {
|
|
496
|
+
const inlineHtml = inlineNodes.map((node) => $.html(node)).join('');
|
|
497
|
+
for (const node of inlineNodes) {
|
|
498
|
+
$(node).remove();
|
|
499
|
+
}
|
|
500
|
+
$item.prepend(`<span data-wxgzh="li-inline">${inlineHtml}</span>`);
|
|
501
|
+
}
|
|
484
502
|
return;
|
|
485
503
|
}
|
|
486
|
-
$item.html(`<span>${$item.html() ?? ''}</span>`);
|
|
504
|
+
$item.html(`<span data-wxgzh="li-inline">${$item.html() ?? ''}</span>`);
|
|
487
505
|
});
|
|
488
506
|
}
|
|
489
507
|
function normalizeImages($) {
|
|
@@ -700,6 +718,38 @@ function normalizeInlinedListStyles($) {
|
|
|
700
718
|
$item.removeAttr('style');
|
|
701
719
|
});
|
|
702
720
|
}
|
|
721
|
+
function decorateUnorderedListMarkers($) {
|
|
722
|
+
$('ul').each((_, element) => {
|
|
723
|
+
const $list = $(element);
|
|
724
|
+
const depth = $list.parents('ul').length;
|
|
725
|
+
const paddingLeft = depth === 0 ? '0 !important' : '1.2em !important';
|
|
726
|
+
$list.attr('style', setInlineStyleProperty($list.attr('style'), 'list-style', 'none !important'));
|
|
727
|
+
$list.attr('style', setInlineStyleProperty($list.attr('style'), 'margin-left', '0 !important'));
|
|
728
|
+
$list.attr('style', setInlineStyleProperty($list.attr('style'), 'padding-left', paddingLeft));
|
|
729
|
+
});
|
|
730
|
+
$('ul > li').each((_, element) => {
|
|
731
|
+
const $item = $(element);
|
|
732
|
+
const hasCheckbox = $item.children('input[type="checkbox"]').length > 0;
|
|
733
|
+
if (hasCheckbox) {
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
$item.children('span[data-wxgzh="ul-marker"]').remove();
|
|
737
|
+
$item.attr('style', setInlineStyleProperty($item.attr('style'), 'list-style', 'none !important'));
|
|
738
|
+
$item.attr('style', setInlineStyleProperty($item.attr('style'), 'margin-left', '0 !important'));
|
|
739
|
+
const $content = $item.children('span[data-wxgzh="li-inline"]').first();
|
|
740
|
+
if ($content.length === 0) {
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
$content.children('span[data-wxgzh="ul-marker"]').remove();
|
|
744
|
+
$content.prepend('<span data-wxgzh="ul-marker">● </span>');
|
|
745
|
+
const $marker = $content.children('span[data-wxgzh="ul-marker"]').first();
|
|
746
|
+
$marker.attr('style', setInlineStyleProperty($marker.attr('style'), 'display', 'inline !important'));
|
|
747
|
+
$marker.attr('style', setInlineStyleProperty($marker.attr('style'), 'line-height', 'inherit !important'));
|
|
748
|
+
$marker.attr('style', setInlineStyleProperty($marker.attr('style'), 'font-size', '1.1em !important'));
|
|
749
|
+
$marker.attr('style', setInlineStyleProperty($marker.attr('style'), 'font-weight', '700 !important'));
|
|
750
|
+
$marker.attr('style', setInlineStyleProperty($marker.attr('style'), 'color', '#000000 !important'));
|
|
751
|
+
});
|
|
752
|
+
}
|
|
703
753
|
function removeWechatUnsafeListWhitespace($) {
|
|
704
754
|
$('ol, ul').each((_, element) => {
|
|
705
755
|
$(element)
|
|
@@ -807,6 +857,7 @@ function cleanInlinedHtml(html) {
|
|
|
807
857
|
$element.html(renderWechatFriendlyCodeHtml($element.contents().toArray()));
|
|
808
858
|
});
|
|
809
859
|
normalizeInlinedListStyles($);
|
|
860
|
+
decorateUnorderedListMarkers($);
|
|
810
861
|
removeWechatUnsafeListWhitespace($);
|
|
811
862
|
normalizeWechatCodeBlocks($);
|
|
812
863
|
const $article = $('body > #write > article').first();
|