-
Notifications
You must be signed in to change notification settings - Fork 0
LIF 612 - Add support for Flourish graphics #549
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
base: main
Are you sure you want to change the base?
Conversation
|
|
||
|
|
||
| if(isFlourishElement) { | ||
| const match = elementSrc.match(/\/visualisation\/(\d+)\//); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: What is the value of elementSrc?
Instead of Regex, we can use the built-in URL parser and then apply a focused regex only to the pathname. Regexes are fragile in case of matching with URL paths, as they will not cover the URL variations:
// Parse the URL
const urlObj = new URL(elementSrc);
| let isFlourishElement = false; | ||
| // identify flourish element | ||
| const elementSrc = el.getAttribute('src'); | ||
| if(elementSrc?.includes('public.flourish.studio/')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment/suggestion: I'll consider a more functional approach instead of imperative style when making changes in the DOM. We could simplify this to something like:
// Determine if it is a Flourish Element
const isFlourishElement = elementSrc?.includes('public.flourish.studio/');
// Determine image type
const imageType = isFlourishElement
? 'graphic'
: el.getAttribute('data-image-type');
This reduces multiple declarations and less to maintain.
| const RE_BAD_CHARS = /[^A-Za-z0-9_]/gm; | ||
| const RE_SPACE = /\s/gm; | ||
|
|
||
| function extractFourishEmbeds(contentHTMLBody) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: extractFlourishEmbeds
| const flourishEmbeds = []; | ||
| let match; | ||
|
|
||
| while ((match = flourishIdRegex.exec(contentHTMLBody)) !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: Regex.exec has a state inside it, explained here. Maybe we can use a simpler approach which doesn't involve any states.
Example:
for (const match of contentHTMLBody.matchAll(regex)) {
// match[1] will be captured ID I believe
ids2.push(match[1]);
}
Description
This PR introduces a temporary solution to support Flourish graphics in articles by ensuring they are included in the
content.embedsarray, even when not embedded.Ideally, Flourish graphics should be parsed and included in the
content.embedssection. Currently, they are not, which affects downstream rendering. This change bridges that gap until a more robust solution is implemented.Code changes
server/lib/enrich/article.jsserver/lib/builders/document-builder.jsremoveNonSyndicatableImagesto preserve Flourish content and prevent it from being removed inadvertently.Ticket
https://financialtimes.atlassian.net/browse/LIF-612