在 React 中将自定义 Typekit/Adobe 字体添加到 Tiny MCE
我正在尝试将自定义 Adobe Typekit 字体添加到 Tiny MCE React 组件中,以设置编辑器中文本的样式。我有以下内容:
<Editor
init={{
allow_html_in_named_anchor: false,
branding: false,
plugins: [
"autolink lists link image preview anchor",
"searchreplace",
"insertdatetime media table paste code"
],
toolbar: "bold italic | bullist numlist",
content_css: ["https://use.typekit.net/XXXXXX.css", "/overrides.css"]
}}
/>
我已删除 Typekit CSS 文件名,因为这是特定于帐户的。
overrides.css
文件如下所示:
@import url("https://use.typekit.net/XXXXX.css");
body {
font-family: "neue-haas-grotesk-text, Arial, sans-serif" !important;
font-size: 14px;
font-weight: 400;
}
TinyMCE 编辑器生成的 的
标签包含两个 CSS
标签按预期以正确的顺序:
<link rel="stylesheet" type="text/css" id="mce-u0" crossorigin="anonymous" referrerpolicy="origin" href="https://cdn.tiny.cloud/1/k9s4r4mdxeukqc7mrign93b26zofvznzyw98lj16y5rlb73z/tinymce/5.10.3-128/skins/ui/oxide/content.min.css">
<link rel="stylesheet" type="text/css" id="mce-u1" crossorigin="anonymous" referrerpolicy="origin" href="https://use.typekit.net/XXXXXX.css">
<link rel="stylesheet" type="text/css" id="mce-u0" crossorigin="anonymous" referrerpolicy="origin" href="https://cdn.tiny.cloud/1/k9s4r4mdxeukqc7mrign93b26zofvznzyw98lj16y5rlb73z/tinymce/5.10.3-128/skins/ui/oxide/content.min.css">
我尝试导入 CSS 两次,一次在 overrides.css
中,一次在 content_css
属性中。然而,什么都不起作用,我在编辑器中得到了一个奇怪的衬线字体(甚至不是 Arial 或默认的“sans-serif”)。
CSS 样式表加载正常,并且 Adobe 字体在编辑器所在的页面上工作,只是不在编辑器中编辑器预览本身。
I'm trying to add a custom Adobe Typekit font to a Tiny MCE React component to style the text in the editor. I have the following:
<Editor
init={{
allow_html_in_named_anchor: false,
branding: false,
plugins: [
"autolink lists link image preview anchor",
"searchreplace",
"insertdatetime media table paste code"
],
toolbar: "bold italic | bullist numlist",
content_css: ["https://use.typekit.net/XXXXXX.css", "/overrides.css"]
}}
/>
I've blanked out the Typekit CSS filename as this is account-specific.
The overrides.css
file looks like:
@import url("https://use.typekit.net/XXXXX.css");
body {
font-family: "neue-haas-grotesk-text, Arial, sans-serif" !important;
font-size: 14px;
font-weight: 400;
}
The <head>
tag of the TinyMCE editor generated <iframe>
contains two CSS <link>
tags as expected in the correct order:
<link rel="stylesheet" type="text/css" id="mce-u0" crossorigin="anonymous" referrerpolicy="origin" href="https://cdn.tiny.cloud/1/k9s4r4mdxeukqc7mrign93b26zofvznzyw98lj16y5rlb73z/tinymce/5.10.3-128/skins/ui/oxide/content.min.css">
<link rel="stylesheet" type="text/css" id="mce-u1" crossorigin="anonymous" referrerpolicy="origin" href="https://use.typekit.net/XXXXXX.css">
<link rel="stylesheet" type="text/css" id="mce-u0" crossorigin="anonymous" referrerpolicy="origin" href="https://cdn.tiny.cloud/1/k9s4r4mdxeukqc7mrign93b26zofvznzyw98lj16y5rlb73z/tinymce/5.10.3-128/skins/ui/oxide/content.min.css">
I've tried importing the CSS twice, once in overrides.css
and once in the content_css
property. However nothing is working, and I get a strange serif font in the editor (not even Arial or the default 'sans-serif'.
The CSS stylesheets load fine and the Adobe font is working on the page the editor is in, just not in the editor preview itself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个插件来加载该插件,
首先我们将启动插件:
然后,我们需要添加一个函数,该函数将添加一个将插入字体的脚本:
现在,我们将获得DOM对象(在函数内部):
创建一个脚本,然后我们将添加到标题:
插入字体到脚本:
将脚本添加到标题:
调用我们的函数:
所有内容:
我不确定我从哪里得到想法,但我很久以前就在代码中使用了它。
you need to create a plugin to load that,
first we will initiate the plugin:
then inside it we need to add a function that will add a script that will insert the fonts:
now, we'll get the DOM object (inside the function):
create a script that we will then add to the header:
insert font to script:
add script to header:
call our function:
everything together:
I'm not sure where i got the idea from, but I used it in my code a long time ago.