This commit is contained in:
Jacobinwwey 2025-12-30 16:27:49 +08:00
parent ec39bd0da2
commit 7b2479a0ca
9 changed files with 93 additions and 23 deletions

View file

@ -20,7 +20,7 @@ A Easy way to create your own Knowledge-base!
Notemd enhances your Obsidian workflow by integrating with various Large Language Models (LLMs) to process your multi-languages notes, automatically generate wiki-links for key concepts, create corresponding concept notes, perform web research, helping you build powerful knowledge graphs and more.
**Version:** 1.6.0
**Version:** 1.6.1
<img width="1853" height="1080" alt="show" src="https://github.com/user-attachments/assets/b9f9292b-a9d8-48a3-9acf-1b6f00413966" />
<img width="1853" height="1080" alt="multi-langu" src="https://github.com/user-attachments/assets/d9a0a4fb-1c00-425a-ac1d-0134a013a381" />
@ -117,7 +117,7 @@ That's it! Explore the settings to unlock more features like web research, trans
- **Error Reporting**: Generates a `mermaid_error_{foldername}.md` report listing files that still contain potential Mermaid errors after processing.
- **Move Error Files**: Optionally moves files with detected errors to a specified folder for manual review.
- **Smart Detection**: Now intelligently checks files for syntax errors using `mermaid.parse` before attempting fixes, saving processing time and avoiding unnecessary edits.
- **Safe Processing**: Ensures syntax fixes are applied exclusively to Mermaid code blocks, preventing accidental modification of Markdown tables or other content.
- **Safe Processing**: Ensures syntax fixes are applied exclusively to Mermaid code blocks, preventing accidental modification of Markdown tables or other content. Includes robust safeguards to protect table syntax (e.g., `| :--- |`) from aggressive debug fixes.
- **Deep Debug Mode**: If errors persist after the initial fix, an advanced deep debug mode is triggered. This mode handles complex edge cases, including:
- **Comment Integration**: Automatically merges trailing comments (starting with `%`) into the edge label (e.g., `A -- Label --> B; % Comment` becomes `A -- "Label(Comment)" --> B;`).
- **Malformed Arrows**: Fixes arrows absorbed into quotes (e.g., `A -- "Label -->" B` becomes `A -- "Label" --> B`).
@ -535,7 +535,7 @@ MIT License - See [LICENSE](LICENSE) file for details.
---
*Notemd v1.5.0 - Enhance your Obsidian knowledge graph with AI.*
*Notemd v1.6.1 - Enhance your Obsidian knowledge graph with AI.*
![Star History Chart](https://api.star-history.com/svg?repos=Jacobinwwey/obsidian-NotEMD&type=Date)

View file

@ -18,7 +18,7 @@
Notemd 通过与各种大型语言模型 (LLM) 集成来增强您的 Obsidian 工作流程支持多语言笔记处理自动为关键概念生成维基链接、创建相应的概念笔记、执行网页搜索与摘要、翻译内容、总结为Mermaid脑图等助力构建强大的知识图谱。
**版本:** 1.6.0
**版本:** 1.6.1
![image](https://img.shields.io/github/v/release/Jacobinwwey/obsidian-NotEMD?label=Version&link=https%3A%2F%2Fgithub.com%2Jacobinwwey%2Fobsidian-NotEMD%2Freleases%2Flatest) ![image](https://img.shields.io/github/downloads/Jacobinwwey/obsidian-NotEMD/total?logo=Obsidian&label=Downloads&labelColor=%237C3AED&color=%235b5b5b&link=https%3A%2F%2Fgithub.com%2Jacobinwwey%2Fobsidian-NotEMD%2Freleases%2Flatest)
@ -115,7 +115,7 @@ Notemd 通过与各种大型语言模型 (LLM) 集成来增强您的 Obsidian
- **错误报告**: 生成 `mermaid_error_{foldername}.md` 报告列出处理后仍包含潜在Mermaid错误的文件。
- **移动错误文件**: 可选地将检测到错误的文件移动到指定文件夹以供手动审查。
- **智能检测**: 在尝试修复之前,使用 `mermaid.parse` 智能检查文件是否存在语法错误,节省处理时间并避免不必要的编辑。
- **安全处理**: 确保语法修复仅应用于 Mermaid 代码块,防止意外修改 Markdown 表格或其他内容。
- **安全处理**: 确保语法修复仅应用于 Mermaid 代码块,防止意外修改 Markdown 表格或其他内容。包含针对表格语法(例如 `| :--- |`)的稳健保护措施,防止被深度调试功能误修。
- **深度调试模式**: 如果初始修复后错误仍然存在,将触发高级深度调试模式。此模式处理复杂的边缘情况,包括:
- **注释集成**: 自动将尾随注释(以 `%` 开头)合并到连接线标签中(例如,`A -- Label --> B; % Comment` 变为 `A -- "Label(Comment)" --> B;`)。
- **畸形箭头**: 修复被引号吸收的箭头(例如 `A -- "Label -->" B` 修正为 `A -- "Label" --> B`)。
@ -600,6 +600,6 @@ MIT许可证 - 详情请见[LICENSE](LICENSE)。
---
*Notemd v1.5.0 - 用AI提升你的Obsidian知识图谱。*
*Notemd v1.6.1 - 用AI提升你的Obsidian知识图谱。*
![Star History Chart](https://api.star-history.com/svg?repos=Jacobinwwey/obsidian-NotEMD&type=Date)

View file

@ -8,9 +8,11 @@ This document summarizes the major functional and architectural changes implemen
### English
* **Fix Mermaid Table Corruption**: Resolved a critical issue where the "Batch Mermaid Fix" and "Deep Debug" features would incorrectly apply syntax fixes to Markdown tables (e.g., changing `| : --- |` to `| : -- "- |`), ensuring that modifications are strictly limited to code blocks within ```mermaid``` tags.
* **Enhanced Table Protection**: Implemented robust safeguards in the deep debug processor to specifically ignore lines matching Markdown table separators (e.g., `| :--- |`) and lines containing `:-- :`, preserving table integrity even in aggressive fix modes.
### Chinese (中文)
* **修复Mermaid表格损坏**: 解决了“批量Mermaid修复”和“深度调试”功能错误地将语法修复应用于Markdown表格例如`| : --- |` 更改为 `| : -- "- |`)的关键问题,确保修改严格限制在 ```mermaid``` 标签内的代码块中。
* **增强的表格保护**: 在深度调试处理器中实现了稳健的保护措施专门忽略匹配Markdown表格分隔符例如 `| :--- |`)和包含 `:-- :` 的行,即使在激进的修复模式下也能保持表格完整性。
---

View file

@ -1,7 +1,7 @@
{
"id": "notemd",
"name": "Notemd",
"version": "1.6.0",
"version": "1.6.1",
"minAppVersion": "0.15.0",
"description": "Enhances notes using LLMs: 1) Processes text to add [[wiki-links]] and create concept notes. 2) Performs web research (Tavily/DuckDuckGo) and summarizes topics. 3) Generates content from note titles. 4) Translates notes/selections. 5) build powerful knowledge graphs Supports multiple LLM providers and customizable output.",
"author": "jacob",

View file

@ -1,6 +1,6 @@
{
"name": "notemd",
"version": "1.6.0",
"version": "1.6.1",
"description": "Enhances notes using LLMs: 1) Processes text to add [[wiki-links]] and create concept notes. 2) Performs web research (Tavily/DuckDuckGo) and summarizes topics. 3) Generates content from note titles. 4) Translates notes/selections. Supports multiple LLM providers and customizable output.",
"main": "main.js",
"scripts": {

View file

@ -5,7 +5,7 @@ import { NotemdSettings, ProgressReporter } from './types';
import { DEFAULT_SETTINGS } from './constants';
import { normalizeNameForFilePath, splitContent, getProviderForTask, getModelForTask, delay, createConcurrentProcessor, chunkArray, retry } from './utils'; // Added delay import
import { callDeepSeekAPI, callOpenAIApi, callAnthropicApi, callGoogleApi, callMistralApi, callAzureOpenAIApi, callLMStudioApi, callOllamaApi, callOpenRouterAPI } from './llmUtils';
import { refineMermaidBlocks, cleanupLatexDelimiters, deepDebugMermaid, checkMermaidErrors } from './mermaidProcessor'; // Assuming this will be moved or imported correctly later
import { refineMermaidBlocks, cleanupLatexDelimiters, deepDebugMermaid, applyDeepDebugToMermaidBlocks, checkMermaidErrors } from './mermaidProcessor'; // Assuming this will be moved or imported correctly later
import { _performResearch } from './searchUtils'; // Assuming this will be moved or imported correctly later
import { showDeletionConfirmationModal } from './ui/modals'; // Assuming this will be moved or imported correctly later
import mermaid from 'mermaid';
@ -1003,7 +1003,7 @@ export async function batchFixMermaidSyntaxInFolder(app: App, settings: NotemdSe
if (fileErrorCount > 0) {
progressReporter.log(`⚠️ Errors persist in ${file.name}. Attempting Deep Debug...`);
const deepDebugged = deepDebugMermaid(content);
const deepDebugged = applyDeepDebugToMermaidBlocks(content);
if (deepDebugged !== content) {
// Apply deep debug changes

View file

@ -246,6 +246,21 @@ export async function refineMermaidBlocks(content: string): Promise<string> {
return result;
}
/**
* Applies deep debug fixes ONLY to the content within Mermaid code blocks.
* This is a safe alternative to calling deepDebugMermaid on the entire file.
* @param content The markdown content.
* @returns The processed content with Mermaid blocks debugged.
*/
export function applyDeepDebugToMermaidBlocks(content: string): string {
const mermaidBlockRegex = /(```\s*mermaid\n)([\s\S]*?)(\n```)/gi;
return content.replace(mermaidBlockRegex, (match, startTag, blockContent, endTag) => {
const processedBlock = deepDebugMermaid(blockContent);
return `${startTag}${processedBlock}${endTag}`;
});
}
/**
* Cleans up LaTeX math delimiters.
* Converts \( and \) to $.
@ -307,8 +322,26 @@ export function cleanupLatexDelimiters(content: string): string {
* 14. Enhanced Note and Semicolon Cleanup.
*/
export function deepDebugMermaid(content: string): string {
// --- SAFEGUARD: Protect Table Lines ---
// User requirement: Ensure no modification to lines containing ':-- :'
// Also protecting standard markdown table separators to prevent corruption
const tableLinePlaceholderPrefix = '___PROTECTED_TABLE_LINE_';
const protectedTableLines: string[] = [];
// Regex for table separator line: starts with |, contains dashes/colons/pipes, ends with | (roughly)
const tableSeparatorRegex = /^\s*\|(?:[\s\t]*:?[\s\t]*-+[\s\t]*:?[\s\t]*\|)+[\s\t]*$/;
let processed = content.split('\n').map(line => {
if (line.includes(':-- :') || tableSeparatorRegex.test(line)) {
const placeholder = `${tableLinePlaceholderPrefix}${protectedTableLines.length}___`;
protectedTableLines.push(line);
return placeholder;
}
return line;
}).join('\n');
// 0. Fix Smart Quotes FIRST - handles “” -> "" and Note["/“text”/"] -> Note["/text/"]
let processed = fixSmartQuotes(content);
processed = fixSmartQuotes(processed);
// 1. Fix Mermaid Pipes (handle `|`) - Requested to be first
processed = fixMermaidPipes(processed);
@ -343,7 +376,7 @@ export function deepDebugMermaid(content: string): string {
// 10. Fix Doubled IDs (SplitSplit Sample -> Split[Split Sample])
processed = fixDoubledID(processed);
// 11. Fix Excessive Brackets (Clean up [[...]] and handle ["; patterns)
// 11. Fix Excessive Brackets (including ]]] -> ]).
processed = fixExcessiveBrackets(processed);
// 12. Fix Semicolon Positioning (Move "] before ;)
@ -355,7 +388,7 @@ export function deepDebugMermaid(content: string): string {
// 13. Fix Unquoted Labels Ending with Semicolons
processed = fixUnquotedLabelsWithSemicolons(processed);
// 14. Enhanced Note Pattern and Semicolon Content Removal
// 14. Enhanced Note and Semicolon Cleanup.
processed = enhancedNoteAndSemicolonCleanup(processed);
// 15. Fix Reverse Arrows (<--)
@ -367,7 +400,7 @@ export function deepDebugMermaid(content: string): string {
// 18. Fix Duplicate Labels (["..."]["..."] -> ["..."])
processed = fixDuplicateLabels(processed);
// 19. Fix Nested Mermaid Quotes (["...["..."]..."] -> ["...[...]..."])
// 19. Fix Nested Mermaid Quotes (["...["..."]...."] -> ["...[...]..."])
processed = fixNestedMermaidQuotes(processed);
// 20. Fix Quoted Labels After Semicolon (A --> B; "Label" -> A -- "Label" --> B;)
@ -391,6 +424,22 @@ export function deepDebugMermaid(content: string): string {
// 26. Fix Shape Mismatch ([/["...["/] -> ["..."])
processed = fixShapeMismatch(processed);
// --- RESTORE: Table Lines ---
if (protectedTableLines.length > 0) {
// We need to restore them. Since we operate on the whole string, we can replace the placeholders.
// However, some functions might have shifted things around?
// Most functions are line-preserving or map lines.
// But `fixMermaidNotes` removes lines. `fixTargetedNotes` adds lines.
// The placeholders should persist as lines.
// We iterate through the protected lines and replace their corresponding placeholder
protectedTableLines.forEach((originalLine, index) => {
const placeholder = `${tableLinePlaceholderPrefix}${index}___`;
// Use split/join to replace all occurrences (though strictly should be one)
processed = processed.split(placeholder).join(originalLine);
});
}
return processed;
}

View file

@ -1,4 +1,4 @@
import { refineMermaidBlocks, deepDebugMermaid } from '../mermaidProcessor';
import { refineMermaidBlocks, deepDebugMermaid, applyDeepDebugToMermaidBlocks } from '../mermaidProcessor';
describe('Table Corruption Reproduction', () => {
const tableContent = `
@ -9,15 +9,33 @@ describe('Table Corruption Reproduction', () => {
const tripleBacktick = '```';
test('deepDebugMermaid should corrupt markdown tables (expected behavior for unsafe input)', () => {
// deepDebugMermaid applies global regexes.
test('deepDebugMermaid should NOT corrupt markdown tables due to safeguard', () => {
// deepDebugMermaid now has internal safeguards for lines with :-- :
const result = deepDebugMermaid(tableContent);
// The reported corruption: | : --- | becomes | : -- "- |
// We expect it to change (corrupt) because deepDebugMermaid is not context-aware on its own.
// The fix is in refineMermaidBlocks not calling it on non-mermaid content.
expect(result).not.toBe(tableContent);
expect(result).toContain('| : -- "- |');
// We expect it to REMAIN UNCHANGED
expect(result).toBe(tableContent);
expect(result).not.toContain('| : -- "- |');
});
test('applyDeepDebugToMermaidBlocks should not corrupt markdown tables outside mermaid blocks', () => {
const content = `
# Title
Some text.
${tableContent}
${tripleBacktick}mermaid
graph TD
A --> B
${tripleBacktick}
`;
const result = applyDeepDebugToMermaidBlocks(content);
// Table should be intact
expect(result).toContain('| : --- |');
expect(result).not.toContain('| : -- "- |');
});
test('refineMermaidBlocks should not corrupt markdown tables outside mermaid blocks', async () => {

View file

@ -3,5 +3,6 @@
"1.4.1": "0.15.0",
"1.5.0": "0.15.0",
"1.5.1": "0.15.0",
"1.6.0": "0.15.0"
"1.6.0": "0.15.0",
"1.6.1": "0.15.0"
}