From 4bdd94cbf061790e1477d10eece4bf347b85739f Mon Sep 17 00:00:00 2001
From: Puetsua ` + p + ``;
};
- renderer.paragraph = (text) => {
- const split = text.split('\n');
- return split.reduce((acc, p, i) => {
- const result = /h(\d)\./.exec(p);
- if (result !== null) {
- const h = `h${result[1]}`;
- return acc + `<${h}>${p.replace(result[0], '')}${h}>`;
- }
-
- if (split.length === 1) {
- return `
` + p; - }, ''); - }; - // parse all RFC3986 URIs const urlPattern = /\b((([A-Za-z][A-Za-z0-9+.-]*):\/\/([^\/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?)\b/gi; const rendererTxtOld = renderer.text; - renderer.text = (text) => { - return rendererTxtOld( - text.replace(urlPattern, (url) => { - return `${url}`; - }), - ); + renderer.text = (token) => { + const textWithLinks = token.text.replace(urlPattern, (url) => { + return `${url}`; + }); + return rendererTxtOld({ ...token, text: textWithLinks }); }; const options: MarkedOptions = { @@ -116,12 +100,9 @@ export const markedOptionsFactory = (): MarkedOptions => { }; // Add preprocessing hook to handle image sizing syntax - // We need to provide all required hooks functions as stubs - (options as any).hooks = { - preprocess: preprocessMarkdown, - postprocess: (html: string) => html, - processAllTokens: (tokens: any[]) => tokens, - }; + const hooks = new Hooks(); + hooks.preprocess = preprocessMarkdown; + options.hooks = hooks; return options; }; diff --git a/src/main.ts b/src/main.ts index a1a3137504..5e5f5a1944 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,7 +19,7 @@ import { App as CapacitorApp } from '@capacitor/app'; import { GlobalErrorHandler } from './app/core/error-handler/global-error-handler.class'; import { bootstrapApplication, BrowserModule } from '@angular/platform-browser'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; -import { MarkdownModule, MARKED_OPTIONS, provideMarkdown } from 'ngx-markdown'; +import { MarkdownModule, MARKED_OPTIONS, SANITIZE, provideMarkdown } from 'ngx-markdown'; import { MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field'; import { FeatureStoresModule } from './app/root-store/feature-stores.module'; import { MATERIAL_ANIMATIONS, MatNativeDateModule } from '@angular/material/core'; @@ -90,7 +90,10 @@ bootstrapApplication(AppComponent, { }, // Don't sanitize in Electron - we trust local file:// URLs for clipboard images // In web, use HTML sanitization for security - sanitize: IS_ELECTRON ? SecurityContext.NONE : SecurityContext.HTML, + sanitize: { + provide: SANITIZE, + useValue: IS_ELECTRON ? SecurityContext.NONE : SecurityContext.HTML, + }, }), MaterialCssVarsModule.forRoot(), MatSidenavModule,