Skip to content

Commit

Permalink
fix: Fix compatibility issue with litetools.
Browse files Browse the repository at this point in the history
  • Loading branch information
nfnfgo committed Oct 20, 2024
1 parent cbf2ec9 commit 069fb9a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
27 changes: 23 additions & 4 deletions src/render/msgpiece_processor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ const textElementProcessor: FragmentProcessFunc = (parent, element, index) => {
let settings = useSettingsStore.getState();

// generate rendered HTML processor based on user config.
function renderedHtmlPostProcessor(x: string) {
function renderedHtmlPostProcessor(x: string): string {
// text processor
if ((settings.forceEnableHtmlPurify() ?? settings.enableHtmlPurify) === true) {
mditLogger('debug', `Purify`, 'Input:', `${x}`);
return purifyHtml(x);
return purifyHtml(x) as string;
}

return x;
Expand Down Expand Up @@ -138,11 +138,30 @@ const textElementProcessor: FragmentProcessFunc = (parent, element, index) => {

// render
let renderedTextElement = element;
renderedTextElement.innerHTML = (
let renderedMarkdownInnerHtml = (
// first use markdownit to render the html text
// then passed to post processor (post processor also accept text)
renderedHtmlPostProcessor(getMarkdownIns().render(originalText))
renderedHtmlPostProcessor(getMarkdownIns().render(originalText)).trim()
);
mditLogger('debug', 'Rendered/post-processed HTML innterText:', renderedMarkdownInnerHtml);

// remove unnecessary wrapping <p> if there is only one element
let renderedHtmlElement = (new DOMParser).parseFromString(renderedMarkdownInnerHtml, 'text/html');
mditLogger('debug', 'renderedHtmlElement.children.length==1', renderedHtmlElement.children.length == 1);
mditLogger('debug', 'renderedMarkdownInnerHtml.startsWith(p)', renderedMarkdownInnerHtml.startsWith('<p>'));
mditLogger('debug', 'renderedMarkdownInnerHtml.endsWith(p)', renderedMarkdownInnerHtml.endsWith('</p>'));
if ((renderedHtmlElement.children.length == 1)
&& renderedMarkdownInnerHtml.startsWith('<p>')
&& renderedMarkdownInnerHtml.endsWith('</p>')) {
renderedMarkdownInnerHtml =
renderedMarkdownInnerHtml
.substring(3, renderedMarkdownInnerHtml.length - 4)
.trim();
mditLogger('debug', 'Striped innerHTML:', renderedMarkdownInnerHtml);
}

renderedTextElement.innerHTML = renderedMarkdownInnerHtml;


return {
original: element,
Expand Down
6 changes: 3 additions & 3 deletions src/style/markdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ pre.hl-code-block > button.lang_copy:not(:hover) > p.copy {
}

/* 修复轻量工具箱等插件时间显示多出换行的问题 */
.mix-message__inner {
/* .mix-message__inner {
display: flex;
flex-direction: row;
}
} */

.lite-tools-slot.embed-slot {
flex: none;
Expand All @@ -186,6 +186,6 @@ button.mdit-show-origin-button {
color: inherit;
opacity: 0.5;
padding-inline: 2px;
text-underline: auto;
/* text-underline: auto; */
border-width: 0px;
}

0 comments on commit 069fb9a

Please sign in to comment.