编辑器不支持section html,小程序富文本编辑器editor初体验

终于,微信在5月9号的 v2.7.0 版本中新增了 editor富文本编辑器组件,今天有时间了准备体验一下

在5月6日的时候写了一篇 小程序富文本解析的「伪需求」,从wxParse到towxml的坑 ,当时还在感慨官方什么时候出个比较全面的富文本组件,谁知道没几天就发布了 editor 富文本组件。

d8ca4d8be773288883c829b2aede9cbc.png

熟悉下文档

首先是兼容版本,最低要求 2.7.0 ,使用时确认下开发 工具 的调试基础库。

e0eceebde11f0834e4371dc6f904fe73.png

然后需要关注下目前支持的标签,从目前公众号排版出来的文章的样式还是比较复杂的,总觉得目前的富文本编辑器不一定全部支持「我的猜测还是正确的」

从文档上看目前支持的标签数不是很多,但常用的基本都在里面了。

792fdaabba6154dc82c65ab4625b7398.png

初尝试

使用还是比较简单的,官方的文档已经表述的比较清楚了,直接在 wxml 中引入组件

id="editor"

class="ql-container"

placeholder="{{placeholder}}"

showImgSize

showImgToolbar

showImgResize

bindstatuschange="onStatusChange"

read-only="{{readOnly}}"

bindready="onEditorReady">

然后在js中对组件进行初始化即可。

onEditorReady() {

const that = this

wx.createSelectorQuery().select('#editor').context(function (res) {

that.editorCtx = res.context

}).exec()

},

具体也可以直接下载官方的demo,可以直接在开发工具中运行,还是比较简单的。

b68216cd26b061618eee235c73008434.png

结合我的博客小程序

最后就想尝试下,我的博客小程序中是否可以将 towxml 替换成 editor ,毕竟 towxml 太大了。

实现也比较简单,获取文章详情后,利用 setContents 来给富文本赋值,先写了一个简单的demo,核心代码如下:

/**

* 初始化富文本框

*/

onEditorReady:async function() {

const that = this

wx.createSelectorQuery().select('#editor').context(function (res) {

that.editorCtx = res.context

}).exec()

let result=await api.getPostsById('ee3099285ccee97e0ca03888750d4603')

console.info(result.data)

that.editorCtx.setContents({

html:result.data.content,

success: (res)=> {

console.log(res)

},

fail:(res)=> {

console.log(res)

}

})

},

运行后发现,一片空白,但看了日志数据已经获取成功,调用 setContents 方法也是成功的。

b72210f79e5fe0127744c452c62808ff.png

首先确认下代码是否有问题,将 html 赋值的地方写死固定的字符串,运行后发现是可以渲染成功的,证明代码应该没问题。

在确认代码确实无问题之后,优先想到的是开发工具是不是也要更新成最新版,检查更新之后发现确实有最新版,于是更新了下开发工具。

可遗憾的是即使更新到最新的版本,依旧无法显示,但神奇的是,利用手机预览是可以渲染成功的。

ddc0ec839692da3af1506e5d425c571f.png

可还是比较遗憾,渲染出来的效果不是特别理想,原因还是因为部分标签不支持的缘故。

这里简单看了下样式出现问题的html代码,比如截图中的 使用教程 标题没有居中且颜色也不是原来的红色。

使用教程

/section>

代码中是使,用 section 标签来进行渲染的,可目前 editor 应该还不支持。

同样的,对于文章中的代码块的样式渲染也不是很理想,原因与上面一样,不支持 code 标签。

总结

editor 富文本编辑器还是基本能满足需求的,但对于从第三方生成的复杂的 html 文本,支持的不是很完美。

