/**
* MdxHtmlTools
*
* Utilities for loading dictionary entry HTML and applying templates.
* Height tracking and navigation handling are initialized via iframe onload in ContentItem.
*/
import { useSystemStore } from '../../store/useSystemStore';
/**
* Fetch content from a URL and return a complete HTML document string.
* Wraps the content in HTML structure. Height tracking is initialized via iframe onload.
*/
export const fetchContentFromUrl = async (
url: string
): Promise => {
try {
console.log('Fetching content from URL:', url);
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
// Determine how to handle response by content-type
const contentType = response.headers.get('content-type') || '';
let rawContent: string;
if (contentType.includes('text/html') || contentType.includes('text/plain')) {
rawContent = await response.text();
} else {
// For other content types, still try to interpret as text
rawContent = await response.text();
}
// Wrap content in basic HTML structure
// Initialization is handled via iframe onload in ContentItem
const wrappedContent = `
${rawContent}
`;
return wrappedContent;
} catch (error) {
console.error('Error fetching content from URL:', url, error);
throw error;
}
};
export const getIconUrl = (profileId: number): string => {
return `${useSystemStore.getState().baseUrl}mdd?profile_id=${profileId}&key=%2F$MdxDictIcon`;
};