I am using Rails 7.0.6 and Ruby 3.1.4p223
I am trying to email a PDF file to the user with a ToastUI markdown viewer.
email.pdf.erb
<head>
<%= wicked_pdf_stylesheet_link_tag "application" %>
<%= wicked_pdf_stylesheet_link_tag "bootstrap" %>
<link rel="stylesheet" href="https://uicdn.toast.com/tui-editor/latest/tui-editor.css">
<link rel="stylesheet" href="https://uicdn.toast.com/tui-editor/latest/tui-editor-contents.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://uicdn.toast.com/tui-editor/latest/tui-editor-Editor-full.js"></script>
</head>
<page>
<div class="markdownViewSection" data-content="<%= @department.description %>"></div>
</page>
<script>
$(document).ready(function() {
if($('.markdownViewSection').length > 0){
$.each($('.markdownViewSection'), function(index, el) {
// Ensure tui.Editor is defined and loaded correctly
if (typeof tui.Editor.factory === "function") {
try {
var editor = new tui.Editor.factory({
el: el,
initialEditType: 'wysiwyg',
previewStyle: 'vertical',
exts: ['table'],
initialValue: $(el).data('content')
});
// Continue with any further code related to the editor
} catch (error) {
$(".markdownViewSection").text(error);
}
} else {
$(".markdownViewSection").text(typeof tui.Editor);
}
});
}
});
</script>
After trying to open the email using letter_opener, I am getting tui.Editor.factory is undefined and tui.Editor is an object.
In my Department Edit page, tui.editor is a function. I use the same script and it's rendering bullet points and tables.
I am assuming there is something wrong in loading tui-editor-full cdn.
Can anyone please help on how to properly load ToastUI into a pdf.erb file?
I tried loading the toastUI by cdn and it still didn't work. I got an object instead of a function.