arvid-e 8 месяцев назад
Родитель
Сommit
127d56f150

+ 0 - 43
apps/app/src/services/renderer/rehype-plugins/add-inline-code-attribute.ts

@@ -1,43 +0,0 @@
-import type { Element } from 'hast';
-
-export function rehypePlugin() {
-  return (tree: any) => { // 'any' needs replacing probably
-    function visitor(node: Element, parent: Element | null) {
-      if (node.tagName === 'code') {
-        const isInsidePre = parent
-                            && parent.type === 'element'
-                            && parent.tagName === 'pre';
-
-        if (!isInsidePre) {
-          node.properties = node.properties || {};
-
-          if (!node.properties.className) {
-            node.properties.className = [];
-          }
-          // This is the key part: push 'code-inline' to className
-          if (Array.isArray(node.properties.className) && !node.properties.className.includes('code-inline')) {
-            (node.properties.className as string[]).push('code-inline');
-          }
-        }
-      }
-
-      if ('children' in node && Array.isArray(node.children)) {
-        for (let i = 0; i < node.children.length; i++) {
-          const child = node.children[i];
-          if (child.type === 'element') {
-            visitor(child as Element, node);
-          }
-        }
-      }
-    }
-
-    if ('children' in tree && Array.isArray(tree.children)) {
-      for (let i = 0; i < tree.children.length; i++) {
-        const child = tree.children[i];
-        if (child.type === 'element') {
-          visitor(child as Element, tree as Element); // Pass tree as parent for its direct children
-        }
-      }
-    }
-  };
-}

+ 5 - 10
apps/app/src/services/renderer/remark-plugins/codeblock.ts

@@ -4,10 +4,13 @@ import type { Plugin } from 'unified';
 import { visit } from 'unist-util-visit';
 
 
+const SUPPORTED_CODE = ['inline'];
+
 export const remarkPlugin: Plugin = () => {
   return (tree) => {
     visit(tree, 'inlineCode', (node: InlineCode) => {
-      // REMOVE THIS BLOCK
+      const data = node.data || (node.data = {});
+      data.hProperties = { inline: 'true' }; // set 'true' explicitly because the empty string is evaluated as false for `if (inline) { ... }`
     });
   };
 };
@@ -15,14 +18,6 @@ export const remarkPlugin: Plugin = () => {
 export const sanitizeOption: SanitizeOption = {
   tagNames: ['code'],
   attributes: {
-
-    code: [
-      'className', // Allow the 'class' attribute on <code> tags
-      ['className', 'code-inline'], // Explicitly allow 'code-inline' as a class value
-      // By NOT listing 'inline' here, rehype-sanitize will strip inline="true"
-      // which is what you want for Markdown inline code.
-    ],
-    // If you have `data-line` attributes on code blocks, you might need to allow them globally or specifically:
-    '*': ['data-line'],
+    code: SUPPORTED_CODE,
   },
 };