Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(share): render webviews using iframe
Elian Doran945f29c75933
diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.tsindex c830a92a25..5a61102c69 100644--- a/apps/server/src/share/content_renderer.ts+++ b/apps/server/src/share/content_renderer.ts@@ -18,6 +18,7 @@ import { highlightAuto } from "@triliumnext/highlightjs";import becca from "../becca/becca.js";import { BAttachment } from "../services/backend_script_entrypoint.js";import SAttachment from "./shaca/entities/sattachment.js";+import { sanitizeUrl } from "@braintree/sanitize-url";const shareAdjustedAssetPath = isDev ? assetPath : `../${assetPath}`;const templateCache: Map<string, string> = new Map();@@ -250,6 +251,8 @@ export function getContent(note: SNote | BNote) {renderFile(note, result);} else if (note.type === "book") {result.isEmpty = true;+ } else if (note.type === "webView") {+ renderWebView(note, result);} else {result.content = `<p>${t("content_renderer.note-cannot-be-displayed")}</p>`;}@@ -414,6 +417,13 @@ function renderFile(note: SNote | BNote, result: Result) {}}+function renderWebView(note: SNote | BNote, result: Result) {+ const url = note.getLabelValue("webViewSrc");+ if (!url) return;++ result.content = `<iframe class="webview" src="${sanitizeUrl(url)}"></iframe>`;+}+export default {getContent};diff --git a/packages/share-theme/src/styles/content.css b/packages/share-theme/src/styles/content.cssindex 47111f9785..07d691cb45 100644--- a/packages/share-theme/src/styles/content.css+++ b/packages/share-theme/src/styles/content.css@@ -52,4 +52,19 @@body:not(.math-loaded) .math-tex {visibility: hidden;+}++body.type-webView #main {+ max-width: unset;+}++body.type-webView #content {+ display: flex;+ flex-direction: column;+ height: 100%;+}++iframe.webview {+ width: 100%;+ flex-grow: 1;}\ No newline at end of file