mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 15:44:21 +00:00
Compare commits
13 Commits
v0.5.2
...
6c408fdfbe
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c408fdfbe | |||
| 6753f32520 | |||
| de06939b01 | |||
| c11d956ced | |||
| 9a232819a8 | |||
| f9ce8b9e9f | |||
| a6d2663a7d | |||
| 071e99f4da | |||
| b13ee987c7 | |||
| 543dbe6ffe | |||
| d0842c515f | |||
| 01d9a984fc | |||
|
|
a3975c9acd |
8
app/package-lock.json
generated
8
app/package-lock.json
generated
@@ -55,7 +55,7 @@
|
||||
"postcss-simple-vars": "^7.0.1",
|
||||
"sass": "^1.80.4",
|
||||
"typescript": "^5.8.2",
|
||||
"vite": "^6.3.6",
|
||||
"vite": "^6.4.1",
|
||||
"vite-plugin-compression2": "^1.3.0",
|
||||
"vitest": "^3.1.4"
|
||||
}
|
||||
@@ -9696,9 +9696,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/vite": {
|
||||
"version": "6.3.6",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-6.3.6.tgz",
|
||||
"integrity": "sha512-0msEVHJEScQbhkbVTb/4iHZdJ6SXp/AvxL2sjwYQFfBqleHtnCqv1J3sa9zbWz/6kW1m9Tfzn92vW+kZ1WV6QA==",
|
||||
"version": "6.4.1",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.1.tgz",
|
||||
"integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
"postcss-simple-vars": "^7.0.1",
|
||||
"sass": "^1.80.4",
|
||||
"typescript": "^5.8.2",
|
||||
"vite": "^6.3.6",
|
||||
"vite": "^6.4.1",
|
||||
"vite-plugin-compression2": "^1.3.0",
|
||||
"vitest": "^3.1.4"
|
||||
},
|
||||
|
||||
@@ -108,29 +108,3 @@ $navbar-height: 64px;
|
||||
.tree {
|
||||
padding-top: $padding;
|
||||
}
|
||||
|
||||
// Syntax highlighting themes
|
||||
@import 'highlight.js/styles/github.css' layer(light-theme);
|
||||
@import 'highlight.js/styles/github-dark.css' layer(dark-theme);
|
||||
|
||||
// Show light theme by default
|
||||
@layer light-theme {
|
||||
[data-mantine-color-scheme='light'] .markdown-preview {
|
||||
pre code.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
padding: 1em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Show dark theme in dark mode
|
||||
@layer dark-theme {
|
||||
[data-mantine-color-scheme='dark'] .markdown-preview {
|
||||
pre code.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
padding: 1em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,16 @@ export const apiCall = async (
|
||||
// Set up headers with CSRF token for non-GET requests
|
||||
const method = options.method || 'GET';
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
...(options.headers as Record<string, string>),
|
||||
};
|
||||
|
||||
// Only set Content-Type to application/json if not already set and body is not FormData
|
||||
// FormData requires the browser to set Content-Type with the boundary parameter
|
||||
const isFormData = options.body instanceof FormData;
|
||||
if (!headers['Content-Type'] && !isFormData) {
|
||||
headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
|
||||
// Add CSRF token for non-GET methods
|
||||
if (method !== 'GET') {
|
||||
const csrfToken = getCsrfToken();
|
||||
@@ -41,11 +47,18 @@ export const apiCall = async (
|
||||
}
|
||||
}
|
||||
|
||||
// For FormData, don't include Content-Type in headers - let the browser set it
|
||||
const fetchHeaders = isFormData
|
||||
? Object.fromEntries(
|
||||
Object.entries(headers).filter(([key]) => key !== 'Content-Type')
|
||||
)
|
||||
: headers;
|
||||
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
// Include credentials to send/receive cookies
|
||||
credentials: 'include',
|
||||
headers,
|
||||
headers: fetchHeaders,
|
||||
});
|
||||
console.debug(`Response status: ${response.status} for URL: ${url}`);
|
||||
|
||||
|
||||
@@ -120,6 +120,34 @@ describe('MarkdownPreview', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('renders code blocks with correct structure for theme switching', async () => {
|
||||
const content = '```javascript\nconst hello = "world";\n```';
|
||||
|
||||
render(
|
||||
<MarkdownPreview
|
||||
content={content}
|
||||
handleFileSelect={mockHandleFileSelect}
|
||||
/>
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
// Check that rehype-highlight generates the correct structure
|
||||
const preElement = screen
|
||||
.getByRole('code', { hidden: true })
|
||||
.closest('pre');
|
||||
const codeElement = preElement?.querySelector('code');
|
||||
|
||||
expect(preElement).toBeInTheDocument();
|
||||
expect(codeElement).toBeInTheDocument();
|
||||
|
||||
// The code element should have hljs class for theme switching to work
|
||||
expect(codeElement).toHaveClass('hljs');
|
||||
|
||||
// Should also have language class
|
||||
expect(codeElement).toHaveClass('language-javascript');
|
||||
});
|
||||
});
|
||||
|
||||
it('handles image loading errors gracefully', async () => {
|
||||
const content = '';
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import * as prod from 'react/jsx-runtime';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
import { remarkWikiLinks } from '../../utils/remarkWikiLinks';
|
||||
import { useWorkspace } from '../../hooks/useWorkspace';
|
||||
import { useHighlightTheme } from '../../hooks/useHighlightTheme';
|
||||
|
||||
interface MarkdownPreviewProps {
|
||||
content: string;
|
||||
@@ -28,12 +29,6 @@ interface MarkdownLinkProps {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
interface MarkdownCodeProps {
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
const MarkdownPreview: React.FC<MarkdownPreviewProps> = ({
|
||||
content,
|
||||
handleFileSelect,
|
||||
@@ -42,7 +37,10 @@ const MarkdownPreview: React.FC<MarkdownPreviewProps> = ({
|
||||
null
|
||||
);
|
||||
const baseUrl = window.API_BASE_URL;
|
||||
const { currentWorkspace } = useWorkspace();
|
||||
const { currentWorkspace, colorScheme } = useWorkspace();
|
||||
|
||||
// Use the highlight theme hook
|
||||
useHighlightTheme(colorScheme === 'auto' ? 'light' : colorScheme);
|
||||
|
||||
const processor = useMemo(() => {
|
||||
const handleLinkClick = (
|
||||
@@ -107,13 +105,6 @@ const MarkdownPreview: React.FC<MarkdownPreviewProps> = ({
|
||||
{children}
|
||||
</a>
|
||||
),
|
||||
code: ({ children, className, ...props }: MarkdownCodeProps) => {
|
||||
return (
|
||||
<pre className={className}>
|
||||
<code {...props}>{children}</code>
|
||||
</pre>
|
||||
);
|
||||
},
|
||||
},
|
||||
} as Options);
|
||||
}, [currentWorkspace?.name, baseUrl, handleFileSelect]);
|
||||
|
||||
@@ -122,7 +122,8 @@ export const useFileOperations = (): UseFileOperationsResult => {
|
||||
if (!currentWorkspace) return false;
|
||||
|
||||
try {
|
||||
await uploadFile(currentWorkspace.name, targetPath || '', files);
|
||||
// Default to '.' (root directory) if no target path is provided
|
||||
await uploadFile(currentWorkspace.name, targetPath || '.', files);
|
||||
|
||||
notifications.show({
|
||||
title: 'Success',
|
||||
|
||||
36
app/src/hooks/useHighlightTheme.ts
Normal file
36
app/src/hooks/useHighlightTheme.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { useEffect } from 'react';
|
||||
// Import theme CSS as text that will be bundled
|
||||
import atomOneLightTheme from 'highlight.js/styles/atom-one-light.css?inline';
|
||||
import atomOneDarkTheme from 'highlight.js/styles/atom-one-dark.css?inline';
|
||||
|
||||
export const useHighlightTheme = (colorScheme: 'light' | 'dark') => {
|
||||
useEffect(() => {
|
||||
// Remove existing highlight theme
|
||||
const existingStylesheet = document.querySelector(
|
||||
'style[data-highlight-theme]'
|
||||
);
|
||||
if (existingStylesheet) {
|
||||
existingStylesheet.remove();
|
||||
}
|
||||
|
||||
// Add new theme stylesheet using bundled CSS
|
||||
const style = document.createElement('style');
|
||||
style.setAttribute('data-highlight-theme', 'true');
|
||||
|
||||
if (colorScheme === 'dark') {
|
||||
style.textContent = atomOneDarkTheme as string;
|
||||
} else {
|
||||
style.textContent = atomOneLightTheme as string;
|
||||
}
|
||||
|
||||
document.head.appendChild(style);
|
||||
|
||||
return () => {
|
||||
// Cleanup on unmount
|
||||
const stylesheet = document.querySelector('style[data-highlight-theme]');
|
||||
if (stylesheet) {
|
||||
stylesheet.remove();
|
||||
}
|
||||
};
|
||||
}, [colorScheme]);
|
||||
};
|
||||
5
app/src/types/css-inline.d.ts
vendored
Normal file
5
app/src/types/css-inline.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
// Type declarations for CSS imports with ?inline modifier
|
||||
declare module '*.css?inline' {
|
||||
const content: string;
|
||||
export default content;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -134,7 +134,7 @@ func setupRouter(o Options) *chi.Mux {
|
||||
r.Get("/lookup", handler.LookupFileByName())
|
||||
|
||||
r.Post("/upload", handler.UploadFile())
|
||||
r.Put("/move", handler.MoveFile())
|
||||
r.Post("/move", handler.MoveFile())
|
||||
|
||||
r.Post("/", handler.SaveFile())
|
||||
r.Get("/content", handler.GetFileContent())
|
||||
@@ -152,7 +152,9 @@ func setupRouter(o Options) *chi.Mux {
|
||||
})
|
||||
|
||||
// Handle all other routes with static file server
|
||||
r.Get("/*", handlers.NewStaticHandler(o.Config.StaticPath).ServeHTTP)
|
||||
staticHandler := handlers.NewStaticHandler(o.Config.StaticPath)
|
||||
r.Get("/*", staticHandler.ServeHTTP)
|
||||
r.Head("/*", staticHandler.ServeHTTP)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -410,7 +410,8 @@ func (h *Handler) UploadFile() http.HandlerFunc {
|
||||
}
|
||||
}()
|
||||
|
||||
filePath := decodedPath + "/" + formFile.Filename
|
||||
// Use filepath.Join to properly construct the path
|
||||
filePath := filepath.Join(decodedPath, formFile.Filename)
|
||||
|
||||
content, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
|
||||
@@ -156,6 +156,54 @@ func testFileHandlers(t *testing.T, dbConfig DatabaseConfig) {
|
||||
assert.Equal(t, http.StatusNotFound, rr.Code)
|
||||
})
|
||||
|
||||
t.Run("move file", func(t *testing.T) {
|
||||
srcPath := "original.md"
|
||||
destPath := "moved.md"
|
||||
content := "This file will be moved"
|
||||
|
||||
// Create file
|
||||
rr := h.makeRequestRaw(t, http.MethodPost, baseURL+"?file_path="+url.QueryEscape(srcPath), strings.NewReader(content), h.RegularTestUser)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
// Move file
|
||||
moveURL := baseURL + "/move?src_path=" + url.QueryEscape(srcPath) + "&dest_path=" + url.QueryEscape(destPath)
|
||||
rr = h.makeRequest(t, http.MethodPost, moveURL, nil, h.RegularTestUser)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
// Verify source is gone
|
||||
rr = h.makeRequest(t, http.MethodGet, baseURL+"/content?file_path="+url.QueryEscape(srcPath), nil, h.RegularTestUser)
|
||||
assert.Equal(t, http.StatusNotFound, rr.Code)
|
||||
|
||||
// Verify destination exists with correct content
|
||||
rr = h.makeRequest(t, http.MethodGet, baseURL+"/content?file_path="+url.QueryEscape(destPath), nil, h.RegularTestUser)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
assert.Equal(t, content, rr.Body.String())
|
||||
})
|
||||
|
||||
t.Run("rename file in directory", func(t *testing.T) {
|
||||
srcPath := "folder/old-name.md"
|
||||
destPath := "folder/new-name.md"
|
||||
content := "This file will be renamed"
|
||||
|
||||
// Create file
|
||||
rr := h.makeRequestRaw(t, http.MethodPost, baseURL+"?file_path="+url.QueryEscape(srcPath), strings.NewReader(content), h.RegularTestUser)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
// Rename file (move within same directory)
|
||||
moveURL := baseURL + "/move?src_path=" + url.QueryEscape(srcPath) + "&dest_path=" + url.QueryEscape(destPath)
|
||||
rr = h.makeRequest(t, http.MethodPost, moveURL, nil, h.RegularTestUser)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
// Verify source is gone
|
||||
rr = h.makeRequest(t, http.MethodGet, baseURL+"/content?file_path="+url.QueryEscape(srcPath), nil, h.RegularTestUser)
|
||||
assert.Equal(t, http.StatusNotFound, rr.Code)
|
||||
|
||||
// Verify destination exists with correct content
|
||||
rr = h.makeRequest(t, http.MethodGet, baseURL+"/content?file_path="+url.QueryEscape(destPath), nil, h.RegularTestUser)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
assert.Equal(t, content, rr.Body.String())
|
||||
})
|
||||
|
||||
t.Run("last opened file", func(t *testing.T) {
|
||||
// Initially should be empty
|
||||
rr := h.makeRequest(t, http.MethodGet, baseURL+"/last", nil, h.RegularTestUser)
|
||||
@@ -304,15 +352,6 @@ func testFileHandlers(t *testing.T, dbConfig DatabaseConfig) {
|
||||
assert.Equal(t, http.StatusBadRequest, rr.Code)
|
||||
})
|
||||
|
||||
t.Run("upload with missing file_path parameter", func(t *testing.T) {
|
||||
fileName := "test.txt"
|
||||
fileContent := "test content"
|
||||
files := map[string]string{fileName: fileContent}
|
||||
|
||||
rr := h.makeUploadRequest(t, baseURL+"/upload", files, h.RegularTestUser)
|
||||
assert.Equal(t, http.StatusBadRequest, rr.Code)
|
||||
})
|
||||
|
||||
t.Run("upload with invalid file_path", func(t *testing.T) {
|
||||
fileName := "test.txt"
|
||||
fileContent := "test content"
|
||||
|
||||
Reference in New Issue
Block a user