diff --git a/package-lock.json b/package-lock.json
index 7e44138..8945ef7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,10 @@
{
- "name": "markdown_it",
+ "name": "markdown-it",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
- "@types/react": "^18.3.3",
- "@types/react-dom": "^18.3.0",
"dompurify": "^3.1.5",
"highlight.js": "^11.9.0",
"immer": "^10.1.1",
@@ -24,6 +22,8 @@
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@types/markdown-it": "^14.1.1",
+ "@types/react": "^18.3.3",
+ "@types/react-dom": "^18.3.0",
"@types/throttle-debounce": "^5.0.2",
"babel-loader": "^9.1.3",
"webpack": "^5.92.1",
@@ -2266,7 +2266,8 @@
"node_modules/@types/prop-types": {
"version": "15.7.12",
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.12.tgz",
- "integrity": "sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q=="
+ "integrity": "sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==",
+ "devOptional": true
},
"node_modules/@types/qs": {
"version": "6.9.15",
@@ -2284,6 +2285,7 @@
"version": "18.3.3",
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.3.tgz",
"integrity": "sha512-hti/R0pS0q1/xx+TsI73XIqk26eBsISZ2R0wUijXIngRK9R/e7Xw/cXVxQK7R5JjW+SV4zGcn5hXjudkN/pLIw==",
+ "devOptional": true,
"dependencies": {
"@types/prop-types": "*",
"csstype": "^3.0.2"
@@ -2293,6 +2295,7 @@
"version": "18.3.0",
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.0.tgz",
"integrity": "sha512-EhwApuTmMBmXuFOikhQLIBUn6uFg81SwLMOAUgodJF14SOBOCMdU04gDoYi0WOJJHD144TL32z4yDqCW3dnkQg==",
+ "dev": true,
"dependencies": {
"@types/react": "*"
}
@@ -3285,7 +3288,8 @@
"node_modules/csstype": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
- "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="
+ "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
+ "devOptional": true
},
"node_modules/debug": {
"version": "2.6.9",
diff --git a/src/components/code_block.jsx b/src/components/code_block.jsx
index 8036c83..2a5f35b 100644
--- a/src/components/code_block.jsx
+++ b/src/components/code_block.jsx
@@ -100,8 +100,12 @@ export function changeDirectionToColumnWhenLargerHeight() {
var msgBlocks = document.querySelectorAll('.mix-message__inner');
Array.from(msgBlocks).forEach(function (block) {
var height = block.offsetHeight;
- if (height > 30) {
+ mditLogger('debug', 'Detected messagebox height:', height);
+ if (height > 35) {
block.style.flexDirection = 'column';
}
+ else {
+ block.style.flexDirection = 'row';
+ }
});
}
\ No newline at end of file
diff --git a/src/render/msgpiece_processor.ts b/src/render/msgpiece_processor.ts
deleted file mode 100644
index a698fb0..0000000
--- a/src/render/msgpiece_processor.ts
+++ /dev/null
@@ -1,129 +0,0 @@
-import { useSettingsStore } from '@/states/settings';
-import { escapeHtml, purifyHtml, unescapeHtml } from '@/utils/htmlProc';
-import { mditLogger } from '@/utils/logger';
-
-type ReplaceFunc = (parentElement: HTMLElement, id: string) => any;
-
-const TEXT_ELEMENT_MATCHER = 'text-element';
-const IMG_ELEMENT_MATCHER = 'pic-element';
-
-/**
- * Data type used by renderer to determine how to render and replace an element.
- */
-export interface MsgProcessInfo {
- mark: string;
- replace?: ReplaceFunc;
- id?: string;
-}
-
-/**
- * Function type that used to process children elements inside QQNT message box.
- */
-type FragmentProcessFunc = (element: HTMLElement, index: number) => MsgProcessInfo | undefined;
-
-function textElementProcessor(element: Element): MsgProcessInfo | undefined {
- // return undefine if type not match
- if (!(element.tagName == 'SPAN') || !element.classList.contains(TEXT_ELEMENT_MATCHER) || element.querySelector('.text-element--at')) {
- return undefined;
- }
-
- mditLogger('debug', 'ElementMatch', 'Source', element);
- mditLogger('debug', 'Element', 'Match', 'spanTextProcessor');
-
- // text processor
- let settings = useSettingsStore.getState();
- function entityProcesor(x: string) {
- if (settings.unescapeAllHtmlEntites == true) {
- return unescapeHtml(x);
- }
- if (settings.unescapeGtInText == true) {
- return x.replaceAll('>', '>');
- }
- return x;
- }
-
- return {
- mark: Array.from(element.getElementsByTagName("span"))
- .map((element) => element.innerHTML)
- .reduce((acc, x) => acc + entityProcesor(x), ''),
- };
-}
-
-/**
- * This fucked up everything.
- */
-const picElementProcessor = replaceFuncGenerator({ filter: (e) => e.classList.contains(IMG_ELEMENT_MATCHER), placeholder: (id) => (` `) });
-
-const spanReplaceProcessor = replaceFuncGenerator({
- filter: (e) => (
- e.tagName == 'SPAN' || // deal with span
- (e.tagName == 'DIV' && (e.classList?.contains('reply-element') ?? false)) // deal with reply element
- )
-});
-
-
-interface replaceFuncGeneratorProps {
- /**
- * The generated processort with only deal with elements which this filter returns `true`.
- */
- filter: (element: HTMLElement) => boolean,
- /**
- * Custom function to generate placeholder text based on id.
- */
- placeholder?: (id: string) => string,
- /**
- * Custom replace function. Use defaul one if `undefined`.
- */
- replace?: (parent: HTMLElement, id: string) => any,
-}
-
-function replaceFuncGenerator(
- props: replaceFuncGeneratorProps,
-): FragmentProcessFunc {
- let {
- filter,
- placeholder,
- } = props;
- placeholder ??= (id) => (``);
-
- return function (element: HTMLElement, index: number) {
- if (!filter(element)) {
- return undefined;
- }
-
- let id = `placeholder-${index}`;
- let replace = props.replace;
-
- replace ??= (parent: HTMLElement, id: string) => {
- try {
- // here oldNode may be `undefined` or `null`.
- // Plugin will broke without this try catch block.
- mditLogger('debug', 'Try replace oldNode with element:', element);
- mditLogger('debug', 'Search placeholder with id', id);
-
- const oldNode = parent.querySelector(`#${id}`);
- mditLogger('debug', 'Old node found', oldNode);
-
- oldNode.replaceWith(element);
- mditLogger('debug', 'Replace success:', element);
- } catch (e) {
- mditLogger('error', 'Replace failed on element:', element, e);
- }
- };
-
- return {
- mark: placeholder(id),
- id: id,
- replace: replace,
- }
- }
-}
-
-/**
- * Triggered from begin to end, preemptive.
- */
-export const processorList: FragmentProcessFunc[] = [
- picElementProcessor,
- textElementProcessor,
- spanReplaceProcessor,
-];
\ No newline at end of file
diff --git a/src/render/msgpiece_processor.tsx b/src/render/msgpiece_processor.tsx
new file mode 100644
index 0000000..69e1320
--- /dev/null
+++ b/src/render/msgpiece_processor.tsx
@@ -0,0 +1,249 @@
+// markdown
+import React from 'react';
+import markdownIt from 'markdown-it';
+import { renderToString } from 'react-dom/server';
+const hljs = require('highlight.js');
+import katex from '@/lib/markdown-it-katex';
+
+// Components
+import { HighLightedCodeBlock, renderInlineCodeBlockString } from '@/components/code_block';
+
+// Settings
+import { useSettingsStore } from '@/states/settings';
+
+// Utils
+import { escapeHtml, purifyHtml, unescapeHtml } from '@/utils/htmlProc';
+import { mditLogger } from '@/utils/logger';
+
+
+
+type ReplaceFunc = (parentElement: HTMLElement, id: string) => any;
+
+const TEXT_ELEMENT_MATCHER = 'text-element';
+const IMG_ELEMENT_MATCHER = 'pic-element';
+
+const HANDLED_BY_FRAG_PROC_PREFIX = 'markdown-it-handled-as-'
+
+/**
+ * Data type used by renderer to determine how to render and replace an element.
+ */
+export interface MsgProcessInfo {
+ mark: string;
+ replace?: ReplaceFunc;
+ id?: string;
+}
+
+// declare const LiteLoader: LiteLoaderInterFace