Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

fix(edusharing-embed): Make link embeds visible #353

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/frontend/plugins/edusharing-asset/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export function EdusharingAssetRenderer(props: {
ltik: string
contentWidth: string | null
}) {
// Use default value for widthInPercent so that old content can be load
// where this property was not set
const { nodeId, repositoryId, ltik, contentWidth } = props

let [embedHtml, setEmbedHtml] = useState<string | null>(null)
Expand Down Expand Up @@ -107,6 +105,34 @@ export function EdusharingAssetRenderer(props: {
const parser = new DOMParser()
const htmlDocument = parser.parseFromString(detailsSnippet, 'text/html')

// Sadly, LearningApps also have `mediatype: 'link'` so we need to check more stuff here than just `mediatype`
const isLink =
content.node.mediatype === 'link' &&
!content.node.mimetype &&
content.node.repositoryType === 'ALFRESCO'
if (isLink) {
const linkElement = htmlDocument.querySelector<HTMLLinkElement>(
'.edusharing_rendering_content_footer a',
)
if (!linkElement) {
return {
html: '<div>Fehler beim Einbinden des Inhalts</div>',
renderMethod: 'dangerously-set-inner-html',
defineContainerHeight: false,
}
}

return {
html: `<a class="serlo-link" target="_blank" rel="noopener noreferrer" href="${
linkElement.href
}">${
linkElement.innerText ? linkElement.innerText : linkElement.href
}</a>`,
renderMethod: 'dangerously-set-inner-html',
defineContainerHeight: false,
}
}

const image = getImageOrUndefined(htmlDocument)

const isPixabayImage =
Expand Down
Loading