Patch Squidex Markdown editor image src paths to render as paths within our app.
This commit is contained in:
parent
f7f147cfc1
commit
1ce08dbe40
|
@ -78,8 +78,8 @@ export const getWebhookPort = () => env.WEBHOOK_PORT ? parseInt(env.WEBHOOK_PORT
|
|||
export const getSquidexAppName = () => env.SQUIDEX_APP_NAME || undefined;
|
||||
export const getSquidexClientId = () => env.SQUIDEX_CLIENT_ID || undefined;
|
||||
export const getSquidexClientSecret = () => env.SQUIDEX_CLIENT_SECRET || undefined;
|
||||
export const getSquidexEnvironment = () => env.SQUIDEX_ENVIRONMENT || undefined;
|
||||
export const getSquidexPublicUrl = () => env.SQUIDEX_PUBLIC_URL || getSquidexEnvironment();
|
||||
export const getSquidexEnvironment = () => trimSlashes(env.SQUIDEX_ENVIRONMENT||'') || undefined;
|
||||
export const getSquidexPublicUrl = () => trimSlashes(env.SQUIDEX_PUBLIC_URL||'') || getSquidexEnvironment();
|
||||
|
||||
export const config: Config = {
|
||||
// AmazonProductAdvertisingAPIAccessKey: getAmazonProductAdvertisingAPIAccessKey(),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import markdownIt from "markdown-it";
|
||||
import markdownItAttrs from "markdown-it-attrs";
|
||||
import vm from 'node:vm';
|
||||
import { config } from "../config";
|
||||
|
||||
export const md = markdownIt().use(markdownItAttrs, {
|
||||
});
|
||||
|
@ -67,9 +68,15 @@ const renderCodeblock = (lang: string, template: string, templateContext?: any)
|
|||
return template;
|
||||
}
|
||||
|
||||
const replaceSquidexAssetPathWithOwn = (html: string) => {
|
||||
let re = new RegExp(`src\\s*=\\s*["']${config.squidexPublicUrl?.replaceAll(`/`, `\\/`).replaceAll(`.`, `\\.`)||''}\\/api\\/assets/${config.squidexAppName||''}/([\\w-\\.\\/]*)["']`, 'g');
|
||||
return html.replaceAll(re, `src="${config.siteUrl}/img/$1"`);
|
||||
}
|
||||
|
||||
export const renderMarkdown = (template: string, templateContext?: any) => {
|
||||
// render code blocks inside of the Markdown
|
||||
template = renderCodeblock('markdown', template, templateContext);
|
||||
template = md.render(interpolateString(template, templateContext));
|
||||
template = replaceSquidexAssetPathWithOwn(template);
|
||||
return template;
|
||||
}
|
Loading…
Reference in New Issue
Block a user