feat(new tool): Markdown Diff

Fix #1804
Co-authored-by: nimza <maz.webfreelance@gmail.com>
This commit is contained in:
ShareVB committed 2026-07-11 17:17:30 +02:00
1 parent 8b19bf00c3
commit 02df0f3e98
6 files changed
+301 -8

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Markdown Diff',
path: '/markdown-diff',
description: 'Compare two Markdown documents and see the differences between them.',
keywords: ['markdown', 'diff', 'compare', 'difference', 'markdown diff', 'md', 'text'],
component: () => import('./markdown-diff.vue'),
icon: defineAsyncComponent(() => import('@vicons/tabler/es/Markdown')),
createdAt: new Date('2026-07-10'),
category: 'Markdown',
});
@@ -0,0 +1,48 @@
export const originalMarkdown = `# Release notes
## Added
- JSON export for reports
- Keyboard shortcuts for navigation
- Markdown table previews
## Fixed
- Preserve whitespace in code blocks
## Plugin support
| user | host | plugin |
| --- | --- | --- |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
\`inline code\` stays readable in preview mode.
`;
export const modifiedMarkdown = `# Release notes
## Added
- JSON and CSV export for reports
- Keyboard shortcuts for navigation
- Dark mode support for charts
- Markdown table previews
## Fixed
- Preserve whitespace in fenced code blocks
## Plugin support
| user | host | plugin |
| --- | --- | --- |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
\`\`\`sql
select user, host, plugin
from mysql.user;
\`\`\`
`;
@@ -0,0 +1,33 @@
import { expect, test } from '@playwright/test';
test.describe('Tool - Markdown Diff', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/markdown-diff');
});
test('Has correct title', async ({ page }) => {
await expect(page).toHaveTitle('Markdown Diff - IT Tools', { timeout: 15000 });
});
test('Diff editor is visible with two editable panes', async ({ page }) => {
await expect(page.getByTestId('markdown-diff-editor')).toBeVisible();
await expect(page.locator('.monaco-diff-editor')).toBeVisible();
await expect(page.locator('.monaco-diff-editor .editor')).toHaveCount(2);
});
test('Preview mode shows rendered source and modified Markdown', async ({ page }) => {
await page.getByTestId('preview').click();
await expect(page.getByTestId('markdown-preview')).toBeVisible();
await expect(page.getByTestId('source-markdown-preview')).toBeVisible();
await expect(page.getByTestId('modified-markdown-preview')).toBeVisible();
await expect(page.getByTestId('source-markdown-preview').locator('table')).toBeVisible();
await expect(page.getByTestId('modified-markdown-preview')).toContainText('caching_sha2_password');
await page.getByTestId('code').click();
await expect(page.getByTestId('markdown-diff-editor')).toBeVisible();
await expect(page.locator('.monaco-diff-editor')).toBeVisible();
});
});
+138
View File
@@ -0,0 +1,138 @@
<template>
<div class="markdown-diff-tool">
<div flex justify-center mb-4>
<c-buttons-select v-model:value="mode" :options="modeOptions" size="small" />
</div>
<c-card v-if="mode === 'code'" w-full important:flex-1 important:pa-0>
<c-diff-editor
v-model:original="sourceMarkdown"
v-model:modified="targetMarkdown"
test-id="markdown-diff-editor"
language="markdown"
height="clamp(620px, 72vh, 820px)"
/>
</c-card>
<c-card v-else data-test-id="markdown-preview" w-full>
<div class="markdown-preview-grid">
<section>
<h3>Source Markdown</h3>
<div class="markdown-preview-pane" data-test-id="source-markdown-preview">
<c-markdown :markdown="sourceMarkdown" />
</div>
</section>
<section>
<h3>Modified Markdown</h3>
<div class="markdown-preview-pane" data-test-id="modified-markdown-preview">
<c-markdown :markdown="targetMarkdown" />
</div>
</section>
</div>
</c-card>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { modifiedMarkdown, originalMarkdown } from './markdown-diff.constants';
type MarkdownDiffMode = 'code' | 'preview';
const mode = ref<MarkdownDiffMode>('code');
const sourceMarkdown = ref(originalMarkdown);
const targetMarkdown = ref(modifiedMarkdown);
const modeOptions: Array<{ label: string; value: MarkdownDiffMode }> = [
{ label: 'Code', value: 'code' },
{ label: 'Preview', value: 'preview' },
];
</script>
<style lang="less" scoped>
.markdown-preview-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 24px;
section {
min-width: 0;
}
h3 {
margin: 0 0 12px;
font-size: 18px;
font-weight: 600;
}
}
.markdown-diff-tool {
width: 100%;
max-width: 1200px;
flex: 1 1 1200px !important;
}
.markdown-preview-pane {
min-height: clamp(620px, 72vh, 820px);
padding: 18px;
border: 1px solid #d8dee8;
border-radius: 8px;
overflow: auto;
}
:deep(.markdown-preview-pane) {
line-height: 1.65;
}
:deep(.markdown-preview-pane > div > *:first-child) {
margin-top: 0;
}
:deep(.markdown-preview-pane > div > *:last-child) {
margin-bottom: 0;
}
:deep(.markdown-preview-pane table) {
width: 100%;
border-collapse: collapse;
margin: 16px 0;
}
:deep(.markdown-preview-pane th),
:deep(.markdown-preview-pane td) {
padding: 10px 12px;
border: 1px solid #cfd6e2;
text-align: left;
}
:deep(.markdown-preview-pane th) {
font-weight: 600;
background: rgb(248 250 252);
}
:deep(.markdown-preview-pane code) {
padding: 2px 5px;
border-radius: 4px;
background: rgb(241 245 249);
}
:deep(.markdown-preview-pane pre) {
padding: 14px;
border-radius: 6px;
overflow: auto;
background: rgb(15 23 42);
}
:deep(.markdown-preview-pane pre code) {
padding: 0;
color: rgb(226 232 240);
background: transparent;
}
@media (max-width: 900px) {
.markdown-preview-grid {
grid-template-columns: 1fr;
}
}
</style>
+1 -1
View File
@@ -50,7 +50,7 @@ function selectOption(option: CButtonSelectOption<T>) {
<div class="flex gap-2">
<c-tooltip v-for="option in options" :key="option.value as PropertyKey" :tooltip="option.tooltip">
<c-button
:test-id="option.value"
:data-test-id="option.value"
:size="size"
:type="option.value === value ? 'primary' : 'default'"
@click="selectOption(option)"
+69 -7
View File
@@ -2,11 +2,35 @@
import * as monaco from 'monaco-editor';
import { useStyleStore } from '@/stores/style.store';
const props = withDefaults(defineProps<{ options?: monaco.editor.IDiffEditorOptions }>(), { options: () => ({}) });
const { options } = toRefs(props);
const props = withDefaults(
defineProps<{
options?: monaco.editor.IDiffEditorOptions;
original?: string;
modified?: string;
language?: string;
height?: string;
testId?: string;
}>(),
{
options: () => ({}),
original: 'original text',
modified: 'modified text',
language: 'txt',
height: '80vh',
testId: undefined,
},
);
const emit = defineEmits<{
'update:original': [value: string];
'update:modified': [value: string];
}>();
const { options, original, modified, language, height, testId } = toRefs(props);
const editorContainer = ref<HTMLElement | null>(null);
let editor: monaco.editor.IStandaloneDiffEditor | null = null;
let originalModel: monaco.editor.ITextModel | null = null;
let modifiedModel: monaco.editor.ITextModel | null = null;
let modelListeners: monaco.IDisposable[] = [];
monaco.editor.defineTheme('it-tools-dark', {
base: 'vs-dark',
@@ -32,16 +56,38 @@ const styleStore = useStyleStore();
watch(
() => styleStore.isDarkTheme,
isDarkTheme => monaco.editor.setTheme(isDarkTheme ? 'it-tools-dark' : 'it-tools-light'),
(isDarkTheme) => monaco.editor.setTheme(isDarkTheme ? 'it-tools-dark' : 'it-tools-light'),
{ immediate: true },
);
watch(
() => options.value,
options => editor?.updateOptions(options),
(options) => editor?.updateOptions(options),
{ immediate: true, deep: true },
);
watch(original, (value) => {
if (originalModel && originalModel.getValue() !== value) {
originalModel.setValue(value);
}
});
watch(modified, (value) => {
if (modifiedModel && modifiedModel.getValue() !== value) {
modifiedModel.setValue(value);
}
});
watch(language, (value) => {
if (originalModel) {
monaco.editor.setModelLanguage(originalModel, value);
}
if (modifiedModel) {
monaco.editor.setModelLanguage(modifiedModel, value);
}
});
useResizeObserver(editorContainer, () => {
editor?.layout();
});
@@ -56,15 +102,31 @@ onMounted(() => {
minimap: {
enabled: false,
},
...options.value,
});
originalModel = monaco.editor.createModel(original.value, language.value);
modifiedModel = monaco.editor.createModel(modified.value, language.value);
editor.setModel({
original: monaco.editor.createModel('original text', 'txt'),
modified: monaco.editor.createModel('modified text', 'txt'),
original: originalModel,
modified: modifiedModel,
});
modelListeners = [
originalModel.onDidChangeContent(() => emit('update:original', originalModel?.getValue() ?? '')),
modifiedModel.onDidChangeContent(() => emit('update:modified', modifiedModel?.getValue() ?? '')),
];
});
onBeforeUnmount(() => {
modelListeners.forEach((listener) => listener.dispose());
editor?.dispose();
originalModel?.dispose();
modifiedModel?.dispose();
});
</script>
<template>
<div ref="editorContainer" h-80vh />
<div ref="editorContainer" :data-test-id="testId" :style="{ height }" />
</template>