就目前来看,目前还不能替换 towxml 组件,期待 editor 后续的更新吧。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Great Cow BASIC 0.98.02 老朽痴拙汉化版(大母牛BASIC)是一个8位芯片PIC和Atmel AVR微控制器的开放源码的BASIC编辑器。 在项目中还包括 Great Cow Graphical BASIC(大母牛图形化BASIC), 是一个基于GCASIC程序的图形化编辑器. 最新版本是2018年5月,甚至快要接近V1.00 版本!! 添加的新的功能,使Great Cow BASIC具备最简单方便的工具集-这些工具使用有趣和简单,支持超过1000个微控制器。 有关选项请参阅下载部分。那里有一个图形化的IDE 和文本IDE, 有一个编译器和最小的安装-任由你的选择。 功能特点: - 完整融合的 Great Cow BASIC编译器 - 编译器调用可通过bat批文件进行配置 - SynWrite 编辑器 - 语法高亮显示 - 代码折叠 - 子程序/函数列表 - 自动完成 - 上下文相关帮助 (F1) - 多文件选项卡 - 书签 - 双击错误编译产生源代码行 - oneclick组装/编译/闪存单片机 (F5, F6, F7, F8) - 终端由 Br@y ++ - PICpgm 和 WinPicPgm 编程软件。对于其他编程支持PicPgms 配置(pgmifcfg), 请参见 http://www.franksteinberg.de/#Mikrocontroller - 通过从微芯片中添加 pk2cmd 来实现简单的PicKit2支持 - 微芯片IPE自动化工具(...\GCB@Syn\PicKit3\IPE-Pusher.exe) - 编程-软件可通过GUI进行配置Programmer Editor - AVRdude 和 AVRdude-GUI 工具版本: - SynWrite 6.22.2290 - PPS Tool version: 0.0.5.3 - XpressLoade..exe 1.0.5.954.41244 - Putty.exe 0.63.0.0 - Terminal.exe v.19b 2013116b - TinyMultiBootloader+.exe 0.11.1.9 - WinPICgm.exe 1.9.2.5 - PK3 Gui v3.10 - IPE-Pusher.exe 3.1.1.0 - PK2 Gui v2.61.0.0 - PK2Cmd.exe v1.20 - Micronucleus.exe 2.0a4 - avrdudess.exe 2.4.6123.39693 - avrdude.exe v6.3 操作方法: -只需启动 IDE.exe -当Great Cow Basic 打开源文件时,观察工具栏。通过按钮也可尝试右键按钮,访问oneclick命令。 -通过单击工具栏上的 "GCBasic" 自定义编程软件;然后 "编辑编程首选项"。选择 "编程" 选项卡并拖/放 你的编程在上面。 -使用 "编辑..." 按钮调整编程设置。 -如果没有预安装的适合编程, 您可以添加自己的。 -如果有一个bat批处理 "FlashThis.bat"出现在与源文件相同的文件夹中,则此bat批处理文件会闪烁。 这可能对特定项目的闪烁很有用。 请查看主页: http://gcbasic.sourceforge.net 请查看其他下载选项: http://gcbasic.sourceforge.net/download.html 请查看大母牛BASIC帮助: http://gcbasic.sourceforge.net/help/ Great Cow BASIC is an open-source BASIC compiler for 8 bit Microchip PIC and Atmel AVR microcontrollers. Also included in the project is Great Cow Graphical BASIC, an icon based editor for GCBASIC programs. The latest release is May 2018. We are even closer to v1.00 release!! We have added new capabilities that make Great Cow BASIC the easiest tool set available - supporting over 1000's microcontrollers with tools to make this fun and simple. Please see the download section for your options. We have a Graphical IDE and textual IDE, we have just the compiler and we have a minimal install - it is your choice. Please see the homepage here: http://gcbasic.sourceforge.net and also see http://gcbasic.sourceforge.net/download.html for other Great Cow Basic download options. Great Cow BASIC Help http://gcbasic.sourceforge.net/help/
<br/>CuteEditor功能特点 <br/>是什么使CuteEditor成为Html在线编辑器的领航者?除了其强大的功能和方便的使用, 这里还有一些顶尖的技术因素是CuteEditor编辑器成为你编辑和发布Web内容的最佳选择: <br/> 界面简洁加载速度快 <br/><br/>由于才有了很多优化方法,所以CuteEditor非常简单、小巧、装载速度快,但仍然保持功能强大、执行效率高的特点。 <br/> <br/> 跨浏览器,跨平台的所见即所得在线html编辑器 <br/><br/>兼容市面上最流行的ie5.5+,firefox1.0+,mozilla1.3+, netscape7+和Safari(1.3+)浏览器,并且包括Mac和Linux操作平台。 <br/> <br/> CuteEditor遵循Web标准,没有类似 <FONT> 这种标签 <br/><br/>你的Html编辑器还在使用类似 <FONT>这种标签么? CuteEditor会帮助你构建用户最新Web标准的html代码标签,自动生成简洁的HTML/XHTML代码。 为什么要遵循Web标准? <br/><br/>学习应用Web标准有很多益处,下面给几个简单例子:<br/><br/>获得好的搜索引擎排名: The separation of content and presentation makes the content represent a larger part of the total file size. Combined with semantic markup this will improve search engine rankings. <br/>更快的下载和加载网页: Less HTML results in smaller file sizes and quicker downloads. Modern web browsers render pages faster when they are in their standards mode than when they are in their backwards compatible mode. <br/>适应未来网页浏览器: When you use defined standards and valid code you future-proof your documents by reducing the risk of future web browsers not being able to understand the code you have used. <br/>代码编写简单,维护方便: Using more semantic and structured HTML makes it easier and quicker to understand code created by somebody else. <br/>适应其他设备: Semantic HTML, where structure is separated from presentation, makes it easier for screen readers and alternative browsing devices to interpret the content. <br/>非常好的适应性: A semantically marked up document can be easily adapted to print and alternative browsing devices, like handheld computers and cellular phones, just by linking to a different CSS file. You can also make site-wide changes to presentation by editing a single file. <br/>Read more:<br/>我的网页符合Web标准,你的呢? <br/> 能自动清理HTML代码中Word标记 <br/><br/>When text is pasted from Microsoft Word allot of unnecessary word specific markup is carried across. This can result in web pages that take an unnecessarily long time to download. The Paste from Word button solves this by removing word markup before pasting the text into your page. <br/> <br/> 支持W3C WAI和section 508的无障碍引导 <br/><br/>Cute Editor optional accessibility settings ensure your site complies with Section 508, so people with disabilities can have full access to your content.<br/> <br/> 输出的HTML或不错的XHTML供你选择 (Demo)<br/><br/>Cute Editor supports output well-formed XHTML. Your choice of XHTML 1.0 or HTML 4.01 output. <br/><br/> <br/> 无限次的撤销/恢复<br/><br/>Many of the other editors on the market cannot undo or redo certain actions, and certain table operations - such as cell merge or column deletion. Cute Editor 4.0 has a new custom undo/redo implementation to make you can now safely undo those actions. <br/><br/> <br/> 多语言支持,通过简单设置XML即可完成 (Demo)<br/><br/>All labels, buttons, tooltips and messages are located in external XML files, so that the language of the editor can be switched with a single property. You can also create a new language in a matter of minutes. <br/> <br/> 完全支持页面编辑(从 <HTML> 到 </HTML>) (Demo)<br/><br/>Cute Editor 4.0 allows you to edit a full HTML page, including <title>, <!DOCTYPE...> and some other options. You can also insert Form elements (checkbox, button, textarea, etc.) and modify certain properties of the element.<br/> <br/> 默认换行为软回车 (Demo)<br/><br/>Most other editors insert double line returns which can be annoying for clients who are used to editing in Microsoft Word. CuteEditor can be configured to use <div>, <br> or <p> tags when you press enter. In either mode <br> tags can be created by using shift+enter.<br/> <br/> 支持代码缩进和小写字母<br/><br/>Cute Editor displays nicely indented code in the HTML mode and the generating HTML tags and Attributes are in lower case. This is very convenient and important for the advanced users. <br/> <br/> 支持全屏编辑 (Demo)<br/><br/>It does not open a new window, instead it will resize to fit the browser screen. Edit in full screen mode, maximizing your available space. <br/><br/> <br/> 没有打开较慢的Java或ActiveX组件<br/><br/>100% DHTML, JavaScript ASP.Net code. There are no slow Java or ActiveX components to worry about and everything is handled in the browser! <br/><br/> <br/> 支持相对地址和URL自动关联(Demo)<br/><br/>With Cute Editor, you have the choice of using either a relative or absolute URL. <br/> <br/> 部署简单<br/><br/>The perfect addition to your content management system! Only a couple lines of code , you don't need to be an expert. Allows you to add an online HTML editing functionality that works with standard HTML form.<br/> <br/> 可以简单的通过API隐藏按钮和标签 <br/><br/>Cute Editor allows developers to set the image directory, set the controls width, disable image uploading and deleting, restrict access to the source/preview tabs, hide buttons and lists that you don't want your clients to see or access. <br/> <br/> 支持图片的文字环绕 <br/><br/>Locate the image you want to wrap text around, and click any justify button in the toolbar. The image will float to the desired direction. Text will be positioned around the image. <br/> <br/> 支持文件下载 <br/><br/>You can upload document files, create a link from your HTML content to the document files (zip files, ppt files...). <br/> <br/> CSS型皮肤 (Demo)<br/><br/>Cute Editor provides several built in themes that are ready to use. Developers can completely change the appearance of the toolbar and the dialogs by simply modifying the supplied classes and images. <br/> <br/> 高级的表格管理<br/><br/>Create and modify tables and table cells. Set their border color, alignment, cellspacing and more! Once you've created a table, simply right click inside of it and use the handy popup menu to change its attributes. <caption>,<summary>,<thead>,<tfoot>,<th> tags are supported. <br/><br/> <br/> 图片插入和自动上传<br/><br/>Built-in thumbnail generator. Thumbnail images are dynamically created; Supports upload new images. Paging - specify how many images. Support auto resize images.<br/> <br/> 具有特殊的对话框<br/><br/>With Style builder dialog box you can apply CSS style attributes directly to any HTML elements on your Web page.<br/> <br/> 支持内容模板 (Demo)<br/><br/>The basic idea behind a Content Management System (CMS) is to separate the management of content from design. Cute Editor allows the site designer to easily create and establish templates to give the site a uniform look. Templates may be modified when desired. <br/> <br/> 通过限制html和文字的长度来保护你的数据库 (Demo)<br/><br/>If you tried to insert a record whose text length is greater than allowed by your table, an error will be reported. To prevent this type of error from occurring, developers can use MaxHTMLLength or MaxTextLength in the Cute Editor to limit the length of the user抯 input. <br/> <br/> Apply security to control user access to resources <br/><br/>Cute Editor allows developers to assign a pre-defined set of permissions by group or individual. This prevents a normal user to access the administration functionality. <br/><br/>The details of permissions are specified by an XML security policy file. Each level maps to a specific file. The default mappings: <br/><br/>admin设置 admin.config <br/>default设置 default.config <br/>guest设置 guest.config <br/>You can customize and extend each policy file by editing the XML security policy file. You can also create your own policy files that define arbitrary permission sets.<br/><br/>Comparison of the sample security policy file <br/><br/> <br/>Permissions/Resource Setting Admin Default Guest <br/>AllowUpload <br/>AllowDelete <br/>AllowCopy <br/>AllowMove <br/>AllowCreateFolder <br/>AllowDeleteFolder <br/>RestrictUploadedImageDimension <br/>AutoResizeUploadedImages <br/>MaxImageWidth 6400 640 640 <br/>MaxImageHeight 4800 480 480 <br/>MaxImageSize 10000 100 100 <br/>MaxMediaSize 10000 100 100 <br/>MaxFlashSize 10000 100 100 <br/>MaxDocumentSize 10000 100 100 <br/>ImageGalleryPath ~/uploads ~/uploads/member ~/uploads/guest <br/>MediaGalleryPath ~/uploads ~/uploads/member ~/uploads/guest <br/>FlashGalleryPath ~/uploads ~/uploads/member ~/uploads/guest <br/>FilesGallaryPath ~/uploads ~/uploads/member ~/uploads/guest <br/>ImageFilters .jpg <br/>.jpeg <br/>.gif <br/>.png .jpg <br/>.jpeg <br/>.gif <br/> .jpg <br/>.jpeg <br/>.gif <br/> <br/>MediaFilters .avi <br/>.mpg <br/>.mpeg <br/>.mp3 .avi <br/>.mpg <br/>.mpeg <br/> .avi <br/>.mpg <br/>.mpeg <br/> <br/>DocumentFilters .txt, .doc<br/>.pdf, .zip<br/>.rar, .avi<br/>.mpg, .mpeg<br/>.mp3, .jpg<br/>.jpeg,.gif<br/>.png .pdf, .doc<br/> .txt, .doc<br/>.pdf, .zip<br/> <br/> <br/> 在线图片编辑<br/><br/>People that input content on a website are generally not web designers, so most don't have that design & technical fibre in them. With online image editor, you can now edit image file with no image editing software to download or install! Easy drag and drop familiar interface. Resize, change dimensions, scale, crop, add text, optimize, rotate, flip, mirror and add watermark. <br/> <br/> 控制上传文件夹大小<br/><br/>Max Upload Folder size(Including all subfolders and files. A must have feature for people who have limited hosting space.) Dynamic display of available free space in the Upload Folder.Limits the size of your upload folder. If the max is reached uploads will be disabled. <br/> <br/> 支持图片热点<br/><br/>Image maps are pictures with clickable regions also known as "hotspots." When users click on one of the hotspots, they're directed to the page you designate. CuteEditor 5.0 lets you easily create image maps to add fun and excitement to a page<br/> <br/> <div> 的盒模式<br/><br/><div> boxes offer a much greater ability to control the layout of a page. With CuteEditor, you can put any content between <div> tags and then use CSS to style all sorts of borders, backgrounds, etc. <br/> <br/> 通用虚拟键盘<br/><br/>Virtual Keyboard does not require changes to language settings of your system and even speeds up the entire text input process for your customers. It lets your native speaking clients to access your web resources from any location in the world without changing national keyboard layouts and fonts on their machines. <br/> <br/> 把图片存到数据库<br/><br/>With CuteEditor you can easily use a Sql Server database or access database as the file storage. <br/> <br/> RTF和HTML之间互相转换<br/><br/>With CuteEditor you can easily convert an HTML document into an RTF file and RTF file into HTML or XHTML document. <br/> <br/> 生成PDF文件<br/><br/>CuteEditor also allows you dynamically create Adobe PDF documents from ASP.NET.<br/> cuteEditor6.0多语言版(集成lic文件) <br/><br/>目前功能强大,最好的Asp.net编辑器之一 <br/>除了一般html编辑器具有的功能外,还有word过滤、图片在线处理、加水印等实用功能 <br/>使用关键步骤: <br/><br/>1、引用bin下的cuteEditor文件 <br/>2、在aspx页面顶部中添加引用 <br/>3、在aspx页面中加入代码 <br/>4、最后可以在.cs文件中通过来读取Editor1.Text的值来进行任意的扩展和控制了 <br/>具体配置可参照default.aspx和default.aspx.cs <br/><br/>关于cuteEditor6.0的特征及体验请浏览cuteEditor.cn,系统集成了lic授权文件,仅供体验测试使用,请不要用于任何商业用途! <br/><br/> <br/>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值