Skip to content

Commit a66701c

Browse files
Merge pull request #111 from ThisIs-Developer/audit-fixes
Audit fixes
2 parents 64c6f08 + 8531b85 commit a66701c

3 files changed

Lines changed: 159 additions & 4 deletions

File tree

desktop-app/resources/js/script.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4295,8 +4295,9 @@ This is a fully client-side application. Your content never leaves your browser
42954295

42964296
exportHtml.addEventListener("click", function () {
42974297
try {
4298-
const markdown = markdownEditor.value;
4299-
const html = marked.parse(markdown);
4298+
const { frontmatter, body } = parseFrontmatter(markdownEditor.value);
4299+
const tableHtml = frontmatter ? renderFrontmatterTable(frontmatter) : '';
4300+
const html = tableHtml + marked.parse(body);
43004301
const sanitizedHtml = DOMPurify.sanitize(html, {
43014302
ADD_TAGS: ['mjx-container', 'input'],
43024303
ADD_ATTR: ['id', 'class', 'style', 'align', 'type', 'checked', 'disabled']
@@ -4395,6 +4396,24 @@ This is a fully client-side application. Your content never leaves your browser
43954396
.markdown-alert-caution { color: ${isDarkTheme ? "#f85149" : "#cf222e"}; border-left-color: ${isDarkTheme ? "#f85149" : "#cf222e"}; background-color: ${isDarkTheme ? "rgba(248, 81, 73, 0.18)" : "#ffebe9"}; }
43964397
.markdown-alert > *:not(.markdown-alert-title) { color: ${isDarkTheme ? "#c9d1d9" : "#24292e"}; }
43974398
4399+
.frontmatter-table {
4400+
width: 100%;
4401+
border-collapse: collapse;
4402+
margin-bottom: 24px;
4403+
font-size: 14px;
4404+
}
4405+
.frontmatter-table th,
4406+
.frontmatter-table td {
4407+
border: 1px solid ${isDarkTheme ? "#30363d" : "#e1e4e8"};
4408+
padding: 8px 12px;
4409+
text-align: left;
4410+
}
4411+
.frontmatter-table th {
4412+
font-weight: 600;
4413+
background-color: ${isDarkTheme ? "#161b22" : "#f6f8fa"};
4414+
width: 150px;
4415+
}
4416+
43984417
@media (max-width: 767px) {
43994418
.markdown-body {
44004419
padding: 15px;

script.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4295,8 +4295,9 @@ This is a fully client-side application. Your content never leaves your browser
42954295

42964296
exportHtml.addEventListener("click", function () {
42974297
try {
4298-
const markdown = markdownEditor.value;
4299-
const html = marked.parse(markdown);
4298+
const { frontmatter, body } = parseFrontmatter(markdownEditor.value);
4299+
const tableHtml = frontmatter ? renderFrontmatterTable(frontmatter) : '';
4300+
const html = tableHtml + marked.parse(body);
43004301
const sanitizedHtml = DOMPurify.sanitize(html, {
43014302
ADD_TAGS: ['mjx-container', 'input'],
43024303
ADD_ATTR: ['id', 'class', 'style', 'align', 'type', 'checked', 'disabled']
@@ -4395,6 +4396,24 @@ This is a fully client-side application. Your content never leaves your browser
43954396
.markdown-alert-caution { color: ${isDarkTheme ? "#f85149" : "#cf222e"}; border-left-color: ${isDarkTheme ? "#f85149" : "#cf222e"}; background-color: ${isDarkTheme ? "rgba(248, 81, 73, 0.18)" : "#ffebe9"}; }
43964397
.markdown-alert > *:not(.markdown-alert-title) { color: ${isDarkTheme ? "#c9d1d9" : "#24292e"}; }
43974398
4399+
.frontmatter-table {
4400+
width: 100%;
4401+
border-collapse: collapse;
4402+
margin-bottom: 24px;
4403+
font-size: 14px;
4404+
}
4405+
.frontmatter-table th,
4406+
.frontmatter-table td {
4407+
border: 1px solid ${isDarkTheme ? "#30363d" : "#e1e4e8"};
4408+
padding: 8px 12px;
4409+
text-align: left;
4410+
}
4411+
.frontmatter-table th {
4412+
font-weight: 600;
4413+
background-color: ${isDarkTheme ? "#161b22" : "#f6f8fa"};
4414+
width: 150px;
4415+
}
4416+
43984417
@media (max-width: 767px) {
43994418
.markdown-body {
44004419
padding: 15px;

test.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
document_type: Technical Test Suite
3+
version: 1.0.0
4+
last_updated: 2026-05-24
5+
audited_by: Antigravity Codebase Auditor Swarm
6+
status: Fixed & Verified
7+
---
8+
9+
# Markdown Viewer Verification & Test Suite
10+
11+
This document is a comprehensive test suite designed to verify that the Markdown Viewer renders all standard and custom extensions correctly in the live preview and exports cleanly to standalone HTML and PDF formats.
12+
13+
---
14+
15+
## 1. YAML Frontmatter Verification (Fixes #109)
16+
*The table below is rendered from the YAML frontmatter block at the very top of this document. It must render correctly in both the live preview pane and the exported HTML/PDF documents.*
17+
18+
- **Expected Behavior:** A styled metadata table containing headers (`document_type`, `version`, `last_updated`, `status`) must appear at the absolute top of the document.
19+
- **Verification:** Export this document to HTML and check if the metadata table is styled with borders and clean background rows.
20+
21+
---
22+
23+
## 2. Mermaid Diagram rendering (XSS & Operator Escaping Fixes)
24+
*This section tests if the Mermaid parser compiles flowcharts correctly without HTML-mangling when dealing with mathematical comparison operators like `<` or `>`.*
25+
26+
```mermaid
27+
graph TD
28+
Start([Initialize App]) --> Parse{Parse YAML Frontmatter}
29+
Parse -- Case 1: x < 5 --> RenderTable[Render Metadata Table]
30+
Parse -- Case 2: y >= 10 --> RenderMarkdown[Render GFM Body]
31+
RenderTable --> Compile[Compile Standalone HTML]
32+
RenderMarkdown --> Compile
33+
Compile --> Success((Verify Layout))
34+
```
35+
36+
- **Expected Behavior:** A flowchart displaying the rendering pipeline must compile visually in the preview panel. The comparison texts `x < 5` and `y >= 10` must display correctly without causing syntax rendering errors.
37+
- **Security Check:** Inline script elements inside Mermaid labels are strictly blocked by setting `securityLevel: 'strict'`.
38+
39+
---
40+
41+
## 3. Mathematical Formulations (LaTeX & MathJax Delimiters)
42+
*This section tests that inline and block mathematical typesetting engines compile correctly without colliding with standard inline currency symbols.*
43+
44+
### Inline Math Test
45+
The Pythagorean theorem is expressed as $a^2 + b^2 = c^2$.
46+
47+
### Block Math Test
48+
The Gaussian distribution probability density function is represented as:
49+
50+
$$f(x \mid \mu, \sigma^2) = \frac{1}{\sigma \sqrt{2\pi}} e^{-\frac{(x - \mu)^2}{2\sigma^2}}$$
51+
52+
### Currency Delimiter Collision Test
53+
*Standard currency symbols must NOT compile as LaTeX equations:*
54+
- I bought this book for $5 and that markdown guide for $10. (Should render as standard text with raw dollar signs).
55+
56+
---
57+
58+
## 4. GitHub-Style Admonitions / Alerts
59+
*This section verifies that GFM alert blocks render with matching accent colors, border highlights, and icons.*
60+
61+
> [!NOTE]
62+
> This is a standard blue note alert. It provides general background information.
63+
64+
> [!TIP]
65+
> This is a green tip alert. It highlights optimizations or recommended paths.
66+
67+
> [!IMPORTANT]
68+
> This is a purple important alert. It documents essential steps.
69+
70+
> [!WARNING]
71+
> This is a yellow warning alert. It warns of potential compatibility risks.
72+
73+
> [!CAUTION]
74+
> This is a red caution alert. It flags high-risk data-loss actions.
75+
76+
---
77+
78+
## 5. Standard GitHub-Flavored Markdown (GFM)
79+
80+
### Syntax Highlighting (highlight.js)
81+
```javascript
82+
// Verification script for startup files
83+
(async function verifyStartup() {
84+
const isDesktop = typeof Neutralino !== 'undefined';
85+
if (isDesktop && window.NL_INITIAL_FILE_CONTENT) {
86+
console.log("Startup file loaded successfully:", window.NL_INITIAL_FILE_CONTENT.name);
87+
}
88+
})();
89+
```
90+
91+
### Task Lists / Checklists
92+
- [x] Fixed startup double-click race condition
93+
- [x] Standardized modals with focus traps
94+
- [x] Enabled case-insensitive drag-and-drop matches
95+
- [ ] Implement incremental Mermaid rendering cache (Future)
96+
97+
### Tables
98+
| Component | Status | Verification Link |
99+
| :--- | :--- | :--- |
100+
| Dynamic Tabs | **Fixed** | [Tab Bar](#1-yaml-frontmatter-verification-fixes-109) |
101+
| Pane Resizer | **Fixed** | [Resizer Separator](#) |
102+
| Math Equations | **Fixed** | [LaTeX block](#3-mathematical-formulations-latex--mathjax-delimiters) |
103+
104+
---
105+
106+
## 6. Custom Markdown Extensions
107+
108+
### Footnotes
109+
Here is a simple footnote reference[^1] and a second complex one[^2].
110+
111+
[^1]: This is the first standard footnote text.
112+
[^2]: This is the second footnote containing *styled markdown* and a backlink.
113+
114+
### Subscripts, Superscripts, and Highlights
115+
- Water is H~2~O.
116+
- The Einstein equation is E=mc^2^.
117+
- Highly critical text must be ==highlighted in yellow== for scannability.

0 commit comments

Comments
 (0)