0

我已将ckfinder集成到asp.net 的ckeditor中。

我有一个问题,当我将文件上传到 ckeditor 但链接生成并显示为

/Folder/files/ruby_on_rails_tutorial_2nd_edition.pdf

但我只想将文件名显示为链接,如ruby​​_on_rails_tutorial_2nd_edition.pdf

我怎样才能做到这一点。生成显示名称是否需要任何 ckeditor 或 ckfinder 配置。

4

1 回答 1

0

I would mark as Duplicate, but the target doesn't have an accepted answer. This is copied form my answer Here.

You can just delete that text manually. If you mean you do it automatically using the Link dialog, this hack should work:

Replace "editor1" with your editor name in the hack below or hack into whatever system you have after the CKE js has loaded. What it does is listens to dialogs closing, when it sees that the link dialog is being hidden and that the current selection begins with an <a...> link, it takes the contents of said link and cuts it from the final slash.

var editor = CKEDITOR.instances.editor1;

editor.on('dialogHide', function(e) {
    if(e.data.getName() === "link") {
        var sel = editor.getSelection();
        var se = sel.getStartElement();
        var text = se.getText();
        if(se.getName() === "a") {
            var newtext = text.slice(text.lastIndexOf('/')+1);
            se.setText(newtext);
        }
    }     
});

It's complicated and disgusting but seems to work. Be warned, I have not tested this if it breaks anything else like anchoring. More checks would be better, like checking if newtext actually gets a value > 1 and only then replacing.

于 2013-10-23T10:36:16.833 回答