禁用 TinyMCE 绝对 URL 到相对 URL 转换

发布于 2024-10-20 11:46:57 字数 529 浏览 6 评论 0原文

谁能告诉我如何让 TinyMCE 停止将我的 URL 转换为 Plone 中的相对链接?

例如,如果我在 HTML 源中输入:

<img src="/images/dir/subdir/my_image.png" />

它会将其转换为:

<img src="../../../my_image.png" />

我已编辑tiny_mce.js(在portal_skins 中)以设置:

convert_urls:false,
relative_urls:false,

但没有效果。我在这里阅读了所有类似的帖子,但没有一个真正回答这个问题。

当用户通过浏览文件系统(即目录)选择图像时,如果它执行相关的操作,那就没问题了。我只是希望它尊重我在 html 框中输入的内容...这样我就可以选择强制使用绝对路径(如果我认为合适)。这是 kupu 中的标准行为。

有什么想法吗?

Can anyone tell me how to get TinyMCE to stop converting my URLs to relative links in Plone?

For example, if I enter this in the HTML source:

<img src="/images/dir/subdir/my_image.png" />

it will convert it to:

<img src="../../../my_image.png" />

I've edited tiny_mce.js (in portal_skins) to set:

convert_urls:false,
relative_urls:false,

but to no effect. I've read all similar posts here, but none really answer this question.

It's fine if it does the relative thing when users are picking images by browsing the filesystem (i.e. the catalog). I just want it to respect what I type in the html box ... so that I have the option of forcing an absolute path if I deem it appropriate. This is the standard behavior in kupu.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

抚你发端 2024-10-27 11:46:57

在tiny_mce_init.js而不是tiny_mce.js中设置convert_urls: false。在tiny_mce_init.js的早期,您会看到对window.tinyMCE.init的调用传递了一堆初始化选项。在我正在查看的 Products.TinyMCE 中,最后一个选项是 fix_list_elements: false。在那里添加您的选项。

编辑:Products.TinyMCE 1.3.x (Plone 4.3) 中不再使用tiny_mce_init.js。相反,覆盖 tinymce-jsonconfiguration 浏览器视图,例如:

假设您有一个带有浏览器层的包,请添加 browser/configure.zcml

<browser:page
    for="*"
    name="tinymce-jsonconfiguration"
    class=".tinymce.TinyMCEBrowserView"
    permission="zope2.View"
    attribute="jsonConfiguration"
    layer="..interfaces.IMyBrowserLayer"
    />

然后添加 browser /tinymce.py

try:
    import simplejson as json
except ImportError:
    import json

from Acquisition import aq_inner
from Products.CMFCore.utils import getToolByName
from Products.TinyMCE.browser.browser import TinyMCEBrowserView as View
from Products.TinyMCE.browser.interfaces.browser import ITinyMCEBrowserView
from zope.interface import implements


class TinyMCEBrowserView(View):
    implements(ITinyMCEBrowserView)

    def jsonConfiguration(self, field):
        """Return the configuration in JSON"""

        utility = getToolByName(aq_inner(self.context), 'portal_tinymce')
        config = utility.getConfiguration(context=self.context,
                                          field=field,
                                          request=self.request)
        config['convert_urls'] = False
        return json.dumps(config)

Set convert_urls: false in tiny_mce_init.js, not tiny_mce.js. Early in tiny_mce_init.js you'll see a call to window.tinyMCE.init passing a bunch of initialisation options. In the Products.TinyMCE I'm looking at, the last option is fix_list_elements: false. Add your option there.

Edit: tiny_mce_init.js is no longer used in Products.TinyMCE 1.3.x (Plone 4.3). Instead, override the tinymce-jsonconfiguration browser view, e.g.:

Assuming you have a package with a browser layer, add in browser/configure.zcml:

<browser:page
    for="*"
    name="tinymce-jsonconfiguration"
    class=".tinymce.TinyMCEBrowserView"
    permission="zope2.View"
    attribute="jsonConfiguration"
    layer="..interfaces.IMyBrowserLayer"
    />

Then add browser/tinymce.py:

try:
    import simplejson as json
except ImportError:
    import json

from Acquisition import aq_inner
from Products.CMFCore.utils import getToolByName
from Products.TinyMCE.browser.browser import TinyMCEBrowserView as View
from Products.TinyMCE.browser.interfaces.browser import ITinyMCEBrowserView
from zope.interface import implements


class TinyMCEBrowserView(View):
    implements(ITinyMCEBrowserView)

    def jsonConfiguration(self, field):
        """Return the configuration in JSON"""

        utility = getToolByName(aq_inner(self.context), 'portal_tinymce')
        config = utility.getConfiguration(context=self.context,
                                          field=field,
                                          request=self.request)
        config['convert_urls'] = False
        return json.dumps(config)
峩卟喜欢 2024-10-27 11:46:57

您应该将这些配置添加到tinymce.init中:

  • relative_urls: false,

  • convert_urls:假,

  • remove_script_host:假,

参考:https://www.tiny .cloud/docs/configure/url-handling/

You should add these configs into tinymce.init:

  • relative_urls: false,

  • convert_urls: false,

  • remove_script_host : false,

ref: https://www.tiny.cloud/docs/configure/url-handling/

终止放荡 2024-10-27 11:46:57

另一种解决方案是使用控制面板配置 TinyMCE,为每个链接和图像使用 UID,而不是路径,这样您就不会修改任何现有的 javascript,也不会显示任何相对 url。

An other solution is to configure TinyMCE with the control panel to use UID for every links and images, instead of path, so you don't modify any existing javascripts and don't have any relative url displayed.

错爱 2024-10-27 11:46:57

在 Plone 5 中,可以禁用 TinyMCE 绝对 URL 到相对 URL,在 TinyMCE 设置的“高级”选项卡中添加变量

站点设置 > TinyMCE>高级

{"relative_urls": false, "convert_urls": false, "remove_script_host": false}

更多变量可在 Products/CMFPlone/static/components/tinymce-builded/js/tinymce/tinymce.js 中找到

...
popup_css: '',
plugins: '',
document_base_url: documentBaseUrl,
add_form_submit_trigger: true,
submit_patch: true,
add_unload_trigger: true,
convert_urls: true,
relative_urls: true,
remove_script_host: true,
object_resizing: true,
...

In Plone 5 is possible disable TinyMCE absolute to relative URL adding variables in Advanced tab of TinyMCE Settings

Site setup > TinyMCE > Advaced

{"relative_urls": false, "convert_urls": false, "remove_script_host": false}

Further variables are available in Products/CMFPlone/static/components/tinymce-builded/js/tinymce/tinymce.js

...
popup_css: '',
plugins: '',
document_base_url: documentBaseUrl,
add_form_submit_trigger: true,
submit_patch: true,
add_unload_trigger: true,
convert_urls: true,
relative_urls: true,
remove_script_host: true,
object_resizing: true,
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文