Skip to content

Rendering link Templates. #1796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions packages/malloy-render/src/html/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,32 @@ export class HTMLLinkRenderer implements Renderer {
return createNullElement(this.document);
}

const {tag} = data.field.tagParse();
const linkTag = tag.tag('link');

if (!linkTag) {
return createErrorElement(this.document, 'Missing tag for Link renderer');
}

if (!data.isString()) {
return createErrorElement(
this.document,
'Invalid type for link renderer.'
);
}

// if a URL template is provided, replace the data were '$$$' appears.
const urlTemplate = linkTag.text('url_template');

const element = this.document.createElement('a');
element.href = data.value;
if (urlTemplate) {
if (urlTemplate.indexOf('$$') > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to >-1

element.href = urlTemplate.replace('$$', data.value);
} else {
element.href = urlTemplate + data.value;
}
}
element.target = '_blank';
element.appendChild(
this.document.createTextNode(data.value.replace(/\//g, '/\u200C'))
Expand Down