Add markdown support for script/category names

Add markdown rendering for script and category titles to improve the
presentation of textual content.

- Introduce reusable `MarkdownText` for markdown rendering.
- Incorporate markdown styling into dedicated SCSS file for clarity.
- Define explicit font sizes for consistent visual experience.
- Apply `MarkdownText` usage across UI for unified markdown rendering.
- Streamline related styles and layout for improved maintainability
- Set font sizes explicitly for better consistency and to avoid
  unexpected inheritence.

This enhancement enables richer text formatting and improves the user
interface's flexibility in displaying content.
This commit is contained in:
undergroundwires
2024-01-30 16:36:55 +01:00
parent 6ab6dacd1b
commit a5ffed4cd6
10 changed files with 259 additions and 183 deletions

View File

@@ -0,0 +1,55 @@
import { describe, it, expect } from 'vitest';
import { parseApplication } from '@/application/Parser/ApplicationParser';
import { OperatingSystem } from '@/domain/OperatingSystem';
import { createMarkdownRenderer } from '@/presentation/components/Scripts/View/Tree/NodeContent/Markdown/MarkdownRenderer';
describe('MarkdownRenderer', () => {
describe('can render all docs', () => {
// arrange
const renderer = createMarkdownRenderer();
for (const node of collectAllDocumentableNodes()) {
it(`${node.nodeLabel}`, () => {
// act
const html = renderer.render(node.docs);
const result = validateHtml(html);
// assert
expect(result.isValid, result.generatedHtml);
});
}
});
});
interface IDocumentableNode {
readonly nodeLabel: string
readonly docs: string
}
function* collectAllDocumentableNodes(): Generator<IDocumentableNode> {
const app = parseApplication();
for (const collection of app.collections) {
const documentableNodes = [
...collection.getAllScripts(),
...collection.getAllCategories(),
];
for (const node of documentableNodes) {
const documentable: IDocumentableNode = {
nodeLabel: `${OperatingSystem[collection.os]} | ${node.name} (${node.id})`,
docs: node.docs.join('\n'),
};
yield documentable;
}
}
}
interface IHTMLValidationResult {
readonly isValid: boolean;
readonly generatedHtml: string;
}
function validateHtml(value: string): IHTMLValidationResult {
const doc = new window.DOMParser()
.parseFromString(value, 'text/html');
return {
isValid: Array.from(doc.body.childNodes).some((node) => node.nodeType === 1),
generatedHtml: doc.body.innerHTML,
};
}