npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wepy-html

v0.1.6

Published

Rich text component for WePY applications

Downloads

6

Readme

WePY HTML

简介

「WePY HTML」是基于「WePY」小程序框架所开发的富文本内容组件。与小程序原生的「rich-text」组件相比,本组件能实现更多交互效果;与「wxParse」相比,本组件的解析性能更高、灵活性更强。

(注意:本组件目前仅支持基于「WePY」开发的微信小程序项目)

安装

在小程序项目目录下安装本组件:

npm install wepy-html --save

此外,还要安装一个构建插件:

npm install wepy-plugin-replace --save-dev

调用

首先要在「wepy.config.js」中增加构建步骤(开发和生产都要加):

{
	plugins: {
		replace: {
			filter: /\.wxml$/,
			config: {
				find: /<\!-- wepyhtml-repeat start -->([\W\w]+?)<\!-- wepyhtml-repeat end -->/,
				replace(match, tpl) {
					let result = '';
					let prefix = '';

					tpl = tpl.replace(/\{\{\s*(\$.*?\$)thisIsMe\s*\}\}/, (match, p) => {
						prefix = p;
						return '';
					});

					for (let i = 0; i <= 20; i++) {
						result += '\n' + tpl
							.replace('wepyhtml-0', 'wepyhtml-' + i)
							.replace(/<\!-- next template -->/g, () => {
								return i === 20 ?
									'' :
									`<template is="wepyhtml-${ i + 1 }" wx:if="{{ item.children }}" data="{{ ${ prefix }content: item.children, ${ prefix }imgInsteadOfVideo: ${ prefix }imgInsteadOfVideo }}"></template>`;
							});
					}
					return result;
				}
			}
		}
	}
}

然后就可以在页面(page.wpy)中调用组件了,例如:

<template lang="wxml">
	<wepy-html />
</template>

<style>
/* 可以覆盖默认样式 */
.wepyhtml-tag-p {
	margin: 1em 0;
}
</style>

<script>
import WepyHTML from 'wepy-html';

export default class Page extends wepy.component {
	components: {
		'wepy-html': WepyHTML
	},

	onLoad() {
		// 调用组件接口,传入HTML内容和相关参数
		this.$invoke('wepy-html', 'updateContent', htmlCode, {
			// 是否使用图片代替视频(点击时全屏播放视频),
			// 主要用于防止视频组件遮挡其他元素
			imgInsteadOfVideo: true,

			// 可以在此函数中处理链接点击
			onHyperlinkTap(e) {
				// e.href 为链接地址
			},

			// 可以在此函数中修改属性
			onNodeCreate(nodeName, attrs) {
				// nodeName 为标签名
				// attrs 为属性集合
			}
		});
	}
}
</script>