mirror of
https://github.com/yeban8090/mp-preview.git
synced 2026-07-22 12:40:24 +00:00
优化列表项加粗换行bug
This commit is contained in:
parent
177572ae9c
commit
5aaaee8a8a
3 changed files with 27 additions and 23 deletions
|
|
@ -23,19 +23,16 @@ export class MPConverter {
|
|||
|
||||
private static processElements(container: HTMLElement | null): void {
|
||||
if (!container) return;
|
||||
|
||||
// 处理强调文本
|
||||
container.querySelectorAll('strong, em').forEach(el => {
|
||||
el.classList.add('mp-inline');
|
||||
});
|
||||
|
||||
// 处理段落和有序列表之间的间距
|
||||
container.querySelectorAll('p + ol, p + ul').forEach(list => {
|
||||
const paragraph = list.previousElementSibling;
|
||||
if (paragraph && paragraph.tagName === 'P') {
|
||||
paragraph.classList.add('mp-paragraph-before-list');
|
||||
list.classList.add('mp-list-after-paragraph');
|
||||
// 处理列表项内部元素,用section包裹
|
||||
container.querySelectorAll('li').forEach(li => {
|
||||
// 创建section元素
|
||||
const section = document.createElement('section');
|
||||
// 将li的所有子元素移动到section中
|
||||
while (li.firstChild) {
|
||||
section.appendChild(li.firstChild);
|
||||
}
|
||||
// 将section添加到li中
|
||||
li.appendChild(section);
|
||||
});
|
||||
|
||||
// 处理代码块
|
||||
|
|
|
|||
|
|
@ -51,11 +51,11 @@ export class CreateTemplateModal extends Modal {
|
|||
after: ""
|
||||
}
|
||||
},
|
||||
paragraph: "line-height: 1.8; margin: 1.2em 0; font-size: 1em; color: #4a4a4a;",
|
||||
paragraph: "line-height: 1.8; margin: 0; font-size: 1em; color: #4a4a4a;",
|
||||
list: {
|
||||
container: "padding-left: 32px; margin-bottom: 1.2em; color: #4a4a4a;",
|
||||
item: "margin-bottom: 0.6em; font-size: 1em; color: #4a4a4a; line-height: 1.8;",
|
||||
taskList: "list-style: none; margin-left: -24px; font-size: 1em; color: #4a4a4a; line-height: 1.8;"
|
||||
container: "padding-left: 32px; color: #4a4a4a;",
|
||||
item: "margin-bottom: 0; font-size: 1em; color: #4a4a4a; line-height: 1.8;",
|
||||
taskList: "list-style: none; font-size: 1em; color: #4a4a4a; line-height: 1.8;"
|
||||
},
|
||||
code: {
|
||||
header: {
|
||||
|
|
@ -603,7 +603,8 @@ export class CreateTemplateModal extends Modal {
|
|||
const currentMargin = marginMatch ? marginMatch[1] : '';
|
||||
text.setValue(currentMargin)
|
||||
.onChange(value => {
|
||||
const margin = parseFloat(value) || 1.2;
|
||||
const value_num = parseFloat(value);
|
||||
const margin = !isNaN(value_num) ? value_num : 1.2;
|
||||
if (styles.paragraph.match(/margin:\s*[\d.]+em\s*0/)) {
|
||||
// margin: 1.2em 0; 只替换第一个值
|
||||
styles.paragraph = styles.paragraph.replace(/margin:\s*[\d.]+em\s*0/, `margin: ${margin}em 0`);
|
||||
|
|
@ -708,7 +709,8 @@ export class CreateTemplateModal extends Modal {
|
|||
const currentMargin = styles.item.match(/margin-bottom:\s*([\d.]+)em/)?.[1];
|
||||
text.setValue(currentMargin)
|
||||
.onChange(value => {
|
||||
const margin = parseFloat(value) || 0.8;
|
||||
const value_num = parseFloat(value);
|
||||
const margin = !isNaN(value_num) ? value_num : 1.2;
|
||||
styles.item = styles.item.replace(/margin-bottom:\s*[\d.]+em/, `margin-bottom: ${margin}em`);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,13 +11,16 @@
|
|||
border: 1px solid rgba(82, 144, 220, 0.08);
|
||||
}
|
||||
|
||||
/* 调整段落和列表之间的间距 */
|
||||
.mp-content-section .mp-paragraph-before-list {
|
||||
margin-bottom: 0.5em !important;
|
||||
/* 段落 */
|
||||
.mp-content-section p {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.mp-content-section .mp-list-after-paragraph {
|
||||
margin-top: 0.5em !important; /* 减小列表顶部边距 */
|
||||
/* 列表 */
|
||||
.mp-content-section ul,ol {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* 链接样式 */
|
||||
|
|
@ -82,6 +85,8 @@
|
|||
line-height: inherit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.mp-empty-message {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
|
|
|||
Loading…
Reference in a new issue