简体   繁体   English

如何使CKEditor删除线功能可访问?

[英]How to make CKEditor strikethrough functionality accessible?

Default strikethrough functionality of CKEditor works well and do what is logic, adding an "s" tag surrounding the text that has strikethrough (also I can make the editor use html5's "del" tag), the problem however, is that assistive reading technologies such as NVDA or JAWS do not read this kind of content in any way different from normal text without special settings. CKEditor的默认删除线功能可以很好地工作,并且可以执行逻辑操作,在带有删除线的文本周围添加“ s”标签(我也可以使编辑器使用html5的“ del”标签),但是问题是,辅助阅读技术因为NVDA或JAWS在没有特殊设置的情况下不会以不同于普通文本的任何方式读取此类内容。 What I'm trying to do is to add a span tag at the beginning and at the end of strikethrough text indicating this fact to the user: 我想做的是在删除线文本的开头和结尾添加一个span标记,以向用户指示这一事实:

<p>
    <span style="height: 1px; width: 1px; position: absolute; overflow: hidden; top: -10px;">Start strikethrough. </span>
    <s>Text with strikethrough</s>
    <span style="height: 1px; width: 1px; position: absolute; overflow: hidden; top: -10px;">End strikethrough. </span>
</p>

As you can see in this code the span is not visible in the page but the reader will follow dom order so the user will be alerted of the strikethrough. 如您在该代码中看到的那样,跨度在页面中不可见,但是阅读器将遵循dom顺序,因此将向用户提醒删除线。 I know you can build a plugin to insert any html but I have to make this work in the same way basic styles buttons work, with toggle feature: 我知道您可以构建一个插件来插入任何html,但是我必须以具有切换功能的基本样式按钮的工作方式来完成此工作:

  • The easy part: if there is a selection in the content and the button is pressed we have to strikethrough the content. 最简单的部分:如果内容中有一个选择并且按下了按钮,我们就必须删除内容。 This one is easier as we can get the selected html and surround it with what I want. 这一点比较容易,因为我们可以获取所选的html并用我想要的内容包围它。
  • The harder part: if there is no selection and the button is pressed then every text written next must have the strikethrough. 更难的部分:如果没有选择并且按下了按钮,那么接下来写的每个文本都必须带有删除线。

After lot of researching and analysing how the "real" plugin was made I came to something like this: 经过大量的研究和分析,“真正的”插件是如何制成的,我得出这样的结论:

CKEDITOR.plugins.add( 'customStrike', {
    icons: 'customStrike',
    init: function( editor ) {
        var style = new CKEDITOR.style( { element: 's' } );

        editor.attachStyleStateChange( style, function (state) {
            !editor.readOnly && editor.getCommand( 'customStrike').setState(state);
        } );

        editor.addCommand( 'customStrike', new CKEDITOR.styleCommand( style ) );

        if ( editor.ui.addButton ) {
            editor.ui.addButton( 'CustomStrike', {
                label: 'Strike Through',
                command: 'customStrike',
                toolbar: 'custom'
            } );
        }
    }
});

This works exactly as the real plugin, I tried to work around this code but the element property in the style defintion only accepts one tag as far as I know, I would need a way to nest tags using the element property to accomplish this. 这与真正的插件完全一样,我尝试解决此代码,但是就我所知,样式定义中的element属性仅接受一个标签,我需要一种使用element属性嵌套标签的方法来完成此操作。

Is there any way to solve this? 有什么办法解决这个问题?

Any help would be appreciated. 任何帮助,将不胜感激。

For me it looks like you're trying to fix the wrong end of the problem. 对我来说,您似乎正在尝试解决问题的错误原因。 It's readers' problem that they don't read the content differently. 读者的问题是他们没有以不同的方式阅读内容。 Clobbering the content may help for a while (although it will break the editing), but will be a problem when the readers are updated and start reading the content properly. 掩盖内容可能会帮助一段时间(尽管这会破坏编辑),但是在更新读者并开始正确阅读内容时会出现问题。

Anyway, if you insist on having some solution right now, then I have two advices: 无论如何,如果您现在坚持要一些解决方案,那么我有两个建议:

  • There may be some ARIA role or other attribute that you could set on the s/del tag which will somehow affect the readers. 您可以在s/del标记上设置一些ARIA角色或其他属性,这将以某种方式影响读者。
  • Do not clobber the content inside the editor, because you will break it. 不要破坏编辑器中的内容,因为这会破坏它。 You could for example process the content before sending it to the end user, if that's the part that you want to fix. 例如,您可以在将内容发送给最终用户之前对其进行处理(如果这是您要修复的部分)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM