Showing preview only (408K chars total). Download the full file or copy to clipboard to get everything.
Repository: tumobi/nideshop-mini-program
Branch: master
Commit: 0ae5a3d0c620
Files: 152
Total size: 373.5 KB
Directory structure:
gitextract_vsm6etqj/
├── .gitignore
├── README.md
├── app.js
├── app.json
├── app.wxss
├── config/
│ └── api.js
├── lib/
│ └── wxParse/
│ ├── html2json.js
│ ├── htmlparser.js
│ ├── showdown.js
│ ├── wxDiscode.js
│ ├── wxParse.js
│ ├── wxParse.wxml
│ └── wxParse.wxss
├── pages/
│ ├── auth/
│ │ ├── login/
│ │ │ ├── login.js
│ │ │ ├── login.json
│ │ │ ├── login.wxml
│ │ │ └── login.wxss
│ │ ├── register/
│ │ │ ├── register.js
│ │ │ ├── register.json
│ │ │ ├── register.wxml
│ │ │ └── register.wxss
│ │ └── reset/
│ │ ├── reset.js
│ │ ├── reset.json
│ │ ├── reset.wxml
│ │ └── reset.wxss
│ ├── brand/
│ │ ├── brand.js
│ │ ├── brand.json
│ │ ├── brand.wxml
│ │ └── brand.wxss
│ ├── brandDetail/
│ │ ├── brandDetail.js
│ │ ├── brandDetail.json
│ │ ├── brandDetail.wxml
│ │ └── brandDetail.wxss
│ ├── cart/
│ │ ├── cart.js
│ │ ├── cart.json
│ │ ├── cart.wxml
│ │ └── cart.wxss
│ ├── catalog/
│ │ ├── catalog.js
│ │ ├── catalog.json
│ │ ├── catalog.wxml
│ │ └── catalog.wxss
│ ├── category/
│ │ ├── category.js
│ │ ├── category.json
│ │ ├── category.wxml
│ │ └── category.wxss
│ ├── comment/
│ │ ├── comment.js
│ │ ├── comment.json
│ │ ├── comment.wxml
│ │ └── comment.wxss
│ ├── commentPost/
│ │ ├── commentPost.js
│ │ ├── commentPost.json
│ │ ├── commentPost.wxml
│ │ └── commentPost.wxss
│ ├── goods/
│ │ ├── goods.js
│ │ ├── goods.json
│ │ ├── goods.wxml
│ │ └── goods.wxss
│ ├── hotGoods/
│ │ ├── hotGoods.js
│ │ ├── hotGoods.json
│ │ ├── hotGoods.wxml
│ │ └── hotGoods.wxss
│ ├── index/
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxss
│ ├── logs/
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
│ ├── newGoods/
│ │ ├── newGoods.js
│ │ ├── newGoods.json
│ │ ├── newGoods.wxml
│ │ └── newGoods.wxss
│ ├── pay/
│ │ ├── pay.js
│ │ ├── pay.json
│ │ ├── pay.wxml
│ │ └── pay.wxss
│ ├── payResult/
│ │ ├── payResult.js
│ │ ├── payResult.json
│ │ ├── payResult.wxml
│ │ └── payResult.wxss
│ ├── search/
│ │ ├── search.js
│ │ ├── search.json
│ │ ├── search.wxml
│ │ └── search.wxss
│ ├── shopping/
│ │ ├── address/
│ │ │ ├── address.js
│ │ │ ├── address.json
│ │ │ ├── address.wxml
│ │ │ └── address.wxss
│ │ ├── addressAdd/
│ │ │ ├── addressAdd.js
│ │ │ ├── addressAdd.json
│ │ │ ├── addressAdd.wxml
│ │ │ └── addressAdd.wxss
│ │ └── checkout/
│ │ ├── checkout.js
│ │ ├── checkout.json
│ │ ├── checkout.wxml
│ │ └── checkout.wxss
│ ├── topic/
│ │ ├── topic.js
│ │ ├── topic.json
│ │ ├── topic.wxml
│ │ └── topic.wxss
│ ├── topicComment/
│ │ ├── topicComment.js
│ │ ├── topicComment.json
│ │ ├── topicComment.wxml
│ │ └── topicComment.wxss
│ ├── topicDetail/
│ │ ├── topicDetail.js
│ │ ├── topicDetail.json
│ │ ├── topicDetail.wxml
│ │ └── topicDetail.wxss
│ └── ucenter/
│ ├── address/
│ │ ├── address.js
│ │ ├── address.json
│ │ ├── address.wxml
│ │ └── address.wxss
│ ├── addressAdd/
│ │ ├── addressAdd.js
│ │ ├── addressAdd.json
│ │ ├── addressAdd.wxml
│ │ └── addressAdd.wxss
│ ├── collect/
│ │ ├── collect.js
│ │ ├── collect.json
│ │ ├── collect.wxml
│ │ └── collect.wxss
│ ├── coupon/
│ │ ├── coupon.js
│ │ ├── coupon.json
│ │ ├── coupon.wxml
│ │ └── coupon.wxss
│ ├── express/
│ │ ├── express.js
│ │ ├── express.json
│ │ ├── express.wxml
│ │ └── express.wxss
│ ├── feedback/
│ │ ├── feedback.js
│ │ ├── feedback.json
│ │ ├── feedback.wxml
│ │ └── feedback.wxss
│ ├── footprint/
│ │ ├── footprint.js
│ │ ├── footprint.json
│ │ ├── footprint.wxml
│ │ └── footprint.wxss
│ ├── index/
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxss
│ ├── order/
│ │ ├── order.js
│ │ ├── order.json
│ │ ├── order.wxml
│ │ └── order.wxss
│ └── orderDetail/
│ ├── orderDetail.js
│ ├── orderDetail.json
│ ├── orderDetail.wxml
│ └── orderDetail.wxss
├── services/
│ ├── pay.js
│ └── user.js
└── utils/
└── util.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
project.config.json
================================================
FILE: README.md
================================================
### NideShop商城(微信小程序端)
+ 界面高仿网易严选商城(主要是2016年wap版)
+ 测试数据采集自网易严选商城
+ 功能和数据库参考ecshop
+ 服务端api基于Node.js+ThinkJS+MySQL
+ 计划添加基于Vue.js的后台管理系统、PC版、Wap版
**注意:当前版本功能还未完善,请勿商用。**
本项目需要配合NideShop商城服务端使用,GitHub: [https://github.com/tumobi/nideshop](https://github.com/tumobi/nideshop)
[云服务器ECS-云主机优惠-2折上云](https://www.aliyun.com/daily-act/ecs/activity_selection?userCode=3grpysgf)
### 项目截图







### 功能列表
+ 首页
+ 分类首页、分类商品、新品首发、人气推荐商品页面
+ 商品详情页面,包含加入购物车、收藏商品、商品评论功能
+ 搜索功能
+ 专题功能
+ 品牌功能
+ 完整的购物流程,商品的加入、编辑、删除、批量选择,收货地址的选择,下单支付
+ 会员中心(订单、收藏、足迹、收货地址、意见反馈)
....
### 项目结构
```
├─config
├─lib
│ └─wxParse
├─pages
│ ├─auth
│ │ ├─login
│ │ ├─register
│ │ └─reset
│ ├─brand
│ ├─brandDetail
│ ├─cart
│ ├─catalog
│ ├─category
│ ├─comment
│ ├─goods
│ ├─hotGoods
│ ├─index
│ ├─logs
│ ├─newGoods
│ ├─pay
│ ├─search
│ ├─shopping
│ │ ├─address
│ │ ├─addressAdd
│ │ └─checkout
│ ├─topic
│ ├─topicDetail
│ └─ucenter
│ ├─address
│ ├─addressAdd
│ ├─collect
│ ├─coupon
│ ├─feedback
│ ├─footprint
│ ├─index
│ ├─order
│ └─orderDetail
├─static
│ └─images
└─utils
```
### 服务端api
项目地址:https://github.com/tumobi/nideshop
### 交流
喜欢别忘了 Star,有问题可通过微信、公众号、QQ 群联系我,谢谢您的关注。

================================================
FILE: app.js
================================================
App({
onLaunch: function () {
try {
this.globalData.userInfo = JSON.parse(wx.getStorageSync('userInfo'));
this.globalData.token = wx.getStorageSync('token');
} catch (e) {
console.log(e);
}
},
globalData: {
userInfo: {
nickname: '点击登录',
avatar: 'http://yanxuan.nosdn.127.net/8945ae63d940cc42406c3f67019c5cb6.png'
},
token: '',
}
})
================================================
FILE: app.json
================================================
{
"pages": [
"pages/index/index",
"pages/catalog/catalog",
"pages/newGoods/newGoods",
"pages/hotGoods/hotGoods",
"pages/ucenter/address/address",
"pages/ucenter/addressAdd/addressAdd",
"pages/ucenter/footprint/footprint",
"pages/ucenter/order/order",
"pages/ucenter/orderDetail/orderDetail",
"pages/ucenter/express/express",
"pages/ucenter/feedback/feedback",
"pages/ucenter/coupon/coupon",
"pages/ucenter/collect/collect",
"pages/auth/login/login",
"pages/auth/register/register",
"pages/auth/reset/reset",
"pages/pay/pay",
"pages/payResult/payResult",
"pages/ucenter/index/index",
"pages/topic/topic",
"pages/comment/comment",
"pages/commentPost/commentPost",
"pages/topicComment/topicComment",
"pages/brand/brand",
"pages/brandDetail/brandDetail",
"pages/search/search",
"pages/category/category",
"pages/cart/cart",
"pages/shopping/checkout/checkout",
"pages/shopping/address/address",
"pages/shopping/addressAdd/addressAdd",
"pages/goods/goods",
"pages/topicDetail/topicDetail"
],
"window": {
"backgroundTextStyle": "dark",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "仿网易严选",
"navigationBarTextStyle": "black",
"enablePullDownRefresh": true
},
"tabBar": {
"backgroundColor": "#fafafa",
"borderStyle": "white",
"selectedColor": "#b4282d",
"color": "#666",
"list": [
{
"pagePath": "pages/index/index",
"iconPath": "static/images/ic_menu_choice_nor.png",
"selectedIconPath": "static/images/ic_menu_choice_pressed.png",
"text": "首页"
},
{
"pagePath": "pages/topic/topic",
"iconPath": "static/images/ic_menu_topic_nor.png",
"selectedIconPath": "static/images/ic_menu_topic_pressed.png",
"text": "专题"
},
{
"pagePath": "pages/catalog/catalog",
"iconPath": "static/images/ic_menu_sort_nor.png",
"selectedIconPath": "static/images/ic_menu_sort_pressed.png",
"text": "分类"
},
{
"pagePath": "pages/cart/cart",
"iconPath": "static/images/ic_menu_shoping_nor.png",
"selectedIconPath": "static/images/ic_menu_shoping_pressed.png",
"text": "购物车"
},
{
"pagePath": "pages/ucenter/index/index",
"iconPath": "static/images/ic_menu_me_nor.png",
"selectedIconPath": "static/images/ic_menu_me_pressed.png",
"text": "我的"
}
]
},
"networkTimeout": {
"request": 10000,
"downloadFile": 10000
},
"debug": true
}
================================================
FILE: app.wxss
================================================
/**app.wxss**/
.container {
box-sizing: border-box;
background-color: #f4f4f4;
font-family: PingFangSC-Light,helvetica,'Heiti SC';
}
view,image,text,navigator{
box-sizing: border-box;
padding:0;
margin:0;
}
view,text{
font-family: PingFangSC-Light,helvetica,'Heiti SC';
font-size: 29rpx;
color: #333;
}
================================================
FILE: config/api.js
================================================
const ApiRootUrl = 'http://127.0.0.1:8360/api/';
module.exports = {
IndexUrl: ApiRootUrl + 'index/index', //首页数据接口
CatalogList: ApiRootUrl + 'catalog/index', //分类目录全部分类数据接口
CatalogCurrent: ApiRootUrl + 'catalog/current', //分类目录当前分类数据接口
AuthLoginByWeixin: ApiRootUrl + 'auth/loginByWeixin', //微信登录
GoodsCount: ApiRootUrl + 'goods/count', //统计商品总数
GoodsList: ApiRootUrl + 'goods/list', //获得商品列表
GoodsCategory: ApiRootUrl + 'goods/category', //获得分类数据
GoodsDetail: ApiRootUrl + 'goods/detail', //获得商品的详情
GoodsNew: ApiRootUrl + 'goods/new', //新品
GoodsHot: ApiRootUrl + 'goods/hot', //热门
GoodsRelated: ApiRootUrl + 'goods/related', //商品详情页的关联商品(大家都在看)
BrandList: ApiRootUrl + 'brand/list', //品牌列表
BrandDetail: ApiRootUrl + 'brand/detail', //品牌详情
CartList: ApiRootUrl + 'cart/index', //获取购物车的数据
CartAdd: ApiRootUrl + 'cart/add', // 添加商品到购物车
CartUpdate: ApiRootUrl + 'cart/update', // 更新购物车的商品
CartDelete: ApiRootUrl + 'cart/delete', // 删除购物车的商品
CartChecked: ApiRootUrl + 'cart/checked', // 选择或取消选择商品
CartGoodsCount: ApiRootUrl + 'cart/goodscount', // 获取购物车商品件数
CartCheckout: ApiRootUrl + 'cart/checkout', // 下单前信息确认
OrderSubmit: ApiRootUrl + 'order/submit', // 提交订单
PayPrepayId: ApiRootUrl + 'pay/prepay', //获取微信统一下单prepay_id
CollectList: ApiRootUrl + 'collect/list', //收藏列表
CollectAddOrDelete: ApiRootUrl + 'collect/addordelete', //添加或取消收藏
CommentList: ApiRootUrl + 'comment/list', //评论列表
CommentCount: ApiRootUrl + 'comment/count', //评论总数
CommentPost: ApiRootUrl + 'comment/post', //发表评论
TopicList: ApiRootUrl + 'topic/list', //专题列表
TopicDetail: ApiRootUrl + 'topic/detail', //专题详情
TopicRelated: ApiRootUrl + 'topic/related', //相关专题
SearchIndex: ApiRootUrl + 'search/index', //搜索页面数据
SearchResult: ApiRootUrl + 'search/result', //搜索数据
SearchHelper: ApiRootUrl + 'search/helper', //搜索帮助
SearchClearHistory: ApiRootUrl + 'search/clearhistory', //搜索帮助
AddressList: ApiRootUrl + 'address/list', //收货地址列表
AddressDetail: ApiRootUrl + 'address/detail', //收货地址详情
AddressSave: ApiRootUrl + 'address/save', //保存收货地址
AddressDelete: ApiRootUrl + 'address/delete', //保存收货地址
RegionList: ApiRootUrl + 'region/list', //获取区域列表
OrderList: ApiRootUrl + 'order/list', //订单列表
OrderDetail: ApiRootUrl + 'order/detail', //订单详情
OrderCancel: ApiRootUrl + 'order/cancel', //取消订单
OrderExpress: ApiRootUrl + 'order/express', //物流详情
FootprintList: ApiRootUrl + 'footprint/list', //足迹列表
FootprintDelete: ApiRootUrl + 'footprint/delete', //删除足迹
};
================================================
FILE: lib/wxParse/html2json.js
================================================
/**
* author: Di (微信小程序开发工程师)
* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
* 垂直微信小程序开发交流社区
*
* github地址: https://github.com/icindy/wxParse
*
* for: 微信小程序富文本解析
* detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
*/
var __placeImgeUrlHttps = "https";
var __emojisReg = '';
var __emojisBaseSrc = '';
var __emojis = {};
var wxDiscode = require('wxDiscode.js');
var HTMLParser = require('htmlparser.js');
// Empty Elements - HTML 5
var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr");
// Block Elements - HTML 5
var block = makeMap("br,a,code,address,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video");
// Inline Elements - HTML 5
var inline = makeMap("abbr,acronym,applet,b,basefont,bdo,big,button,cite,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var");
// Elements that you can, intentionally, leave open
// (and which close themselves)
var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");
// Attributes that have their values filled in disabled="disabled"
var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");
// Special Elements (can contain anything)
var special = makeMap("wxxxcode-style,script,style,view,scroll-view,block");
function makeMap(str) {
var obj = {}, items = str.split(",");
for (var i = 0; i < items.length; i++)
obj[items[i]] = true;
return obj;
}
function q(v) {
return '"' + v + '"';
}
function removeDOCTYPE(html) {
return html
.replace(/<\?xml.*\?>\n/, '')
.replace(/<!doctype.*\>\n/, '')
.replace(/<!DOCTYPE.*\>\n/, '');
}
function html2json(html, bindName) {
//处理字符串
html = removeDOCTYPE(html);
html = wxDiscode.strDiscode(html);
//生成node节点
var bufArray = [];
var results = {
node: bindName,
nodes: [],
images:[],
imageUrls:[]
};
HTMLParser(html, {
start: function (tag, attrs, unary) {
//debug(tag, attrs, unary);
// node for this element
var node = {
node: 'element',
tag: tag,
};
if (block[tag]) {
node.tagType = "block";
} else if (inline[tag]) {
node.tagType = "inline";
} else if (closeSelf[tag]) {
node.tagType = "closeSelf";
}
if (attrs.length !== 0) {
node.attr = attrs.reduce(function (pre, attr) {
var name = attr.name;
var value = attr.value;
if (name == 'class') {
console.dir(value);
// value = value.join("")
node.classStr = value;
}
// has multi attibutes
// make it array of attribute
if (name == 'style') {
console.dir(value);
// value = value.join("")
node.styleStr = value;
}
if (value.match(/ /)) {
value = value.split(' ');
}
// if attr already exists
// merge it
if (pre[name]) {
if (Array.isArray(pre[name])) {
// already array, push to last
pre[name].push(value);
} else {
// single value, make it array
pre[name] = [pre[name], value];
}
} else {
// not exist, put it
pre[name] = value;
}
return pre;
}, {});
}
//对img添加额外数据
if (node.tag === 'img') {
node.imgIndex = results.images.length;
var imgUrl = node.attr.src;
imgUrl = wxDiscode.urlToHttpUrl(imgUrl, __placeImgeUrlHttps);
node.attr.src = imgUrl;
node.from = bindName;
results.images.push(node);
results.imageUrls.push(imgUrl);
}
if (unary) {
// if this tag dosen't have end tag
// like <img src="hoge.png"/>
// add to parents
var parent = bufArray[0] || results;
if (parent.nodes === undefined) {
parent.nodes = [];
}
parent.nodes.push(node);
} else {
bufArray.unshift(node);
}
},
end: function (tag) {
//debug(tag);
// merge into parent tag
var node = bufArray.shift();
if (node.tag !== tag) console.error('invalid state: mismatch end tag');
if (bufArray.length === 0) {
results.nodes.push(node);
} else {
var parent = bufArray[0];
if (parent.nodes === undefined) {
parent.nodes = [];
}
parent.nodes.push(node);
}
},
chars: function (text) {
//debug(text);
var node = {
node: 'text',
text: text,
textArray:transEmojiStr(text)
};
if (bufArray.length === 0) {
results.nodes.push(node);
} else {
var parent = bufArray[0];
if (parent.nodes === undefined) {
parent.nodes = [];
}
parent.nodes.push(node);
}
},
comment: function (text) {
//debug(text);
var node = {
node: 'comment',
text: text,
};
var parent = bufArray[0];
if (parent.nodes === undefined) {
parent.nodes = [];
}
parent.nodes.push(node);
},
});
return results;
};
function transEmojiStr(str){
// var eReg = new RegExp("["+__reg+' '+"]");
// str = str.replace(/\[([^\[\]]+)\]/g,':$1:')
var emojiObjs = [];
//如果正则表达式为空
if(__emojisReg.length == 0 || !__emojis){
var emojiObj = {}
emojiObj.node = "text";
emojiObj.text = str;
array = [emojiObj];
return array;
}
//这个地方需要调整
str = str.replace(/\[([^\[\]]+)\]/g,':$1:')
var eReg = new RegExp("[:]");
var array = str.split(eReg);
for(var i = 0; i < array.length; i++){
var ele = array[i];
var emojiObj = {};
if(__emojis[ele]){
emojiObj.node = "element";
emojiObj.tag = "emoji";
emojiObj.text = __emojis[ele];
emojiObj.baseSrc= __emojisBaseSrc;
}else{
emojiObj.node = "text";
emojiObj.text = ele;
}
emojiObjs.push(emojiObj);
}
return emojiObjs;
}
function emojisInit(reg='',baseSrc="/wxParse/emojis/",emojis){
__emojisReg = reg;
__emojisBaseSrc=baseSrc;
__emojis=emojis;
}
module.exports = {
html2json: html2json,
emojisInit:emojisInit
};
================================================
FILE: lib/wxParse/htmlparser.js
================================================
/**
* author: Di (微信小程序开发工程师)
* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
* 垂直微信小程序开发交流社区
*
* github地址: https://github.com/icindy/wxParse
*
* for: 微信小程序富文本解析
* detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
*/
// Regular Expressions for parsing tags and attributes
var startTag = /^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,
endTag = /^<\/([-A-Za-z0-9_]+)[^>]*>/,
attr = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;
// Empty Elements - HTML 5
var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr");
// Block Elements - HTML 5
var block = makeMap("a,address,code,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video");
// Inline Elements - HTML 5
var inline = makeMap("abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var");
// Elements that you can, intentionally, leave open
// (and which close themselves)
var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");
// Attributes that have their values filled in disabled="disabled"
var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");
// Special Elements (can contain anything)
var special = makeMap("wxxxcode-style,script,style,view,scroll-view,block");
function HTMLParser(html, handler) {
var index, chars, match, stack = [], last = html;
stack.last = function () {
return this[this.length - 1];
};
while (html) {
chars = true;
// Make sure we're not in a script or style element
if (!stack.last() || !special[stack.last()]) {
// Comment
if (html.indexOf("<!--") == 0) {
index = html.indexOf("-->");
if (index >= 0) {
if (handler.comment)
handler.comment(html.substring(4, index));
html = html.substring(index + 3);
chars = false;
}
// end tag
} else if (html.indexOf("</") == 0) {
match = html.match(endTag);
if (match) {
html = html.substring(match[0].length);
match[0].replace(endTag, parseEndTag);
chars = false;
}
// start tag
} else if (html.indexOf("<") == 0) {
match = html.match(startTag);
if (match) {
html = html.substring(match[0].length);
match[0].replace(startTag, parseStartTag);
chars = false;
}
}
if (chars) {
index = html.indexOf("<");
var text = index < 0 ? html : html.substring(0, index);
html = index < 0 ? "" : html.substring(index);
if (handler.chars)
handler.chars(text);
}
} else {
html = html.replace(new RegExp("([\\s\\S]*?)<\/" + stack.last() + "[^>]*>"), function (all, text) {
text = text.replace(/<!--([\s\S]*?)-->|<!\[CDATA\[([\s\S]*?)]]>/g, "$1$2");
if (handler.chars)
handler.chars(text);
return "";
});
parseEndTag("", stack.last());
}
if (html == last)
throw "Parse Error: " + html;
last = html;
}
// Clean up any remaining tags
parseEndTag();
function parseStartTag(tag, tagName, rest, unary) {
tagName = tagName.toLowerCase();
if (block[tagName]) {
while (stack.last() && inline[stack.last()]) {
parseEndTag("", stack.last());
}
}
if (closeSelf[tagName] && stack.last() == tagName) {
parseEndTag("", tagName);
}
unary = empty[tagName] || !!unary;
if (!unary)
stack.push(tagName);
if (handler.start) {
var attrs = [];
rest.replace(attr, function (match, name) {
var value = arguments[2] ? arguments[2] :
arguments[3] ? arguments[3] :
arguments[4] ? arguments[4] :
fillAttrs[name] ? name : "";
attrs.push({
name: name,
value: value,
escaped: value.replace(/(^|[^\\])"/g, '$1\\\"') //"
});
});
if (handler.start) {
handler.start(tagName, attrs, unary);
}
}
}
function parseEndTag(tag, tagName) {
// If no tag name is provided, clean shop
if (!tagName)
var pos = 0;
// Find the closest opened tag of the same type
else
for (var pos = stack.length - 1; pos >= 0; pos--)
if (stack[pos] == tagName)
break;
if (pos >= 0) {
// Close all the open elements, up the stack
for (var i = stack.length - 1; i >= pos; i--)
if (handler.end)
handler.end(stack[i]);
// Remove the open elements from the stack
stack.length = pos;
}
}
};
function makeMap(str) {
var obj = {}, items = str.split(",");
for (var i = 0; i < items.length; i++)
obj[items[i]] = true;
return obj;
}
module.exports = HTMLParser;
================================================
FILE: lib/wxParse/showdown.js
================================================
/**
* author: Di (微信小程序开发工程师)
* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
* 垂直微信小程序开发交流社区
*
* github地址: https://github.com/icindy/wxParse
*
* for: 微信小程序富文本解析
* detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
*/
function getDefaultOpts(simple) {
'use strict';
var defaultOptions = {
omitExtraWLInCodeBlocks: {
defaultValue: false,
describe: 'Omit the default extra whiteline added to code blocks',
type: 'boolean'
},
noHeaderId: {
defaultValue: false,
describe: 'Turn on/off generated header id',
type: 'boolean'
},
prefixHeaderId: {
defaultValue: false,
describe: 'Specify a prefix to generated header ids',
type: 'string'
},
headerLevelStart: {
defaultValue: false,
describe: 'The header blocks level start',
type: 'integer'
},
parseImgDimensions: {
defaultValue: false,
describe: 'Turn on/off image dimension parsing',
type: 'boolean'
},
simplifiedAutoLink: {
defaultValue: false,
describe: 'Turn on/off GFM autolink style',
type: 'boolean'
},
literalMidWordUnderscores: {
defaultValue: false,
describe: 'Parse midword underscores as literal underscores',
type: 'boolean'
},
strikethrough: {
defaultValue: false,
describe: 'Turn on/off strikethrough support',
type: 'boolean'
},
tables: {
defaultValue: false,
describe: 'Turn on/off tables support',
type: 'boolean'
},
tablesHeaderId: {
defaultValue: false,
describe: 'Add an id to table headers',
type: 'boolean'
},
ghCodeBlocks: {
defaultValue: true,
describe: 'Turn on/off GFM fenced code blocks support',
type: 'boolean'
},
tasklists: {
defaultValue: false,
describe: 'Turn on/off GFM tasklist support',
type: 'boolean'
},
smoothLivePreview: {
defaultValue: false,
describe: 'Prevents weird effects in live previews due to incomplete input',
type: 'boolean'
},
smartIndentationFix: {
defaultValue: false,
description: 'Tries to smartly fix identation in es6 strings',
type: 'boolean'
}
};
if (simple === false) {
return JSON.parse(JSON.stringify(defaultOptions));
}
var ret = {};
for (var opt in defaultOptions) {
if (defaultOptions.hasOwnProperty(opt)) {
ret[opt] = defaultOptions[opt].defaultValue;
}
}
return ret;
}
/**
* Created by Tivie on 06-01-2015.
*/
// Private properties
var showdown = {},
parsers = {},
extensions = {},
globalOptions = getDefaultOpts(true),
flavor = {
github: {
omitExtraWLInCodeBlocks: true,
prefixHeaderId: 'user-content-',
simplifiedAutoLink: true,
literalMidWordUnderscores: true,
strikethrough: true,
tables: true,
tablesHeaderId: true,
ghCodeBlocks: true,
tasklists: true
},
vanilla: getDefaultOpts(true)
};
/**
* helper namespace
* @type {{}}
*/
showdown.helper = {};
/**
* TODO LEGACY SUPPORT CODE
* @type {{}}
*/
showdown.extensions = {};
/**
* Set a global option
* @static
* @param {string} key
* @param {*} value
* @returns {showdown}
*/
showdown.setOption = function (key, value) {
'use strict';
globalOptions[key] = value;
return this;
};
/**
* Get a global option
* @static
* @param {string} key
* @returns {*}
*/
showdown.getOption = function (key) {
'use strict';
return globalOptions[key];
};
/**
* Get the global options
* @static
* @returns {{}}
*/
showdown.getOptions = function () {
'use strict';
return globalOptions;
};
/**
* Reset global options to the default values
* @static
*/
showdown.resetOptions = function () {
'use strict';
globalOptions = getDefaultOpts(true);
};
/**
* Set the flavor showdown should use as default
* @param {string} name
*/
showdown.setFlavor = function (name) {
'use strict';
if (flavor.hasOwnProperty(name)) {
var preset = flavor[name];
for (var option in preset) {
if (preset.hasOwnProperty(option)) {
globalOptions[option] = preset[option];
}
}
}
};
/**
* Get the default options
* @static
* @param {boolean} [simple=true]
* @returns {{}}
*/
showdown.getDefaultOptions = function (simple) {
'use strict';
return getDefaultOpts(simple);
};
/**
* Get or set a subParser
*
* subParser(name) - Get a registered subParser
* subParser(name, func) - Register a subParser
* @static
* @param {string} name
* @param {function} [func]
* @returns {*}
*/
showdown.subParser = function (name, func) {
'use strict';
if (showdown.helper.isString(name)) {
if (typeof func !== 'undefined') {
parsers[name] = func;
} else {
if (parsers.hasOwnProperty(name)) {
return parsers[name];
} else {
throw Error('SubParser named ' + name + ' not registered!');
}
}
}
};
/**
* Gets or registers an extension
* @static
* @param {string} name
* @param {object|function=} ext
* @returns {*}
*/
showdown.extension = function (name, ext) {
'use strict';
if (!showdown.helper.isString(name)) {
throw Error('Extension \'name\' must be a string');
}
name = showdown.helper.stdExtName(name);
// Getter
if (showdown.helper.isUndefined(ext)) {
if (!extensions.hasOwnProperty(name)) {
throw Error('Extension named ' + name + ' is not registered!');
}
return extensions[name];
// Setter
} else {
// Expand extension if it's wrapped in a function
if (typeof ext === 'function') {
ext = ext();
}
// Ensure extension is an array
if (!showdown.helper.isArray(ext)) {
ext = [ext];
}
var validExtension = validate(ext, name);
if (validExtension.valid) {
extensions[name] = ext;
} else {
throw Error(validExtension.error);
}
}
};
/**
* Gets all extensions registered
* @returns {{}}
*/
showdown.getAllExtensions = function () {
'use strict';
return extensions;
};
/**
* Remove an extension
* @param {string} name
*/
showdown.removeExtension = function (name) {
'use strict';
delete extensions[name];
};
/**
* Removes all extensions
*/
showdown.resetExtensions = function () {
'use strict';
extensions = {};
};
/**
* Validate extension
* @param {array} extension
* @param {string} name
* @returns {{valid: boolean, error: string}}
*/
function validate(extension, name) {
'use strict';
var errMsg = (name) ? 'Error in ' + name + ' extension->' : 'Error in unnamed extension',
ret = {
valid: true,
error: ''
};
if (!showdown.helper.isArray(extension)) {
extension = [extension];
}
for (var i = 0; i < extension.length; ++i) {
var baseMsg = errMsg + ' sub-extension ' + i + ': ',
ext = extension[i];
if (typeof ext !== 'object') {
ret.valid = false;
ret.error = baseMsg + 'must be an object, but ' + typeof ext + ' given';
return ret;
}
if (!showdown.helper.isString(ext.type)) {
ret.valid = false;
ret.error = baseMsg + 'property "type" must be a string, but ' + typeof ext.type + ' given';
return ret;
}
var type = ext.type = ext.type.toLowerCase();
// normalize extension type
if (type === 'language') {
type = ext.type = 'lang';
}
if (type === 'html') {
type = ext.type = 'output';
}
if (type !== 'lang' && type !== 'output' && type !== 'listener') {
ret.valid = false;
ret.error = baseMsg + 'type ' + type + ' is not recognized. Valid values: "lang/language", "output/html" or "listener"';
return ret;
}
if (type === 'listener') {
if (showdown.helper.isUndefined(ext.listeners)) {
ret.valid = false;
ret.error = baseMsg + '. Extensions of type "listener" must have a property called "listeners"';
return ret;
}
} else {
if (showdown.helper.isUndefined(ext.filter) && showdown.helper.isUndefined(ext.regex)) {
ret.valid = false;
ret.error = baseMsg + type + ' extensions must define either a "regex" property or a "filter" method';
return ret;
}
}
if (ext.listeners) {
if (typeof ext.listeners !== 'object') {
ret.valid = false;
ret.error = baseMsg + '"listeners" property must be an object but ' + typeof ext.listeners + ' given';
return ret;
}
for (var ln in ext.listeners) {
if (ext.listeners.hasOwnProperty(ln)) {
if (typeof ext.listeners[ln] !== 'function') {
ret.valid = false;
ret.error = baseMsg + '"listeners" property must be an hash of [event name]: [callback]. listeners.' + ln +
' must be a function but ' + typeof ext.listeners[ln] + ' given';
return ret;
}
}
}
}
if (ext.filter) {
if (typeof ext.filter !== 'function') {
ret.valid = false;
ret.error = baseMsg + '"filter" must be a function, but ' + typeof ext.filter + ' given';
return ret;
}
} else if (ext.regex) {
if (showdown.helper.isString(ext.regex)) {
ext.regex = new RegExp(ext.regex, 'g');
}
if (!ext.regex instanceof RegExp) {
ret.valid = false;
ret.error = baseMsg + '"regex" property must either be a string or a RegExp object, but ' + typeof ext.regex + ' given';
return ret;
}
if (showdown.helper.isUndefined(ext.replace)) {
ret.valid = false;
ret.error = baseMsg + '"regex" extensions must implement a replace string or function';
return ret;
}
}
}
return ret;
}
/**
* Validate extension
* @param {object} ext
* @returns {boolean}
*/
showdown.validateExtension = function (ext) {
'use strict';
var validateExtension = validate(ext, null);
if (!validateExtension.valid) {
console.warn(validateExtension.error);
return false;
}
return true;
};
/**
* showdownjs helper functions
*/
if (!showdown.hasOwnProperty('helper')) {
showdown.helper = {};
}
/**
* Check if var is string
* @static
* @param {string} a
* @returns {boolean}
*/
showdown.helper.isString = function isString(a) {
'use strict';
return (typeof a === 'string' || a instanceof String);
};
/**
* Check if var is a function
* @static
* @param {string} a
* @returns {boolean}
*/
showdown.helper.isFunction = function isFunction(a) {
'use strict';
var getType = {};
return a && getType.toString.call(a) === '[object Function]';
};
/**
* ForEach helper function
* @static
* @param {*} obj
* @param {function} callback
*/
showdown.helper.forEach = function forEach(obj, callback) {
'use strict';
if (typeof obj.forEach === 'function') {
obj.forEach(callback);
} else {
for (var i = 0; i < obj.length; i++) {
callback(obj[i], i, obj);
}
}
};
/**
* isArray helper function
* @static
* @param {*} a
* @returns {boolean}
*/
showdown.helper.isArray = function isArray(a) {
'use strict';
return a.constructor === Array;
};
/**
* Check if value is undefined
* @static
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
*/
showdown.helper.isUndefined = function isUndefined(value) {
'use strict';
return typeof value === 'undefined';
};
/**
* Standardidize extension name
* @static
* @param {string} s extension name
* @returns {string}
*/
showdown.helper.stdExtName = function (s) {
'use strict';
return s.replace(/[_-]||\s/g, '').toLowerCase();
};
function escapeCharactersCallback(wholeMatch, m1) {
'use strict';
var charCodeToEscape = m1.charCodeAt(0);
return '~E' + charCodeToEscape + 'E';
}
/**
* Callback used to escape characters when passing through String.replace
* @static
* @param {string} wholeMatch
* @param {string} m1
* @returns {string}
*/
showdown.helper.escapeCharactersCallback = escapeCharactersCallback;
/**
* Escape characters in a string
* @static
* @param {string} text
* @param {string} charsToEscape
* @param {boolean} afterBackslash
* @returns {XML|string|void|*}
*/
showdown.helper.escapeCharacters = function escapeCharacters(text, charsToEscape, afterBackslash) {
'use strict';
// First we have to escape the escape characters so that
// we can build a character class out of them
var regexString = '([' + charsToEscape.replace(/([\[\]\\])/g, '\\$1') + '])';
if (afterBackslash) {
regexString = '\\\\' + regexString;
}
var regex = new RegExp(regexString, 'g');
text = text.replace(regex, escapeCharactersCallback);
return text;
};
var rgxFindMatchPos = function (str, left, right, flags) {
'use strict';
var f = flags || '',
g = f.indexOf('g') > -1,
x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
l = new RegExp(left, f.replace(/g/g, '')),
pos = [],
t, s, m, start, end;
do {
t = 0;
while ((m = x.exec(str))) {
if (l.test(m[0])) {
if (!(t++)) {
s = x.lastIndex;
start = s - m[0].length;
}
} else if (t) {
if (!--t) {
end = m.index + m[0].length;
var obj = {
left: {start: start, end: s},
match: {start: s, end: m.index},
right: {start: m.index, end: end},
wholeMatch: {start: start, end: end}
};
pos.push(obj);
if (!g) {
return pos;
}
}
}
}
} while (t && (x.lastIndex = s));
return pos;
};
/**
* matchRecursiveRegExp
*
* (c) 2007 Steven Levithan <stevenlevithan.com>
* MIT License
*
* Accepts a string to search, a left and right format delimiter
* as regex patterns, and optional regex flags. Returns an array
* of matches, allowing nested instances of left/right delimiters.
* Use the "g" flag to return all matches, otherwise only the
* first is returned. Be careful to ensure that the left and
* right format delimiters produce mutually exclusive matches.
* Backreferences are not supported within the right delimiter
* due to how it is internally combined with the left delimiter.
* When matching strings whose format delimiters are unbalanced
* to the left or right, the output is intentionally as a
* conventional regex library with recursion support would
* produce, e.g. "<<x>" and "<x>>" both produce ["x"] when using
* "<" and ">" as the delimiters (both strings contain a single,
* balanced instance of "<x>").
*
* examples:
* matchRecursiveRegExp("test", "\\(", "\\)")
* returns: []
* matchRecursiveRegExp("<t<<e>><s>>t<>", "<", ">", "g")
* returns: ["t<<e>><s>", ""]
* matchRecursiveRegExp("<div id=\"x\">test</div>", "<div\\b[^>]*>", "</div>", "gi")
* returns: ["test"]
*/
showdown.helper.matchRecursiveRegExp = function (str, left, right, flags) {
'use strict';
var matchPos = rgxFindMatchPos (str, left, right, flags),
results = [];
for (var i = 0; i < matchPos.length; ++i) {
results.push([
str.slice(matchPos[i].wholeMatch.start, matchPos[i].wholeMatch.end),
str.slice(matchPos[i].match.start, matchPos[i].match.end),
str.slice(matchPos[i].left.start, matchPos[i].left.end),
str.slice(matchPos[i].right.start, matchPos[i].right.end)
]);
}
return results;
};
/**
*
* @param {string} str
* @param {string|function} replacement
* @param {string} left
* @param {string} right
* @param {string} flags
* @returns {string}
*/
showdown.helper.replaceRecursiveRegExp = function (str, replacement, left, right, flags) {
'use strict';
if (!showdown.helper.isFunction(replacement)) {
var repStr = replacement;
replacement = function () {
return repStr;
};
}
var matchPos = rgxFindMatchPos(str, left, right, flags),
finalStr = str,
lng = matchPos.length;
if (lng > 0) {
var bits = [];
if (matchPos[0].wholeMatch.start !== 0) {
bits.push(str.slice(0, matchPos[0].wholeMatch.start));
}
for (var i = 0; i < lng; ++i) {
bits.push(
replacement(
str.slice(matchPos[i].wholeMatch.start, matchPos[i].wholeMatch.end),
str.slice(matchPos[i].match.start, matchPos[i].match.end),
str.slice(matchPos[i].left.start, matchPos[i].left.end),
str.slice(matchPos[i].right.start, matchPos[i].right.end)
)
);
if (i < lng - 1) {
bits.push(str.slice(matchPos[i].wholeMatch.end, matchPos[i + 1].wholeMatch.start));
}
}
if (matchPos[lng - 1].wholeMatch.end < str.length) {
bits.push(str.slice(matchPos[lng - 1].wholeMatch.end));
}
finalStr = bits.join('');
}
return finalStr;
};
/**
* POLYFILLS
*/
if (showdown.helper.isUndefined(console)) {
console = {
warn: function (msg) {
'use strict';
alert(msg);
},
log: function (msg) {
'use strict';
alert(msg);
},
error: function (msg) {
'use strict';
throw msg;
}
};
}
/**
* Created by Estevao on 31-05-2015.
*/
/**
* Showdown Converter class
* @class
* @param {object} [converterOptions]
* @returns {Converter}
*/
showdown.Converter = function (converterOptions) {
'use strict';
var
/**
* Options used by this converter
* @private
* @type {{}}
*/
options = {},
/**
* Language extensions used by this converter
* @private
* @type {Array}
*/
langExtensions = [],
/**
* Output modifiers extensions used by this converter
* @private
* @type {Array}
*/
outputModifiers = [],
/**
* Event listeners
* @private
* @type {{}}
*/
listeners = {};
_constructor();
/**
* Converter constructor
* @private
*/
function _constructor() {
converterOptions = converterOptions || {};
for (var gOpt in globalOptions) {
if (globalOptions.hasOwnProperty(gOpt)) {
options[gOpt] = globalOptions[gOpt];
}
}
// Merge options
if (typeof converterOptions === 'object') {
for (var opt in converterOptions) {
if (converterOptions.hasOwnProperty(opt)) {
options[opt] = converterOptions[opt];
}
}
} else {
throw Error('Converter expects the passed parameter to be an object, but ' + typeof converterOptions +
' was passed instead.');
}
if (options.extensions) {
showdown.helper.forEach(options.extensions, _parseExtension);
}
}
/**
* Parse extension
* @param {*} ext
* @param {string} [name='']
* @private
*/
function _parseExtension(ext, name) {
name = name || null;
// If it's a string, the extension was previously loaded
if (showdown.helper.isString(ext)) {
ext = showdown.helper.stdExtName(ext);
name = ext;
// LEGACY_SUPPORT CODE
if (showdown.extensions[ext]) {
console.warn('DEPRECATION WARNING: ' + ext + ' is an old extension that uses a deprecated loading method.' +
'Please inform the developer that the extension should be updated!');
legacyExtensionLoading(showdown.extensions[ext], ext);
return;
// END LEGACY SUPPORT CODE
} else if (!showdown.helper.isUndefined(extensions[ext])) {
ext = extensions[ext];
} else {
throw Error('Extension "' + ext + '" could not be loaded. It was either not found or is not a valid extension.');
}
}
if (typeof ext === 'function') {
ext = ext();
}
if (!showdown.helper.isArray(ext)) {
ext = [ext];
}
var validExt = validate(ext, name);
if (!validExt.valid) {
throw Error(validExt.error);
}
for (var i = 0; i < ext.length; ++i) {
switch (ext[i].type) {
case 'lang':
langExtensions.push(ext[i]);
break;
case 'output':
outputModifiers.push(ext[i]);
break;
}
if (ext[i].hasOwnProperty(listeners)) {
for (var ln in ext[i].listeners) {
if (ext[i].listeners.hasOwnProperty(ln)) {
listen(ln, ext[i].listeners[ln]);
}
}
}
}
}
/**
* LEGACY_SUPPORT
* @param {*} ext
* @param {string} name
*/
function legacyExtensionLoading(ext, name) {
if (typeof ext === 'function') {
ext = ext(new showdown.Converter());
}
if (!showdown.helper.isArray(ext)) {
ext = [ext];
}
var valid = validate(ext, name);
if (!valid.valid) {
throw Error(valid.error);
}
for (var i = 0; i < ext.length; ++i) {
switch (ext[i].type) {
case 'lang':
langExtensions.push(ext[i]);
break;
case 'output':
outputModifiers.push(ext[i]);
break;
default:// should never reach here
throw Error('Extension loader error: Type unrecognized!!!');
}
}
}
/**
* Listen to an event
* @param {string} name
* @param {function} callback
*/
function listen(name, callback) {
if (!showdown.helper.isString(name)) {
throw Error('Invalid argument in converter.listen() method: name must be a string, but ' + typeof name + ' given');
}
if (typeof callback !== 'function') {
throw Error('Invalid argument in converter.listen() method: callback must be a function, but ' + typeof callback + ' given');
}
if (!listeners.hasOwnProperty(name)) {
listeners[name] = [];
}
listeners[name].push(callback);
}
function rTrimInputText(text) {
var rsp = text.match(/^\s*/)[0].length,
rgx = new RegExp('^\\s{0,' + rsp + '}', 'gm');
return text.replace(rgx, '');
}
/**
* Dispatch an event
* @private
* @param {string} evtName Event name
* @param {string} text Text
* @param {{}} options Converter Options
* @param {{}} globals
* @returns {string}
*/
this._dispatch = function dispatch (evtName, text, options, globals) {
if (listeners.hasOwnProperty(evtName)) {
for (var ei = 0; ei < listeners[evtName].length; ++ei) {
var nText = listeners[evtName][ei](evtName, text, this, options, globals);
if (nText && typeof nText !== 'undefined') {
text = nText;
}
}
}
return text;
};
/**
* Listen to an event
* @param {string} name
* @param {function} callback
* @returns {showdown.Converter}
*/
this.listen = function (name, callback) {
listen(name, callback);
return this;
};
/**
* Converts a markdown string into HTML
* @param {string} text
* @returns {*}
*/
this.makeHtml = function (text) {
//check if text is not falsy
if (!text) {
return text;
}
var globals = {
gHtmlBlocks: [],
gHtmlMdBlocks: [],
gHtmlSpans: [],
gUrls: {},
gTitles: {},
gDimensions: {},
gListLevel: 0,
hashLinkCounts: {},
langExtensions: langExtensions,
outputModifiers: outputModifiers,
converter: this,
ghCodeBlocks: []
};
// attacklab: Replace ~ with ~T
// This lets us use tilde as an escape char to avoid md5 hashes
// The choice of character is arbitrary; anything that isn't
// magic in Markdown will work.
text = text.replace(/~/g, '~T');
// attacklab: Replace $ with ~D
// RegExp interprets $ as a special character
// when it's in a replacement string
text = text.replace(/\$/g, '~D');
// Standardize line endings
text = text.replace(/\r\n/g, '\n'); // DOS to Unix
text = text.replace(/\r/g, '\n'); // Mac to Unix
if (options.smartIndentationFix) {
text = rTrimInputText(text);
}
// Make sure text begins and ends with a couple of newlines:
//text = '\n\n' + text + '\n\n';
text = text;
// detab
text = showdown.subParser('detab')(text, options, globals);
// stripBlankLines
text = showdown.subParser('stripBlankLines')(text, options, globals);
//run languageExtensions
showdown.helper.forEach(langExtensions, function (ext) {
text = showdown.subParser('runExtension')(ext, text, options, globals);
});
// run the sub parsers
text = showdown.subParser('hashPreCodeTags')(text, options, globals);
text = showdown.subParser('githubCodeBlocks')(text, options, globals);
text = showdown.subParser('hashHTMLBlocks')(text, options, globals);
text = showdown.subParser('hashHTMLSpans')(text, options, globals);
text = showdown.subParser('stripLinkDefinitions')(text, options, globals);
text = showdown.subParser('blockGamut')(text, options, globals);
text = showdown.subParser('unhashHTMLSpans')(text, options, globals);
text = showdown.subParser('unescapeSpecialChars')(text, options, globals);
// attacklab: Restore dollar signs
text = text.replace(/~D/g, '$$');
// attacklab: Restore tildes
text = text.replace(/~T/g, '~');
// Run output modifiers
showdown.helper.forEach(outputModifiers, function (ext) {
text = showdown.subParser('runExtension')(ext, text, options, globals);
});
return text;
};
/**
* Set an option of this Converter instance
* @param {string} key
* @param {*} value
*/
this.setOption = function (key, value) {
options[key] = value;
};
/**
* Get the option of this Converter instance
* @param {string} key
* @returns {*}
*/
this.getOption = function (key) {
return options[key];
};
/**
* Get the options of this Converter instance
* @returns {{}}
*/
this.getOptions = function () {
return options;
};
/**
* Add extension to THIS converter
* @param {{}} extension
* @param {string} [name=null]
*/
this.addExtension = function (extension, name) {
name = name || null;
_parseExtension(extension, name);
};
/**
* Use a global registered extension with THIS converter
* @param {string} extensionName Name of the previously registered extension
*/
this.useExtension = function (extensionName) {
_parseExtension(extensionName);
};
/**
* Set the flavor THIS converter should use
* @param {string} name
*/
this.setFlavor = function (name) {
if (flavor.hasOwnProperty(name)) {
var preset = flavor[name];
for (var option in preset) {
if (preset.hasOwnProperty(option)) {
options[option] = preset[option];
}
}
}
};
/**
* Remove an extension from THIS converter.
* Note: This is a costly operation. It's better to initialize a new converter
* and specify the extensions you wish to use
* @param {Array} extension
*/
this.removeExtension = function (extension) {
if (!showdown.helper.isArray(extension)) {
extension = [extension];
}
for (var a = 0; a < extension.length; ++a) {
var ext = extension[a];
for (var i = 0; i < langExtensions.length; ++i) {
if (langExtensions[i] === ext) {
langExtensions[i].splice(i, 1);
}
}
for (var ii = 0; ii < outputModifiers.length; ++i) {
if (outputModifiers[ii] === ext) {
outputModifiers[ii].splice(i, 1);
}
}
}
};
/**
* Get all extension of THIS converter
* @returns {{language: Array, output: Array}}
*/
this.getAllExtensions = function () {
return {
language: langExtensions,
output: outputModifiers
};
};
};
/**
* Turn Markdown link shortcuts into XHTML <a> tags.
*/
showdown.subParser('anchors', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('anchors.before', text, options, globals);
var writeAnchorTag = function (wholeMatch, m1, m2, m3, m4, m5, m6, m7) {
if (showdown.helper.isUndefined(m7)) {
m7 = '';
}
wholeMatch = m1;
var linkText = m2,
linkId = m3.toLowerCase(),
url = m4,
title = m7;
if (!url) {
if (!linkId) {
// lower-case and turn embedded newlines into spaces
linkId = linkText.toLowerCase().replace(/ ?\n/g, ' ');
}
url = '#' + linkId;
if (!showdown.helper.isUndefined(globals.gUrls[linkId])) {
url = globals.gUrls[linkId];
if (!showdown.helper.isUndefined(globals.gTitles[linkId])) {
title = globals.gTitles[linkId];
}
} else {
if (wholeMatch.search(/\(\s*\)$/m) > -1) {
// Special case for explicit empty url
url = '';
} else {
return wholeMatch;
}
}
}
url = showdown.helper.escapeCharacters(url, '*_', false);
var result = '<a href="' + url + '"';
if (title !== '' && title !== null) {
title = title.replace(/"/g, '"');
title = showdown.helper.escapeCharacters(title, '*_', false);
result += ' title="' + title + '"';
}
result += '>' + linkText + '</a>';
return result;
};
// First, handle reference-style links: [link text] [id]
/*
text = text.replace(/
( // wrap whole match in $1
\[
(
(?:
\[[^\]]*\] // allow brackets nested one level
|
[^\[] // or anything else
)*
)
\]
[ ]? // one optional space
(?:\n[ ]*)? // one optional newline followed by spaces
\[
(.*?) // id = $3
\]
)()()()() // pad remaining backreferences
/g,_DoAnchors_callback);
*/
text = text.replace(/(\[((?:\[[^\]]*]|[^\[\]])*)][ ]?(?:\n[ ]*)?\[(.*?)])()()()()/g, writeAnchorTag);
//
// Next, inline-style links: [link text](url "optional title")
//
/*
text = text.replace(/
( // wrap whole match in $1
\[
(
(?:
\[[^\]]*\] // allow brackets nested one level
|
[^\[\]] // or anything else
)
)
\]
\( // literal paren
[ \t]*
() // no id, so leave $3 empty
<?(.*?)>? // href = $4
[ \t]*
( // $5
(['"]) // quote char = $6
(.*?) // Title = $7
\6 // matching quote
[ \t]* // ignore any spaces/tabs between closing quote and )
)? // title is optional
\)
)
/g,writeAnchorTag);
*/
text = text.replace(/(\[((?:\[[^\]]*]|[^\[\]])*)]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,
writeAnchorTag);
//
// Last, handle reference-style shortcuts: [link text]
// These must come last in case you've also got [link test][1]
// or [link test](/foo)
//
/*
text = text.replace(/
( // wrap whole match in $1
\[
([^\[\]]+) // link text = $2; can't contain '[' or ']'
\]
)()()()()() // pad rest of backreferences
/g, writeAnchorTag);
*/
text = text.replace(/(\[([^\[\]]+)])()()()()()/g, writeAnchorTag);
text = globals.converter._dispatch('anchors.after', text, options, globals);
return text;
});
showdown.subParser('autoLinks', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('autoLinks.before', text, options, globals);
var simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)(?=\s|$)(?!["<>])/gi,
delimUrlRegex = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
simpleMailRegex = /(?:^|[ \n\t])([A-Za-z0-9!#$%&'*+-/=?^_`\{|}~\.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?:$|[ \n\t])/gi,
delimMailRegex = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
text = text.replace(delimUrlRegex, replaceLink);
text = text.replace(delimMailRegex, replaceMail);
// simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi,
// Email addresses: <address@domain.foo>
if (options.simplifiedAutoLink) {
text = text.replace(simpleURLRegex, replaceLink);
text = text.replace(simpleMailRegex, replaceMail);
}
function replaceLink(wm, link) {
var lnkTxt = link;
if (/^www\./i.test(link)) {
link = link.replace(/^www\./i, 'http://www.');
}
return '<a href="' + link + '">' + lnkTxt + '</a>';
}
function replaceMail(wholeMatch, m1) {
var unescapedStr = showdown.subParser('unescapeSpecialChars')(m1);
return showdown.subParser('encodeEmailAddress')(unescapedStr);
}
text = globals.converter._dispatch('autoLinks.after', text, options, globals);
return text;
});
/**
* These are all the transformations that form block-level
* tags like paragraphs, headers, and list items.
*/
showdown.subParser('blockGamut', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('blockGamut.before', text, options, globals);
// we parse blockquotes first so that we can have headings and hrs
// inside blockquotes
text = showdown.subParser('blockQuotes')(text, options, globals);
text = showdown.subParser('headers')(text, options, globals);
// Do Horizontal Rules:
var key = showdown.subParser('hashBlock')('<hr />', options, globals);
text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm, key);
text = text.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm, key);
text = text.replace(/^[ ]{0,2}([ ]?_[ ]?){3,}[ \t]*$/gm, key);
text = showdown.subParser('lists')(text, options, globals);
text = showdown.subParser('codeBlocks')(text, options, globals);
text = showdown.subParser('tables')(text, options, globals);
// We already ran _HashHTMLBlocks() before, in Markdown(), but that
// was to escape raw HTML in the original Markdown source. This time,
// we're escaping the markup we've just created, so that we don't wrap
// <p> tags around block-level tags.
text = showdown.subParser('hashHTMLBlocks')(text, options, globals);
text = showdown.subParser('paragraphs')(text, options, globals);
text = globals.converter._dispatch('blockGamut.after', text, options, globals);
return text;
});
showdown.subParser('blockQuotes', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('blockQuotes.before', text, options, globals);
/*
text = text.replace(/
( // Wrap whole match in $1
(
^[ \t]*>[ \t]? // '>' at the start of a line
.+\n // rest of the first line
(.+\n)* // subsequent consecutive lines
\n* // blanks
)+
)
/gm, function(){...});
*/
text = text.replace(/((^[ \t]{0,3}>[ \t]?.+\n(.+\n)*\n*)+)/gm, function (wholeMatch, m1) {
var bq = m1;
// attacklab: hack around Konqueror 3.5.4 bug:
// "----------bug".replace(/^-/g,"") == "bug"
bq = bq.replace(/^[ \t]*>[ \t]?/gm, '~0'); // trim one level of quoting
// attacklab: clean up hack
bq = bq.replace(/~0/g, '');
bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines
bq = showdown.subParser('githubCodeBlocks')(bq, options, globals);
bq = showdown.subParser('blockGamut')(bq, options, globals); // recurse
bq = bq.replace(/(^|\n)/g, '$1 ');
// These leading spaces screw with <pre> content, so we need to fix that:
bq = bq.replace(/(\s*<pre>[^\r]+?<\/pre>)/gm, function (wholeMatch, m1) {
var pre = m1;
// attacklab: hack around Konqueror 3.5.4 bug:
pre = pre.replace(/^ /mg, '~0');
pre = pre.replace(/~0/g, '');
return pre;
});
return showdown.subParser('hashBlock')('<blockquote>\n' + bq + '\n</blockquote>', options, globals);
});
text = globals.converter._dispatch('blockQuotes.after', text, options, globals);
return text;
});
/**
* Process Markdown `<pre><code>` blocks.
*/
showdown.subParser('codeBlocks', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('codeBlocks.before', text, options, globals);
/*
text = text.replace(text,
/(?:\n\n|^)
( // $1 = the code block -- one or more lines, starting with a space/tab
(?:
(?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width
.*\n+
)+
)
(\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width
/g,function(){...});
*/
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
text += '~0';
var pattern = /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g;
text = text.replace(pattern, function (wholeMatch, m1, m2) {
var codeblock = m1,
nextChar = m2,
end = '\n';
codeblock = showdown.subParser('outdent')(codeblock);
codeblock = showdown.subParser('encodeCode')(codeblock);
codeblock = showdown.subParser('detab')(codeblock);
codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing newlines
if (options.omitExtraWLInCodeBlocks) {
end = '';
}
codeblock = '<pre><code>' + codeblock + end + '</code></pre>';
return showdown.subParser('hashBlock')(codeblock, options, globals) + nextChar;
});
// attacklab: strip sentinel
text = text.replace(/~0/, '');
text = globals.converter._dispatch('codeBlocks.after', text, options, globals);
return text;
});
/**
*
* * Backtick quotes are used for <code></code> spans.
*
* * You can use multiple backticks as the delimiters if you want to
* include literal backticks in the code span. So, this input:
*
* Just type ``foo `bar` baz`` at the prompt.
*
* Will translate to:
*
* <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
*
* There's no arbitrary limit to the number of backticks you
* can use as delimters. If you need three consecutive backticks
* in your code, use four for delimiters, etc.
*
* * You can use spaces to get literal backticks at the edges:
*
* ... type `` `bar` `` ...
*
* Turns to:
*
* ... type <code>`bar`</code> ...
*/
showdown.subParser('codeSpans', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('codeSpans.before', text, options, globals);
/*
text = text.replace(/
(^|[^\\]) // Character before opening ` can't be a backslash
(`+) // $2 = Opening run of `
( // $3 = The code block
[^\r]*?
[^`] // attacklab: work around lack of lookbehind
)
\2 // Matching closer
(?!`)
/gm, function(){...});
*/
if (typeof(text) === 'undefined') {
text = '';
}
text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
function (wholeMatch, m1, m2, m3) {
var c = m3;
c = c.replace(/^([ \t]*)/g, ''); // leading whitespace
c = c.replace(/[ \t]*$/g, ''); // trailing whitespace
c = showdown.subParser('encodeCode')(c);
return m1 + '<code>' + c + '</code>';
}
);
text = globals.converter._dispatch('codeSpans.after', text, options, globals);
return text;
});
/**
* Convert all tabs to spaces
*/
showdown.subParser('detab', function (text) {
'use strict';
// expand first n-1 tabs
text = text.replace(/\t(?=\t)/g, ' '); // g_tab_width
// replace the nth with two sentinels
text = text.replace(/\t/g, '~A~B');
// use the sentinel to anchor our regex so it doesn't explode
text = text.replace(/~B(.+?)~A/g, function (wholeMatch, m1) {
var leadingText = m1,
numSpaces = 4 - leadingText.length % 4; // g_tab_width
// there *must* be a better way to do this:
for (var i = 0; i < numSpaces; i++) {
leadingText += ' ';
}
return leadingText;
});
// clean up sentinels
text = text.replace(/~A/g, ' '); // g_tab_width
text = text.replace(/~B/g, '');
return text;
});
/**
* Smart processing for ampersands and angle brackets that need to be encoded.
*/
showdown.subParser('encodeAmpsAndAngles', function (text) {
'use strict';
// Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
// http://bumppo.net/projects/amputator/
text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, '&');
// Encode naked <'s
text = text.replace(/<(?![a-z\/?\$!])/gi, '<');
return text;
});
/**
* Returns the string, with after processing the following backslash escape sequences.
*
* attacklab: The polite way to do this is with the new escapeCharacters() function:
*
* text = escapeCharacters(text,"\\",true);
* text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);
*
* ...but we're sidestepping its use of the (slow) RegExp constructor
* as an optimization for Firefox. This function gets called a LOT.
*/
showdown.subParser('encodeBackslashEscapes', function (text) {
'use strict';
text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g, showdown.helper.escapeCharactersCallback);
return text;
});
/**
* Encode/escape certain characters inside Markdown code runs.
* The point is that in code, these characters are literals,
* and lose their special Markdown meanings.
*/
showdown.subParser('encodeCode', function (text) {
'use strict';
// Encode all ampersands; HTML entities are not
// entities within a Markdown code span.
text = text.replace(/&/g, '&');
// Do the angle bracket song and dance:
text = text.replace(/</g, '<');
text = text.replace(/>/g, '>');
// Now, escape characters that are magic in Markdown:
text = showdown.helper.escapeCharacters(text, '*_{}[]\\', false);
// jj the line above breaks this:
//---
//* Item
// 1. Subitem
// special char: *
// ---
return text;
});
/**
* Input: an email address, e.g. "foo@example.com"
*
* Output: the email address as a mailto link, with each character
* of the address encoded as either a decimal or hex entity, in
* the hopes of foiling most address harvesting spam bots. E.g.:
*
* <a href="mailto:foo@e
* xample.com">foo
* @example.com</a>
*
* Based on a filter by Matthew Wickline, posted to the BBEdit-Talk
* mailing list: <http://tinyurl.com/yu7ue>
*
*/
showdown.subParser('encodeEmailAddress', function (addr) {
'use strict';
var encode = [
function (ch) {
return '&#' + ch.charCodeAt(0) + ';';
},
function (ch) {
return '&#x' + ch.charCodeAt(0).toString(16) + ';';
},
function (ch) {
return ch;
}
];
addr = 'mailto:' + addr;
addr = addr.replace(/./g, function (ch) {
if (ch === '@') {
// this *must* be encoded. I insist.
ch = encode[Math.floor(Math.random() * 2)](ch);
} else if (ch !== ':') {
// leave ':' alone (to spot mailto: later)
var r = Math.random();
// roughly 10% raw, 45% hex, 45% dec
ch = (
r > 0.9 ? encode[2](ch) : r > 0.45 ? encode[1](ch) : encode[0](ch)
);
}
return ch;
});
addr = '<a href="' + addr + '">' + addr + '</a>';
addr = addr.replace(/">.+:/g, '">'); // strip the mailto: from the visible part
return addr;
});
/**
* Within tags -- meaning between < and > -- encode [\ ` * _] so they
* don't conflict with their use in Markdown for code, italics and strong.
*/
showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text) {
'use strict';
// Build a regex to find HTML tags and comments. See Friedl's
// "Mastering Regular Expressions", 2nd Ed., pp. 200-201.
var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi;
text = text.replace(regex, function (wholeMatch) {
var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g, '$1`');
tag = showdown.helper.escapeCharacters(tag, '\\`*_', false);
return tag;
});
return text;
});
/**
* Handle github codeblocks prior to running HashHTML so that
* HTML contained within the codeblock gets escaped properly
* Example:
* ```ruby
* def hello_world(x)
* puts "Hello, #{x}"
* end
* ```
*/
showdown.subParser('githubCodeBlocks', function (text, options, globals) {
'use strict';
// early exit if option is not enabled
if (!options.ghCodeBlocks) {
return text;
}
text = globals.converter._dispatch('githubCodeBlocks.before', text, options, globals);
text += '~0';
text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, language, codeblock) {
var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';
// First parse the github code block
codeblock = showdown.subParser('encodeCode')(codeblock);
codeblock = showdown.subParser('detab')(codeblock);
codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace
codeblock = '<pre><code' + (language ? ' class="' + language + ' language-' + language + '"' : '') + '>' + codeblock + end + '</code></pre>';
codeblock = showdown.subParser('hashBlock')(codeblock, options, globals);
// Since GHCodeblocks can be false positives, we need to
// store the primitive text and the parsed text in a global var,
// and then return a token
return '\n\n~G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
});
// attacklab: strip sentinel
text = text.replace(/~0/, '');
return globals.converter._dispatch('githubCodeBlocks.after', text, options, globals);
});
showdown.subParser('hashBlock', function (text, options, globals) {
'use strict';
text = text.replace(/(^\n+|\n+$)/g, '');
return '\n\n~K' + (globals.gHtmlBlocks.push(text) - 1) + 'K\n\n';
});
showdown.subParser('hashElement', function (text, options, globals) {
'use strict';
return function (wholeMatch, m1) {
var blockText = m1;
// Undo double lines
blockText = blockText.replace(/\n\n/g, '\n');
blockText = blockText.replace(/^\n/, '');
// strip trailing blank lines
blockText = blockText.replace(/\n+$/g, '');
// Replace the element text with a marker ("~KxK" where x is its key)
blockText = '\n\n~K' + (globals.gHtmlBlocks.push(blockText) - 1) + 'K\n\n';
return blockText;
};
});
showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
'use strict';
var blockTags = [
'pre',
'div',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'blockquote',
'table',
'dl',
'ol',
'ul',
'script',
'noscript',
'form',
'fieldset',
'iframe',
'math',
'style',
'section',
'header',
'footer',
'nav',
'article',
'aside',
'address',
'audio',
'canvas',
'figure',
'hgroup',
'output',
'video',
'p'
],
repFunc = function (wholeMatch, match, left, right) {
var txt = wholeMatch;
// check if this html element is marked as markdown
// if so, it's contents should be parsed as markdown
if (left.search(/\bmarkdown\b/) !== -1) {
txt = left + globals.converter.makeHtml(match) + right;
}
return '\n\n~K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
};
for (var i = 0; i < blockTags.length; ++i) {
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^(?: |\\t){0,3}<' + blockTags[i] + '\\b[^>]*>', '</' + blockTags[i] + '>', 'gim');
}
// HR SPECIAL CASE
text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,
showdown.subParser('hashElement')(text, options, globals));
// Special case for standalone HTML comments:
text = text.replace(/(<!--[\s\S]*?-->)/g,
showdown.subParser('hashElement')(text, options, globals));
// PHP and ASP-style processor instructions (<?...?> and <%...%>)
text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
showdown.subParser('hashElement')(text, options, globals));
return text;
});
/**
* Hash span elements that should not be parsed as markdown
*/
showdown.subParser('hashHTMLSpans', function (text, config, globals) {
'use strict';
var matches = showdown.helper.matchRecursiveRegExp(text, '<code\\b[^>]*>', '</code>', 'gi');
for (var i = 0; i < matches.length; ++i) {
text = text.replace(matches[i][0], '~L' + (globals.gHtmlSpans.push(matches[i][0]) - 1) + 'L');
}
return text;
});
/**
* Unhash HTML spans
*/
showdown.subParser('unhashHTMLSpans', function (text, config, globals) {
'use strict';
for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
text = text.replace('~L' + i + 'L', globals.gHtmlSpans[i]);
}
return text;
});
/**
* Hash span elements that should not be parsed as markdown
*/
showdown.subParser('hashPreCodeTags', function (text, config, globals) {
'use strict';
var repFunc = function (wholeMatch, match, left, right) {
// encode html entities
var codeblock = left + showdown.subParser('encodeCode')(match) + right;
return '\n\n~G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
};
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^(?: |\\t){0,3}<pre\\b[^>]*>\\s*<code\\b[^>]*>', '^(?: |\\t){0,3}</code>\\s*</pre>', 'gim');
return text;
});
showdown.subParser('headers', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('headers.before', text, options, globals);
var prefixHeader = options.prefixHeaderId,
headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart),
// Set text-style headers:
// Header 1
// ========
//
// Header 2
// --------
//
setextRegexH1 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n={2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n=+[ \t]*\n+/gm,
setextRegexH2 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n-{2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n-+[ \t]*\n+/gm;
text = text.replace(setextRegexH1, function (wholeMatch, m1) {
var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
hLevel = headerLevelStart,
hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
return showdown.subParser('hashBlock')(hashBlock, options, globals);
});
text = text.replace(setextRegexH2, function (matchFound, m1) {
var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
hLevel = headerLevelStart + 1,
hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
return showdown.subParser('hashBlock')(hashBlock, options, globals);
});
// atx-style headers:
// # Header 1
// ## Header 2
// ## Header 2 with closing hashes ##
// ...
// ###### Header 6
//
text = text.replace(/^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm, function (wholeMatch, m1, m2) {
var span = showdown.subParser('spanGamut')(m2, options, globals),
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
hLevel = headerLevelStart - 1 + m1.length,
header = '<h' + hLevel + hID + '>' + span + '</h' + hLevel + '>';
return showdown.subParser('hashBlock')(header, options, globals);
});
function headerId(m) {
var title, escapedId = m.replace(/[^\w]/g, '').toLowerCase();
if (globals.hashLinkCounts[escapedId]) {
title = escapedId + '-' + (globals.hashLinkCounts[escapedId]++);
} else {
title = escapedId;
globals.hashLinkCounts[escapedId] = 1;
}
// Prefix id to prevent causing inadvertent pre-existing style matches.
if (prefixHeader === true) {
prefixHeader = 'section';
}
if (showdown.helper.isString(prefixHeader)) {
return prefixHeader + title;
}
return title;
}
text = globals.converter._dispatch('headers.after', text, options, globals);
return text;
});
/**
* Turn Markdown image shortcuts into <img> tags.
*/
showdown.subParser('images', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('images.before', text, options, globals);
var inlineRegExp = /!\[(.*?)]\s?\([ \t]*()<?(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g,
referenceRegExp = /!\[([^\]]*?)] ?(?:\n *)?\[(.*?)]()()()()()/g;
function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) {
var gUrls = globals.gUrls,
gTitles = globals.gTitles,
gDims = globals.gDimensions;
linkId = linkId.toLowerCase();
if (!title) {
title = '';
}
if (url === '' || url === null) {
if (linkId === '' || linkId === null) {
// lower-case and turn embedded newlines into spaces
linkId = altText.toLowerCase().replace(/ ?\n/g, ' ');
}
url = '#' + linkId;
if (!showdown.helper.isUndefined(gUrls[linkId])) {
url = gUrls[linkId];
if (!showdown.helper.isUndefined(gTitles[linkId])) {
title = gTitles[linkId];
}
if (!showdown.helper.isUndefined(gDims[linkId])) {
width = gDims[linkId].width;
height = gDims[linkId].height;
}
} else {
return wholeMatch;
}
}
altText = altText.replace(/"/g, '"');
altText = showdown.helper.escapeCharacters(altText, '*_', false);
url = showdown.helper.escapeCharacters(url, '*_', false);
var result = '<img src="' + url + '" alt="' + altText + '"';
if (title) {
title = title.replace(/"/g, '"');
title = showdown.helper.escapeCharacters(title, '*_', false);
result += ' title="' + title + '"';
}
if (width && height) {
width = (width === '*') ? 'auto' : width;
height = (height === '*') ? 'auto' : height;
result += ' width="' + width + '"';
result += ' height="' + height + '"';
}
result += ' />';
return result;
}
// First, handle reference-style labeled images: ![alt text][id]
text = text.replace(referenceRegExp, writeImageTag);
// Next, handle inline images: 
text = text.replace(inlineRegExp, writeImageTag);
text = globals.converter._dispatch('images.after', text, options, globals);
return text;
});
showdown.subParser('italicsAndBold', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('italicsAndBold.before', text, options, globals);
if (options.literalMidWordUnderscores) {
//underscores
// Since we are consuming a \s character, we need to add it
text = text.replace(/(^|\s|>|\b)__(?=\S)([\s\S]+?)__(?=\b|<|\s|$)/gm, '$1<strong>$2</strong>');
text = text.replace(/(^|\s|>|\b)_(?=\S)([\s\S]+?)_(?=\b|<|\s|$)/gm, '$1<em>$2</em>');
//asterisks
text = text.replace(/(\*\*)(?=\S)([^\r]*?\S[*]*)\1/g, '<strong>$2</strong>');
text = text.replace(/(\*)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>');
} else {
// <strong> must go first:
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, '<strong>$2</strong>');
text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>');
}
text = globals.converter._dispatch('italicsAndBold.after', text, options, globals);
return text;
});
/**
* Form HTML ordered (numbered) and unordered (bulleted) lists.
*/
showdown.subParser('lists', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('lists.before', text, options, globals);
/**
* Process the contents of a single ordered or unordered list, splitting it
* into individual list items.
* @param {string} listStr
* @param {boolean} trimTrailing
* @returns {string}
*/
function processListItems (listStr, trimTrailing) {
// The $g_list_level global keeps track of when we're inside a list.
// Each time we enter a list, we increment it; when we leave a list,
// we decrement. If it's zero, we're not in a list anymore.
//
// We do this because when we're not inside a list, we want to treat
// something like this:
//
// I recommend upgrading to version
// 8. Oops, now this line is treated
// as a sub-list.
//
// As a single paragraph, despite the fact that the second line starts
// with a digit-period-space sequence.
//
// Whereas when we're inside a list (or sub-list), that line will be
// treated as the start of a sub-list. What a kludge, huh? This is
// an aspect of Markdown's syntax that's hard to parse perfectly
// without resorting to mind-reading. Perhaps the solution is to
// change the syntax rules such that sub-lists must start with a
// starting cardinal number; e.g. "1." or "a.".
globals.gListLevel++;
// trim trailing blank lines:
listStr = listStr.replace(/\n{2,}$/, '\n');
// attacklab: add sentinel to emulate \z
listStr += '~0';
var rgx = /(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm,
isParagraphed = (/\n[ \t]*\n(?!~0)/.test(listStr));
listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) {
checked = (checked && checked.trim() !== '');
var item = showdown.subParser('outdent')(m4, options, globals),
bulletStyle = '';
// Support for github tasklists
if (taskbtn && options.tasklists) {
bulletStyle = ' class="task-list-item" style="list-style-type: none;"';
item = item.replace(/^[ \t]*\[(x|X| )?]/m, function () {
var otp = '<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"';
if (checked) {
otp += ' checked';
}
otp += '>';
return otp;
});
}
// m1 - Leading line or
// Has a double return (multi paragraph) or
// Has sublist
if (m1 || (item.search(/\n{2,}/) > -1)) {
item = showdown.subParser('githubCodeBlocks')(item, options, globals);
item = showdown.subParser('blockGamut')(item, options, globals);
} else {
// Recursion for sub-lists:
item = showdown.subParser('lists')(item, options, globals);
item = item.replace(/\n$/, ''); // chomp(item)
if (isParagraphed) {
item = showdown.subParser('paragraphs')(item, options, globals);
} else {
item = showdown.subParser('spanGamut')(item, options, globals);
}
}
item = '\n<li' + bulletStyle + '>' + item + '</li>\n';
return item;
});
// attacklab: strip sentinel
listStr = listStr.replace(/~0/g, '');
globals.gListLevel--;
if (trimTrailing) {
listStr = listStr.replace(/\s+$/, '');
}
return listStr;
}
/**
* Check and parse consecutive lists (better fix for issue #142)
* @param {string} list
* @param {string} listType
* @param {boolean} trimTrailing
* @returns {string}
*/
function parseConsecutiveLists(list, listType, trimTrailing) {
// check if we caught 2 or more consecutive lists by mistake
// we use the counterRgx, meaning if listType is UL we look for UL and vice versa
var counterRxg = (listType === 'ul') ? /^ {0,2}\d+\.[ \t]/gm : /^ {0,2}[*+-][ \t]/gm,
subLists = [],
result = '';
if (list.search(counterRxg) !== -1) {
(function parseCL(txt) {
var pos = txt.search(counterRxg);
if (pos !== -1) {
// slice
result += '\n\n<' + listType + '>' + processListItems(txt.slice(0, pos), !!trimTrailing) + '</' + listType + '>\n\n';
// invert counterType and listType
listType = (listType === 'ul') ? 'ol' : 'ul';
counterRxg = (listType === 'ul') ? /^ {0,2}\d+\.[ \t]/gm : /^ {0,2}[*+-][ \t]/gm;
//recurse
parseCL(txt.slice(pos));
} else {
result += '\n\n<' + listType + '>' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n\n';
}
})(list);
for (var i = 0; i < subLists.length; ++i) {
}
} else {
result = '\n\n<' + listType + '>' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n\n';
}
return result;
}
// attacklab: add sentinel to hack around khtml/safari bug:
// http://bugs.webkit.org/show_bug.cgi?id=11231
text += '~0';
// Re-usable pattern to match any entire ul or ol list:
var wholeList = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
if (globals.gListLevel) {
text = text.replace(wholeList, function (wholeMatch, list, m2) {
var listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
return parseConsecutiveLists(list, listType, true);
});
} else {
wholeList = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
//wholeList = /(\n\n|^\n?)( {0,3}([*+-]|\d+\.)[ \t]+[\s\S]+?)(?=(~0)|(\n\n(?!\t| {2,}| {0,3}([*+-]|\d+\.)[ \t])))/g;
text = text.replace(wholeList, function (wholeMatch, m1, list, m3) {
var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
return parseConsecutiveLists(list, listType);
});
}
// attacklab: strip sentinel
text = text.replace(/~0/, '');
text = globals.converter._dispatch('lists.after', text, options, globals);
return text;
});
/**
* Remove one level of line-leading tabs or spaces
*/
showdown.subParser('outdent', function (text) {
'use strict';
// attacklab: hack around Konqueror 3.5.4 bug:
// "----------bug".replace(/^-/g,"") == "bug"
text = text.replace(/^(\t|[ ]{1,4})/gm, '~0'); // attacklab: g_tab_width
// attacklab: clean up hack
text = text.replace(/~0/g, '');
return text;
});
/**
*
*/
showdown.subParser('paragraphs', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('paragraphs.before', text, options, globals);
// Strip leading and trailing lines:
text = text.replace(/^\n+/g, '');
text = text.replace(/\n+$/g, '');
var grafs = text.split(/\n{2,}/g),
grafsOut = [],
end = grafs.length; // Wrap <p> tags
for (var i = 0; i < end; i++) {
var str = grafs[i];
// if this is an HTML marker, copy it
if (str.search(/~(K|G)(\d+)\1/g) >= 0) {
grafsOut.push(str);
} else {
str = showdown.subParser('spanGamut')(str, options, globals);
str = str.replace(/^([ \t]*)/g, '<p>');
str += '</p>';
grafsOut.push(str);
}
}
/** Unhashify HTML blocks */
end = grafsOut.length;
for (i = 0; i < end; i++) {
var blockText = '',
grafsOutIt = grafsOut[i],
codeFlag = false;
// if this is a marker for an html block...
while (grafsOutIt.search(/~(K|G)(\d+)\1/) >= 0) {
var delim = RegExp.$1,
num = RegExp.$2;
if (delim === 'K') {
blockText = globals.gHtmlBlocks[num];
} else {
// we need to check if ghBlock is a false positive
if (codeFlag) {
// use encoded version of all text
blockText = showdown.subParser('encodeCode')(globals.ghCodeBlocks[num].text);
} else {
blockText = globals.ghCodeBlocks[num].codeblock;
}
}
blockText = blockText.replace(/\$/g, '$$$$'); // Escape any dollar signs
grafsOutIt = grafsOutIt.replace(/(\n\n)?~(K|G)\d+\2(\n\n)?/, blockText);
// Check if grafsOutIt is a pre->code
if (/^<pre\b[^>]*>\s*<code\b[^>]*>/.test(grafsOutIt)) {
codeFlag = true;
}
}
grafsOut[i] = grafsOutIt;
}
text = grafsOut.join('\n\n');
// Strip leading and trailing lines:
text = text.replace(/^\n+/g, '');
text = text.replace(/\n+$/g, '');
return globals.converter._dispatch('paragraphs.after', text, options, globals);
});
/**
* Run extension
*/
showdown.subParser('runExtension', function (ext, text, options, globals) {
'use strict';
if (ext.filter) {
text = ext.filter(text, globals.converter, options);
} else if (ext.regex) {
// TODO remove this when old extension loading mechanism is deprecated
var re = ext.regex;
if (!re instanceof RegExp) {
re = new RegExp(re, 'g');
}
text = text.replace(re, ext.replace);
}
return text;
});
/**
* These are all the transformations that occur *within* block-level
* tags like paragraphs, headers, and list items.
*/
showdown.subParser('spanGamut', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('spanGamut.before', text, options, globals);
text = showdown.subParser('codeSpans')(text, options, globals);
text = showdown.subParser('escapeSpecialCharsWithinTagAttributes')(text, options, globals);
text = showdown.subParser('encodeBackslashEscapes')(text, options, globals);
// Process anchor and image tags. Images must come first,
// because ![foo][f] looks like an anchor.
text = showdown.subParser('images')(text, options, globals);
text = showdown.subParser('anchors')(text, options, globals);
// Make links out of things like `<http://example.com/>`
// Must come after _DoAnchors(), because you can use < and >
// delimiters in inline links like [this](<url>).
text = showdown.subParser('autoLinks')(text, options, globals);
text = showdown.subParser('encodeAmpsAndAngles')(text, options, globals);
text = showdown.subParser('italicsAndBold')(text, options, globals);
text = showdown.subParser('strikethrough')(text, options, globals);
// Do hard breaks:
text = text.replace(/ +\n/g, ' <br />\n');
text = globals.converter._dispatch('spanGamut.after', text, options, globals);
return text;
});
showdown.subParser('strikethrough', function (text, options, globals) {
'use strict';
if (options.strikethrough) {
text = globals.converter._dispatch('strikethrough.before', text, options, globals);
text = text.replace(/(?:~T){2}([\s\S]+?)(?:~T){2}/g, '<del>$1</del>');
text = globals.converter._dispatch('strikethrough.after', text, options, globals);
}
return text;
});
/**
* Strip any lines consisting only of spaces and tabs.
* This makes subsequent regexs easier to write, because we can
* match consecutive blank lines with /\n+/ instead of something
* contorted like /[ \t]*\n+/
*/
showdown.subParser('stripBlankLines', function (text) {
'use strict';
return text.replace(/^[ \t]+$/mg, '');
});
/**
* Strips link definitions from text, stores the URLs and titles in
* hash references.
* Link defs are in the form: ^[id]: url "optional title"
*
* ^[ ]{0,3}\[(.+)\]: // id = $1 attacklab: g_tab_width - 1
* [ \t]*
* \n? // maybe *one* newline
* [ \t]*
* <?(\S+?)>? // url = $2
* [ \t]*
* \n? // maybe one newline
* [ \t]*
* (?:
* (\n*) // any lines skipped = $3 attacklab: lookbehind removed
* ["(]
* (.+?) // title = $4
* [")]
* [ \t]*
* )? // title is optional
* (?:\n+|$)
* /gm,
* function(){...});
*
*/
showdown.subParser('stripLinkDefinitions', function (text, options, globals) {
'use strict';
var regex = /^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*<?(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n+|(?=~0))/gm;
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
text += '~0';
text = text.replace(regex, function (wholeMatch, linkId, url, width, height, blankLines, title) {
linkId = linkId.toLowerCase();
globals.gUrls[linkId] = showdown.subParser('encodeAmpsAndAngles')(url); // Link IDs are case-insensitive
if (blankLines) {
// Oops, found blank lines, so it's not a title.
// Put back the parenthetical statement we stole.
return blankLines + title;
} else {
if (title) {
globals.gTitles[linkId] = title.replace(/"|'/g, '"');
}
if (options.parseImgDimensions && width && height) {
globals.gDimensions[linkId] = {
width: width,
height: height
};
}
}
// Completely remove the definition from the text
return '';
});
// attacklab: strip sentinel
text = text.replace(/~0/, '');
return text;
});
showdown.subParser('tables', function (text, options, globals) {
'use strict';
if (!options.tables) {
return text;
}
var tableRgx = /^[ \t]{0,3}\|?.+\|.+\n[ \t]{0,3}\|?[ \t]*:?[ \t]*(?:-|=){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:-|=){2,}[\s\S]+?(?:\n\n|~0)/gm;
function parseStyles(sLine) {
if (/^:[ \t]*--*$/.test(sLine)) {
return ' style="text-align:left;"';
} else if (/^--*[ \t]*:[ \t]*$/.test(sLine)) {
return ' style="text-align:right;"';
} else if (/^:[ \t]*--*[ \t]*:$/.test(sLine)) {
return ' style="text-align:center;"';
} else {
return '';
}
}
function parseHeaders(header, style) {
var id = '';
header = header.trim();
if (options.tableHeaderId) {
id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"';
}
header = showdown.subParser('spanGamut')(header, options, globals);
return '<th' + id + style + '>' + header + '</th>\n';
}
function parseCells(cell, style) {
var subText = showdown.subParser('spanGamut')(cell, options, globals);
return '<td' + style + '>' + subText + '</td>\n';
}
function buildTable(headers, cells) {
var tb = '<table>\n<thead>\n<tr>\n',
tblLgn = headers.length;
for (var i = 0; i < tblLgn; ++i) {
tb += headers[i];
}
tb += '</tr>\n</thead>\n<tbody>\n';
for (i = 0; i < cells.length; ++i) {
tb += '<tr>\n';
for (var ii = 0; ii < tblLgn; ++ii) {
tb += cells[i][ii];
}
tb += '</tr>\n';
}
tb += '</tbody>\n</table>\n';
return tb;
}
text = globals.converter._dispatch('tables.before', text, options, globals);
text = text.replace(tableRgx, function (rawTable) {
var i, tableLines = rawTable.split('\n');
// strip wrong first and last column if wrapped tables are used
for (i = 0; i < tableLines.length; ++i) {
if (/^[ \t]{0,3}\|/.test(tableLines[i])) {
tableLines[i] = tableLines[i].replace(/^[ \t]{0,3}\|/, '');
}
if (/\|[ \t]*$/.test(tableLines[i])) {
tableLines[i] = tableLines[i].replace(/\|[ \t]*$/, '');
}
}
var rawHeaders = tableLines[0].split('|').map(function (s) { return s.trim();}),
rawStyles = tableLines[1].split('|').map(function (s) { return s.trim();}),
rawCells = [],
headers = [],
styles = [],
cells = [];
tableLines.shift();
tableLines.shift();
for (i = 0; i < tableLines.length; ++i) {
if (tableLines[i].trim() === '') {
continue;
}
rawCells.push(
tableLines[i]
.split('|')
.map(function (s) {
return s.trim();
})
);
}
if (rawHeaders.length < rawStyles.length) {
return rawTable;
}
for (i = 0; i < rawStyles.length; ++i) {
styles.push(parseStyles(rawStyles[i]));
}
for (i = 0; i < rawHeaders.length; ++i) {
if (showdown.helper.isUndefined(styles[i])) {
styles[i] = '';
}
headers.push(parseHeaders(rawHeaders[i], styles[i]));
}
for (i = 0; i < rawCells.length; ++i) {
var row = [];
for (var ii = 0; ii < headers.length; ++ii) {
if (showdown.helper.isUndefined(rawCells[i][ii])) {
}
row.push(parseCells(rawCells[i][ii], styles[ii]));
}
cells.push(row);
}
return buildTable(headers, cells);
});
text = globals.converter._dispatch('tables.after', text, options, globals);
return text;
});
/**
* Swap back in all the special characters we've hidden.
*/
showdown.subParser('unescapeSpecialChars', function (text) {
'use strict';
text = text.replace(/~E(\d+)E/g, function (wholeMatch, m1) {
var charCodeToReplace = parseInt(m1);
return String.fromCharCode(charCodeToReplace);
});
return text;
});
module.exports = showdown;
================================================
FILE: lib/wxParse/wxDiscode.js
================================================
// HTML 支持的数学符号
function strNumDiscode(str){
str = str.replace(/∀/g, '∀');
str = str.replace(/∂/g, '∂');
str = str.replace(/&exists;/g, '∃');
str = str.replace(/∅/g, '∅');
str = str.replace(/∇/g, '∇');
str = str.replace(/∈/g, '∈');
str = str.replace(/∉/g, '∉');
str = str.replace(/∋/g, '∋');
str = str.replace(/∏/g, '∏');
str = str.replace(/∑/g, '∑');
str = str.replace(/−/g, '−');
str = str.replace(/∗/g, '∗');
str = str.replace(/√/g, '√');
str = str.replace(/∝/g, '∝');
str = str.replace(/∞/g, '∞');
str = str.replace(/∠/g, '∠');
str = str.replace(/∧/g, '∧');
str = str.replace(/∨/g, '∨');
str = str.replace(/∩/g, '∩');
str = str.replace(/∩/g, '∪');
str = str.replace(/∫/g, '∫');
str = str.replace(/∴/g, '∴');
str = str.replace(/∼/g, '∼');
str = str.replace(/≅/g, '≅');
str = str.replace(/≈/g, '≈');
str = str.replace(/≠/g, '≠');
str = str.replace(/≤/g, '≤');
str = str.replace(/≥/g, '≥');
str = str.replace(/⊂/g, '⊂');
str = str.replace(/⊃/g, '⊃');
str = str.replace(/⊄/g, '⊄');
str = str.replace(/⊆/g, '⊆');
str = str.replace(/⊇/g, '⊇');
str = str.replace(/⊕/g, '⊕');
str = str.replace(/⊗/g, '⊗');
str = str.replace(/⊥/g, '⊥');
str = str.replace(/⋅/g, '⋅');
return str;
}
//HTML 支持的希腊字母
function strGreeceDiscode(str){
str = str.replace(/Α/g, 'Α');
str = str.replace(/Β/g, 'Β');
str = str.replace(/Γ/g, 'Γ');
str = str.replace(/Δ/g, 'Δ');
str = str.replace(/Ε/g, 'Ε');
str = str.replace(/Ζ/g, 'Ζ');
str = str.replace(/Η/g, 'Η');
str = str.replace(/Θ/g, 'Θ');
str = str.replace(/Ι/g, 'Ι');
str = str.replace(/Κ/g, 'Κ');
str = str.replace(/Λ/g, 'Λ');
str = str.replace(/Μ/g, 'Μ');
str = str.replace(/Ν/g, 'Ν');
str = str.replace(/Ξ/g, 'Ν');
str = str.replace(/Ο/g, 'Ο');
str = str.replace(/Π/g, 'Π');
str = str.replace(/Ρ/g, 'Ρ');
str = str.replace(/Σ/g, 'Σ');
str = str.replace(/Τ/g, 'Τ');
str = str.replace(/Υ/g, 'Υ');
str = str.replace(/Φ/g, 'Φ');
str = str.replace(/Χ/g, 'Χ');
str = str.replace(/Ψ/g, 'Ψ');
str = str.replace(/Ω/g, 'Ω');
str = str.replace(/α/g, 'α');
str = str.replace(/β/g, 'β');
str = str.replace(/γ/g, 'γ');
str = str.replace(/δ/g, 'δ');
str = str.replace(/ε/g, 'ε');
str = str.replace(/ζ/g, 'ζ');
str = str.replace(/η/g, 'η');
str = str.replace(/θ/g, 'θ');
str = str.replace(/ι/g, 'ι');
str = str.replace(/κ/g, 'κ');
str = str.replace(/λ/g, 'λ');
str = str.replace(/μ/g, 'μ');
str = str.replace(/ν/g, 'ν');
str = str.replace(/ξ/g, 'ξ');
str = str.replace(/ο/g, 'ο');
str = str.replace(/π/g, 'π');
str = str.replace(/ρ/g, 'ρ');
str = str.replace(/ς/g, 'ς');
str = str.replace(/σ/g, 'σ');
str = str.replace(/τ/g, 'τ');
str = str.replace(/υ/g, 'υ');
str = str.replace(/φ/g, 'φ');
str = str.replace(/χ/g, 'χ');
str = str.replace(/ψ/g, 'ψ');
str = str.replace(/ω/g, 'ω');
str = str.replace(/ϑ/g, 'ϑ');
str = str.replace(/ϒ/g, 'ϒ');
str = str.replace(/ϖ/g, 'ϖ');
str = str.replace(/·/g, '·');
return str;
}
//
function strcharacterDiscode(str){
// 加入常用解析
str = str.replace(/ /g, ' ');
str = str.replace(/"/g, '"');
str = str.replace(/&/g, '&');
// str = str.replace(/</g, '‹');
// str = str.replace(/>/g, '›');
str = str.replace(/</g, '<');
str = str.replace(/>/g, '>');
return str;
}
// HTML 支持的其他实体
function strOtherDiscode(str){
str = str.replace(/Œ/g, 'Œ');
str = str.replace(/œ/g, 'œ');
str = str.replace(/Š/g, 'Š');
str = str.replace(/š/g, 'š');
str = str.replace(/Ÿ/g, 'Ÿ');
str = str.replace(/ƒ/g, 'ƒ');
str = str.replace(/ˆ/g, 'ˆ');
str = str.replace(/˜/g, '˜');
str = str.replace(/ /g, '');
str = str.replace(/ /g, '');
str = str.replace(/ /g, '');
str = str.replace(/‌/g, '');
str = str.replace(/‍/g, '');
str = str.replace(/‎/g, '');
str = str.replace(/‏/g, '');
str = str.replace(/–/g, '–');
str = str.replace(/—/g, '—');
str = str.replace(/‘/g, '‘');
str = str.replace(/’/g, '’');
str = str.replace(/‚/g, '‚');
str = str.replace(/“/g, '“');
str = str.replace(/”/g, '”');
str = str.replace(/„/g, '„');
str = str.replace(/†/g, '†');
str = str.replace(/‡/g, '‡');
str = str.replace(/•/g, '•');
str = str.replace(/…/g, '…');
str = str.replace(/‰/g, '‰');
str = str.replace(/′/g, '′');
str = str.replace(/″/g, '″');
str = str.replace(/‹/g, '‹');
str = str.replace(/›/g, '›');
str = str.replace(/‾/g, '‾');
str = str.replace(/€/g, '€');
str = str.replace(/™/g, '™');
str = str.replace(/←/g, '←');
str = str.replace(/↑/g, '↑');
str = str.replace(/→/g, '→');
str = str.replace(/↓/g, '↓');
str = str.replace(/↔/g, '↔');
str = str.replace(/↵/g, '↵');
str = str.replace(/⌈/g, '⌈');
str = str.replace(/⌉/g, '⌉');
str = str.replace(/⌊/g, '⌊');
str = str.replace(/⌋/g, '⌋');
str = str.replace(/◊/g, '◊');
str = str.replace(/♠/g, '♠');
str = str.replace(/♣/g, '♣');
str = str.replace(/♥/g, '♥');
str = str.replace(/♦/g, '♦');
return str;
}
function strMoreDiscode(str){
str = str.replace(/\r\n/g,"");
str = str.replace(/\n/g,"");
str = str.replace(/code/g,"wxxxcode-style");
return str;
}
function strDiscode(str){
str = strNumDiscode(str);
str = strGreeceDiscode(str);
str = strcharacterDiscode(str);
str = strOtherDiscode(str);
str = strMoreDiscode(str);
return str;
}
function urlToHttpUrl(url,rep){
var patt1 = new RegExp("^//");
var result = patt1.test(url);
if(result){
url = rep+":"+url;
}
return url;
}
module.exports = {
strDiscode:strDiscode,
urlToHttpUrl:urlToHttpUrl
}
================================================
FILE: lib/wxParse/wxParse.js
================================================
/**
* author: Di (微信小程序开发工程师)
* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
* 垂直微信小程序开发交流社区
*
* github地址: https://github.com/icindy/wxParse
*
* for: 微信小程序富文本解析
* detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
*/
/**
* utils函数引入
**/
import showdown from 'showdown.js';
import HtmlToJson from 'html2json.js';
/**
* 配置及公有属性
**/
/**
* 主函数入口区
**/
function wxParse(bindName = 'wxParseData', type='html', data='<div class="color:red;">数据不能为空</div>', target,imagePadding) {
var that = target;
var transData = {};//存放转化后的数据
if (type == 'html') {
transData = HtmlToJson.html2json(data, bindName);
console.log(JSON.stringify(transData, ' ', ' '));
} else if (type == 'md' || type == 'markdown') {
var converter = new showdown.Converter();
var html = converter.makeHtml(data);
transData = HtmlToJson.html2json(html, bindName);
console.log(JSON.stringify(transData, ' ', ' '));
}
transData.view = {};
transData.view.imagePadding = 0;
if(typeof(imagePadding) != 'undefined'){
transData.view.imagePadding = imagePadding
}
var bindData = {};
bindData[bindName] = transData;
that.setData(bindData)
that.wxParseImgLoad = wxParseImgLoad;
that.wxParseImgTap = wxParseImgTap;
}
// 图片点击事件
function wxParseImgTap(e) {
var that = this;
var nowImgUrl = e.target.dataset.src;
var tagFrom = e.target.dataset.from;
if (typeof (tagFrom) != 'undefined' && tagFrom.length > 0) {
wx.previewImage({
current: nowImgUrl, // 当前显示图片的http链接
urls: that.data[tagFrom].imageUrls // 需要预览的图片http链接列表
})
}
}
/**
* 图片视觉宽高计算函数区
**/
function wxParseImgLoad(e) {
var that = this;
var tagFrom = e.target.dataset.from;
var idx = e.target.dataset.idx;
if (typeof (tagFrom) != 'undefined' && tagFrom.length > 0) {
calMoreImageInfo(e, idx, that, tagFrom)
}
}
// 假循环获取计算图片视觉最佳宽高
function calMoreImageInfo(e, idx, that, bindName) {
var temData = that.data[bindName];
if (temData.images.length == 0) {
return;
}
var temImages = temData.images;
//因为无法获取view宽度 需要自定义padding进行计算,稍后处理
var recal = wxAutoImageCal(e.detail.width, e.detail.height,that,bindName);
temImages[idx].width = recal.imageWidth;
temImages[idx].height = recal.imageheight;
temData.images = temImages;
var bindData = {};
bindData[bindName] = temData;
that.setData(bindData);
}
// 计算视觉优先的图片宽高
function wxAutoImageCal(originalWidth, originalHeight,that,bindName) {
//获取图片的原始长宽
var windowWidth = 0, windowHeight = 0;
var autoWidth = 0, autoHeight = 0;
var results = {};
wx.getSystemInfo({
success: function (res) {
var padding = that.data[bindName].view.imagePadding;
windowWidth = res.windowWidth-2*padding;
windowHeight = res.windowHeight;
//判断按照那种方式进行缩放
console.log("windowWidth" + windowWidth);
if (originalWidth > windowWidth) {//在图片width大于手机屏幕width时候
autoWidth = windowWidth;
console.log("autoWidth" + autoWidth);
autoHeight = (autoWidth * originalHeight) / originalWidth;
console.log("autoHeight" + autoHeight);
results.imageWidth = autoWidth;
results.imageheight = autoHeight;
} else {//否则展示原来的数据
results.imageWidth = originalWidth;
results.imageheight = originalHeight;
}
}
})
return results;
}
function wxParseTemArray(temArrayName,bindNameReg,total,that){
var array = [];
var temData = that.data;
var obj = null;
for(var i = 0; i < total; i++){
var simArr = temData[bindNameReg+i].nodes;
array.push(simArr);
}
temArrayName = temArrayName || 'wxParseTemArray';
obj = JSON.parse('{"'+ temArrayName +'":""}');
obj[temArrayName] = array;
that.setData(obj);
}
/**
* 配置emojis
*
*/
function emojisInit(reg='',baseSrc="/wxParse/emojis/",emojis){
HtmlToJson.emojisInit(reg,baseSrc,emojis);
}
module.exports = {
wxParse: wxParse,
wxParseTemArray:wxParseTemArray,
emojisInit:emojisInit
}
================================================
FILE: lib/wxParse/wxParse.wxml
================================================
<!--**
* author: Di (微信小程序开发工程师)
* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
* 垂直微信小程序开发交流社区
*
* github地址: https://github.com/icindy/wxParse
*
* for: 微信小程序富文本解析
* detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
*/-->
<!--基础元素-->
<template name="wxParseVideo">
<!--增加video标签支持,并循环添加-->
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<video class="{{item.classStr}} wxParse-{{item.tag}}-video" src="{{item.attr.src}}"></video>
</view>
</template>
<template name="wxParseImg">
<image class="{{item.classStr}} wxParse-{{item.tag}}" data-from="{{item.from}}" data-src="{{item.attr.src}}" data-idx="{{item.imgIndex}}" src="{{item.attr.src}}" mode="aspectFit" bindload="wxParseImgLoad" bindtap="wxParseImgTap" style="width:{{item.width}}px;height:{{item.height}}px;{{item.attr.style}}" />
</template>
<template name="WxEmojiView">
<view class="WxEmojiView wxParse-inline" style="{{item.styleStr}}">
<block wx:for="{{item.textArray}}" wx:key="">
<block class="{{item.text == '\\n' ? 'wxParse-hide':''}}" wx:if="{{item.node == 'text'}}">{{item.text}}</block>
<block wx:elif="{{item.node == 'element'}}">
<image class="wxEmoji" src="{{item.baseSrc}}{{item.text}}" />
</block>
</block>
</view>
</template>
<!--入口模版-->
<template name="wxParse">
<block wx:for="{{wxParseData}}" wx:key="">
<template is="wxParse0" data="{{item}}"/>
</block>
</template>
<!--循环模版-->
<template name="wxParse0">
<!--<template is="wxParse1" data="{{item}}" />-->
<!--判断是否是标签节点-->
<block wx:if="{{item.node == 'element'}}">
<block wx:if="{{item.tag == 'button'}}">
<button type="default" size="mini" >
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse1" data="{{item}}"/>
</block>
</button>
</block>
<!--li类型-->
<block wx:elif="{{item.tag == 'li'}}">
<view class="{{item.classStr}} wxParse-li">
<view class="{{item.classStr}} wxParse-li-inner">
<view class="{{item.classStr}} wxParse-li-text">
<view class="{{item.classStr}} wxParse-li-circle"></view>
</view>
<view class="{{item.classStr}} wxParse-li-text">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse1" data="{{item}}"/>
</block>
</view>
</view>
</view>
</block>
<!--video类型-->
<block wx:elif="{{item.tag == 'video'}}">
<template is="wxParseVideo" data="{{item}}"/>
</block>
<!--img类型-->
<block wx:elif="{{item.tag == 'img'}}">
<template is="wxParseImg" data="{{item}}"/>
</block>
<!--a类型-->
<block wx:elif="{{item.tag == 'a'}}">
<view bindtap="wxParseTagATap" class="wxParse-inline {{item.classStr}} wxParse-{{item.tag}}" data-c="{{item.attr.href}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse1" data="{{item}}"/>
</block>
</view>
</block>
<block wx:elif="{{item.tag == 'table'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse1" data="{{item}}"/>
</block>
</view>
</block>
<!--其他块级标签-->
<block wx:elif="{{item.tagType == 'block'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse1" data="{{item}}"/>
</block>
</view>
</block>
<!--内联标签-->
<view wx:else class="{{item.classStr}} wxParse-{{item.tag}} wxParse-{{item.tagType}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse1" data="{{item}}"/>
</block>
</view>
</block>
<!--判断是否是文本节点-->
<block wx:elif="{{item.node == 'text'}}">
<!--如果是,直接进行-->
<template is="WxEmojiView" data="{{item}}"/>
</block>
</template>
<!--循环模版-->
<template name="wxParse1">
<!--<template is="wxParse2" data="{{item}}" />-->
<!--判断是否是标签节点-->
<block wx:if="{{item.node == 'element'}}">
<block wx:if="{{item.tag == 'button'}}">
<button type="default" size="mini" >
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse2" data="{{item}}"/>
</block>
</button>
</block>
<!--li类型-->
<block wx:elif="{{item.tag == 'li'}}">
<view class="{{item.classStr}} wxParse-li">
<view class="{{item.classStr}} wxParse-li-inner">
<view class="{{item.classStr}} wxParse-li-text">
<view class="{{item.classStr}} wxParse-li-circle"></view>
</view>
<view class="{{item.classStr}} wxParse-li-text">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse2" data="{{item}}"/>
</block>
</view>
</view>
</view>
</block>
<!--video类型-->
<block wx:elif="{{item.tag == 'video'}}">
<template is="wxParseVideo" data="{{item}}"/>
</block>
<!--img类型-->
<block wx:elif="{{item.tag == 'img'}}">
<template is="wxParseImg" data="{{item}}"/>
</block>
<!--a类型-->
<block wx:elif="{{item.tag == 'a'}}">
<view bindtap="wxParseTagATap" class="wxParse-inline {{item.classStr}} wxParse-{{item.tag}}" data-src="{{item.attr.href}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse2" data="{{item}}"/>
</block>
</view>
</block>
<!--其他块级标签-->
<block wx:elif="{{item.tagType == 'block'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse2" data="{{item}}"/>
</block>
</view>
</block>
<!--内联标签-->
<view wx:else class="{{item.classStr}} wxParse-{{item.tag}} wxParse-{{item.tagType}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse2" data="{{item}}"/>
</block>
</view>
</block>
<!--判断是否是文本节点-->
<block wx:elif="{{item.node == 'text'}}">
<!--如果是,直接进行-->
<template is="WxEmojiView" data="{{item}}"/>
</block>
</template>
<!--循环模版-->
<template name="wxParse2">
<!--<template is="wxParse3" data="{{item}}" />-->
<!--判断是否是标签节点-->
<block wx:if="{{item.node == 'element'}}">
<block wx:if="{{item.tag == 'button'}}">
<button type="default" size="mini" >
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse3" data="{{item}}"/>
</block>
</button>
</block>
<!--li类型-->
<block wx:elif="{{item.tag == 'li'}}">
<view class="{{item.classStr}} wxParse-li">
<view class="{{item.classStr}} wxParse-li-inner">
<view class="{{item.classStr}} wxParse-li-text">
<view class="{{item.classStr}} wxParse-li-circle"></view>
</view>
<view class="{{item.classStr}} wxParse-li-text">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse3" data="{{item}}"/>
</block>
</view>
</view>
</view>
</block>
<!--video类型-->
<block wx:elif="{{item.tag == 'video'}}">
<template is="wxParseVideo" data="{{item}}"/>
</block>
<!--img类型-->
<block wx:elif="{{item.tag == 'img'}}">
<template is="wxParseImg" data="{{item}}"/>
</block>
<!--a类型-->
<block wx:elif="{{item.tag == 'a'}}">
<view bindtap="wxParseTagATap" class="wxParse-inline {{item.classStr}} wxParse-{{item.tag}}" data-src="{{item.attr.href}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse3" data="{{item}}"/>
</block>
</view>
</block>
<!--其他块级标签-->
<block wx:elif="{{item.tagType == 'block'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse3" data="{{item}}"/>
</block>
</view>
</block>
<!--内联标签-->
<view wx:else class="{{item.classStr}} wxParse-{{item.tag}} wxParse-{{item.tagType}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse3" data="{{item}}"/>
</block>
</view>
</block>
<!--判断是否是文本节点-->
<block wx:elif="{{item.node == 'text'}}">
<!--如果是,直接进行-->
<template is="WxEmojiView" data="{{item}}"/>
</block>
</template>
<!--循环模版-->
<template name="wxParse3">
<!--<template is="wxParse4" data="{{item}}" />-->
<!--判断是否是标签节点-->
<block wx:if="{{item.node == 'element'}}">
<block wx:if="{{item.tag == 'button'}}">
<button type="default" size="mini" >
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse4" data="{{item}}"/>
</block>
</button>
</block>
<!--li类型-->
<block wx:elif="{{item.tag == 'li'}}">
<view class="{{item.classStr}} wxParse-li">
<view class="{{item.classStr}} wxParse-li-inner">
<view class="{{item.classStr}} wxParse-li-text">
<view class="{{item.classStr}} wxParse-li-circle"></view>
</view>
<view class="{{item.classStr}} wxParse-li-text">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse4" data="{{item}}"/>
</block>
</view>
</view>
</view>
</block>
<!--video类型-->
<block wx:elif="{{item.tag == 'video'}}">
<template is="wxParseVideo" data="{{item}}"/>
</block>
<!--img类型-->
<block wx:elif="{{item.tag == 'img'}}">
<template is="wxParseImg" data="{{item}}"/>
</block>
<!--a类型-->
<block wx:elif="{{item.tag == 'a'}}">
<view bindtap="wxParseTagATap" class="wxParse-inline {{item.classStr}} wxParse-{{item.tag}}" data-src="{{item.attr.href}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse4" data="{{item}}"/>
</block>
</view>
</block>
<!--其他块级标签-->
<block wx:elif="{{item.tagType == 'block'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse4" data="{{item}}"/>
</block>
</view>
</block>
<!--内联标签-->
<view wx:else class="{{item.classStr}} wxParse-{{item.tag}} wxParse-{{item.tagType}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse4" data="{{item}}"/>
</block>
</view>
</block>
<!--判断是否是文本节点-->
<block wx:elif="{{item.node == 'text'}}">
<!--如果是,直接进行-->
<template is="WxEmojiView" data="{{item}}"/>
</block>
</template>
<!--循环模版-->
<template name="wxParse4">
<!--<template is="wxParse5" data="{{item}}" />-->
<!--判断是否是标签节点-->
<block wx:if="{{item.node == 'element'}}">
<block wx:if="{{item.tag == 'button'}}">
<button type="default" size="mini" >
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse5" data="{{item}}"/>
</block>
</button>
</block>
<!--li类型-->
<block wx:elif="{{item.tag == 'li'}}">
<view class="{{item.classStr}} wxParse-li">
<view class="{{item.classStr}} wxParse-li-inner">
<view class="{{item.classStr}} wxParse-li-text">
<view class="{{item.classStr}} wxParse-li-circle"></view>
</view>
<view class="{{item.classStr}} wxParse-li-text">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse5" data="{{item}}"/>
</block>
</view>
</view>
</view>
</block>
<!--video类型-->
<block wx:elif="{{item.tag == 'video'}}">
<template is="wxParseVideo" data="{{item}}"/>
</block>
<!--img类型-->
<block wx:elif="{{item.tag == 'img'}}">
<template is="wxParseImg" data="{{item}}"/>
</block>
<!--a类型-->
<block wx:elif="{{item.tag == 'a'}}">
<view bindtap="wxParseTagATap" class="wxParse-inline {{item.classStr}} wxParse-{{item.tag}}" data-src="{{item.attr.href}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse5" data="{{item}}"/>
</block>
</view>
</block>
<!--其他块级标签-->
<block wx:elif="{{item.tagType == 'block'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse5" data="{{item}}"/>
</block>
</view>
</block>
<!--内联标签-->
<view wx:else class="{{item.classStr}} wxParse-{{item.tag}} wxParse-{{item.tagType}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse5" data="{{item}}"/>
</block>
</view>
</block>
<!--判断是否是文本节点-->
<block wx:elif="{{item.node == 'text'}}">
<!--如果是,直接进行-->
<template is="WxEmojiView" data="{{item}}"/>
</block>
</template>
<!--循环模版-->
<template name="wxParse5">
<!--<template is="wxParse6" data="{{item}}" />-->
<!--判断是否是标签节点-->
<block wx:if="{{item.node == 'element'}}">
<block wx:if="{{item.tag == 'button'}}">
<button type="default" size="mini" >
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse6" data="{{item}}"/>
</block>
</button>
</block>
<!--li类型-->
<block wx:elif="{{item.tag == 'li'}}">
<view class="{{item.classStr}} wxParse-li">
<view class="{{item.classStr}} wxParse-li-inner">
<view class="{{item.classStr}} wxParse-li-text">
<view class="{{item.classStr}} wxParse-li-circle"></view>
</view>
<view class="{{item.classStr}} wxParse-li-text">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse6" data="{{item}}"/>
</block>
</view>
</view>
</view>
</block>
<!--video类型-->
<block wx:elif="{{item.tag == 'video'}}">
<template is="wxParseVideo" data="{{item}}"/>
</block>
<!--img类型-->
<block wx:elif="{{item.tag == 'img'}}">
<template is="wxParseImg" data="{{item}}"/>
</block>
<!--a类型-->
<block wx:elif="{{item.tag == 'a'}}">
<view bindtap="wxParseTagATap" class="wxParse-inline {{item.classStr}} wxParse-{{item.tag}}" data-src="{{item.attr.href}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse6" data="{{item}}"/>
</block>
</view>
</block>
<!--其他块级标签-->
<block wx:elif="{{item.tagType == 'block'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse6" data="{{item}}"/>
</block>
</view>
</block>
<!--内联标签-->
<view wx:else class="{{item.classStr}} wxParse-{{item.tag}} wxParse-{{item.tagType}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse6" data="{{item}}"/>
</block>
</view>
</block>
<!--判断是否是文本节点-->
<block wx:elif="{{item.node == 'text'}}">
<!--如果是,直接进行-->
<template is="WxEmojiView" data="{{item}}"/>
</block>
</template>
<!--循环模版-->
<template name="wxParse6">
<!--<template is="wxParse7" data="{{item}}" />-->
<!--判断是否是标签节点-->
<block wx:if="{{item.node == 'element'}}">
<block wx:if="{{item.tag == 'button'}}">
<button type="default" size="mini" >
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse7" data="{{item}}"/>
</block>
</button>
</block>
<!--li类型-->
<block wx:elif="{{item.tag == 'li'}}">
<view class="{{item.classStr}} wxParse-li">
<view class="{{item.classStr}} wxParse-li-inner">
<view class="{{item.classStr}} wxParse-li-text">
<view class="{{item.classStr}} wxParse-li-circle"></view>
</view>
<view class="{{item.classStr}} wxParse-li-text">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse7" data="{{item}}"/>
</block>
</view>
</view>
</view>
</block>
<!--video类型-->
<block wx:elif="{{item.tag == 'video'}}">
<template is="wxParseVideo" data="{{item}}"/>
</block>
<!--img类型-->
<block wx:elif="{{item.tag == 'img'}}">
<template is="wxParseImg" data="{{item}}"/>
</block>
<!--a类型-->
<block wx:elif="{{item.tag == 'a'}}">
<view bindtap="wxParseTagATap" class="wxParse-inline {{item.classStr}} wxParse-{{item.tag}}" data-src="{{item.attr.href}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse7" data="{{item}}"/>
</block>
</view>
</block>
<!--其他块级标签-->
<block wx:elif="{{item.tagType == 'block'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse7" data="{{item}}"/>
</block>
</view>
</block>
<!--内联标签-->
<view wx:else class="{{item.classStr}} wxParse-{{item.tag}} wxParse-{{item.tagType}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse7" data="{{item}}"/>
</block>
</view>
</block>
<!--判断是否是文本节点-->
<block wx:elif="{{item.node == 'text'}}">
<!--如果是,直接进行-->
<template is="WxEmojiView" data="{{item}}"/>
</block>
</template>
<!--循环模版-->
<template name="wxParse7">
<!--<template is="wxParse8" data="{{item}}" />-->
<!--判断是否是标签节点-->
<block wx:if="{{item.node == 'element'}}">
<block wx:if="{{item.tag == 'button'}}">
<button type="default" size="mini" >
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse8" data="{{item}}"/>
</block>
</button>
</block>
<!--li类型-->
<block wx:elif="{{item.tag == 'li'}}">
<view class="{{item.classStr}} wxParse-li">
<view class="{{item.classStr}} wxParse-li-inner">
<view class="{{item.classStr}} wxParse-li-text">
<view class="{{item.classStr}} wxParse-li-circle"></view>
</view>
<view class="{{item.classStr}} wxParse-li-text">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse8" data="{{item}}"/>
</block>
</view>
</view>
</view>
</block>
<!--video类型-->
<block wx:elif="{{item.tag == 'video'}}">
<template is="wxParseVideo" data="{{item}}"/>
</block>
<!--img类型-->
<block wx:elif="{{item.tag == 'img'}}">
<template is="wxParseImg" data="{{item}}"/>
</block>
<!--a类型-->
<block wx:elif="{{item.tag == 'a'}}">
<view bindtap="wxParseTagATap" class="wxParse-inline {{item.classStr}} wxParse-{{item.tag}}" data-src="{{item.attr.href}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse8" data="{{item}}"/>
</block>
</view>
</block>
<!--其他块级标签-->
<block wx:elif="{{item.tagType == 'block'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse8" data="{{item}}"/>
</block>
</view>
</block>
<!--内联标签-->
<view wx:else class="{{item.classStr}} wxParse-{{item.tag}} wxParse-{{item.tagType}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse8" data="{{item}}"/>
</block>
</view>
</block>
<!--判断是否是文本节点-->
<block wx:elif="{{item.node == 'text'}}">
<!--如果是,直接进行-->
<template is="WxEmojiView" data="{{item}}"/>
</block>
</template>
<!--循环模版-->
<template name="wxParse8">
<!--<template is="wxParse9" data="{{item}}" />-->
<!--判断是否是标签节点-->
<block wx:if="{{item.node == 'element'}}">
<block wx:if="{{item.tag == 'button'}}">
<button type="default" size="mini" >
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse9" data="{{item}}"/>
</block>
</button>
</block>
<!--li类型-->
<block wx:elif="{{item.tag == 'li'}}">
<view class="{{item.classStr}} wxParse-li">
<view class="{{item.classStr}} wxParse-li-inner">
<view class="{{item.classStr}} wxParse-li-text">
<view class="{{item.classStr}} wxParse-li-circle"></view>
</view>
<view class="{{item.classStr}} wxParse-li-text">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse9" data="{{item}}"/>
</block>
</view>
</view>
</view>
</block>
<!--video类型-->
<block wx:elif="{{item.tag == 'video'}}">
<template is="wxParseVideo" data="{{item}}"/>
</block>
<!--img类型-->
<block wx:elif="{{item.tag == 'img'}}">
<template is="wxParseImg" data="{{item}}"/>
</block>
<!--a类型-->
<block wx:elif="{{item.tag == 'a'}}">
<view bindtap="wxParseTagATap" class="wxParse-inline {{item.classStr}} wxParse-{{item.tag}}" data-src="{{item.attr.href}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse9" data="{{item}}"/>
</block>
</view>
</block>
<!--其他块级标签-->
<block wx:elif="{{item.tagType == 'block'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse9" data="{{item}}"/>
</block>
</view>
</block>
<!--内联标签-->
<view wx:else class="{{item.classStr}} wxParse-{{item.tag}} wxParse-{{item.tagType}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse9" data="{{item}}"/>
</block>
</view>
</block>
<!--判断是否是文本节点-->
<block wx:elif="{{item.node == 'text'}}">
<!--如果是,直接进行-->
<template is="WxEmojiView" data="{{item}}"/>
</block>
</template>
<!--循环模版-->
<template name="wxParse9">
<!--<template is="wxParse10" data="{{item}}" />-->
<!--判断是否是标签节点-->
<block wx:if="{{item.node == 'element'}}">
<block wx:if="{{item.tag == 'button'}}">
<button type="default" size="mini" >
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse10" data="{{item}}"/>
</block>
</button>
</block>
<!--li类型-->
<block wx:elif="{{item.tag == 'li'}}">
<view class="{{item.classStr}} wxParse-li">
<view class="{{item.classStr}} wxParse-li-inner">
<view class="{{item.classStr}} wxParse-li-text">
<view class="{{item.classStr}} wxParse-li-circle"></view>
</view>
<view class="{{item.classStr}} wxParse-li-text">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse10" data="{{item}}"/>
</block>
</view>
</view>
</view>
</block>
<!--video类型-->
<block wx:elif="{{item.tag == 'video'}}">
<template is="wxParseVideo" data="{{item}}"/>
</block>
<!--img类型-->
<block wx:elif="{{item.tag == 'img'}}">
<template is="wxParseImg" data="{{item}}"/>
</block>
<!--a类型-->
<block wx:elif="{{item.tag == 'a'}}">
<view bindtap="wxParseTagATap" class="wxParse-inline {{item.classStr}} wxParse-{{item.tag}}" data-src="{{item.attr.href}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse10" data="{{item}}"/>
</block>
</view>
</block>
<!--其他块级标签-->
<block wx:elif="{{item.tagType == 'block'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse10" data="{{item}}"/>
</block>
</view>
</block>
<!--内联标签-->
<view wx:else class="{{item.classStr}} wxParse-{{item.tag}} wxParse-{{item.tagType}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse10" data="{{item}}"/>
</block>
</view>
</block>
<!--判断是否是文本节点-->
<block wx:elif="{{item.node == 'text'}}">
<!--如果是,直接进行-->
<template is="WxEmojiView" data="{{item}}"/>
</block>
</template>
<!--循环模版-->
<template name="wxParse10">
<!--<template is="wxParse11" data="{{item}}" />-->
<!--判断是否是标签节点-->
<block wx:if="{{item.node == 'element'}}">
<block wx:if="{{item.tag == 'button'}}">
<button type="default" size="mini" >
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse11" data="{{item}}"/>
</block>
</button>
</block>
<!--li类型-->
<block wx:elif="{{item.tag == 'li'}}">
<view class="{{item.classStr}} wxParse-li">
<view class="{{item.classStr}} wxParse-li-inner">
<view class="{{item.classStr}} wxParse-li-text">
<view class="{{item.classStr}} wxParse-li-circle"></view>
</view>
<view class="{{item.classStr}} wxParse-li-text">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse11" data="{{item}}"/>
</block>
</view>
</view>
</view>
</block>
<!--video类型-->
<block wx:elif="{{item.tag == 'video'}}">
<template is="wxParseVideo" data="{{item}}"/>
</block>
<!--img类型-->
<block wx:elif="{{item.tag == 'img'}}">
<template is="wxParseImg" data="{{item}}"/>
</block>
<!--a类型-->
<block wx:elif="{{item.tag == 'a'}}">
<view bindtap="wxParseTagATap" class="wxParse-inline {{item.classStr}} wxParse-{{item.tag}}" data-src="{{item.attr.href}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse11" data="{{item}}"/>
</block>
</view>
</block>
<!--其他块级标签-->
<block wx:elif="{{item.tagType == 'block'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse11" data="{{item}}"/>
</block>
</view>
</block>
<!--内联标签-->
<view wx:else class="{{item.classStr}} wxParse-{{item.tag}} wxParse-{{item.tagType}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse11" data="{{item}}"/>
</block>
</view>
</block>
<!--判断是否是文本节点-->
<block wx:elif="{{item.node == 'text'}}">
<!--如果是,直接进行-->
<template is="WxEmojiView" data="{{item}}"/>
</block>
</template>
<!--循环模版-->
<template name="wxParse11">
<!--<template is="wxParse12" data="{{item}}" />-->
<!--判断是否是标签节点-->
<block wx:if="{{item.node == 'element'}}">
<block wx:if="{{item.tag == 'button'}}">
<button type="default" size="mini" >
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse12" data="{{item}}"/>
</block>
</button>
</block>
<!--li类型-->
<block wx:elif="{{item.tag == 'li'}}">
<view class="{{item.classStr}} wxParse-li">
<view class="{{item.classStr}} wxParse-li-inner">
<view class="{{item.classStr}} wxParse-li-text">
<view class="{{item.classStr}} wxParse-li-circle"></view>
</view>
<view class="{{item.classStr}} wxParse-li-text">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse12" data="{{item}}"/>
</block>
</view>
</view>
</view>
</block>
<!--video类型-->
<block wx:elif="{{item.tag == 'video'}}">
<template is="wxParseVideo" data="{{item}}"/>
</block>
<!--img类型-->
<block wx:elif="{{item.tag == 'img'}}">
<template is="wxParseImg" data="{{item}}"/>
</block>
<!--a类型-->
<block wx:elif="{{item.tag == 'a'}}">
<view bindtap="wxParseTagATap" class="wxParse-inline {{item.classStr}} wxParse-{{item.tag}}" data-src="{{item.attr.href}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse12" data="{{item}}"/>
</block>
</view>
</block>
<!--其他块级标签-->
<block wx:elif="{{item.tagType == 'block'}}">
<view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse12" data="{{item}}"/>
</block>
</view>
</block>
<!--内联标签-->
<view wx:else class="{{item.classStr}} wxParse-{{item.tag}} wxParse-{{item.tagType}}" style="{{item.styleStr}}">
<block wx:for="{{item.nodes}}" wx:for-item="item" wx:key="">
<template is="wxParse12" data="{{item}}"/>
</block>
</view>
</block>
<!--判断是否是文本节点-->
<block wx:elif="{{item.node == 'text'}}">
<!--如果是,直接进行-->
<template is="WxEmojiView" data="{{item}}"/>
</block>
</template>
================================================
FILE: lib/wxParse/wxParse.wxss
================================================
/**
* author: Di (微信小程序开发工程师)
* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
* 垂直微信小程序开发交流社区
*
* github地址: https://github.com/icindy/wxParse
*
* for: 微信小程序富文本解析
* detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
*/
.wxParse{
margin: 0 5px;
font-family: Helvetica,sans-serif;
font-size: 28rpx;
color: #666;
line-height: 1.8;
}
view{
word-break:break-all; overflow:auto;
}
.wxParse-inline{
display: inline;
margin: 0;
padding: 0;
}
/*//标题 */
.wxParse-div{margin: 0;padding: 0;}
.wxParse-h1{ font-size:2em; margin: .67em 0 }
.wxParse-h2{ font-size:1.5em; margin: .75em 0 }
.wxParse-h3{ font-size:1.17em; margin: .83em 0 }
.wxParse-h4{ margin: 1.12em 0}
.wxParse-h5 { font-size:.83em; margin: 1.5em 0 }
.wxParse-h6{ font-size:.75em; margin: 1.67em 0 }
.wxParse-h1 {
font-size: 18px;
font-weight: 400;
margin-bottom: .9em;
}
.wxParse-h2 {
font-size: 16px;
font-weight: 400;
margin-bottom: .34em;
}
.wxParse-h3 {
font-weight: 400;
font-size: 15px;
margin-bottom: .34em;
}
.wxParse-h4 {
font-weight: 400;
font-size: 14px;
margin-bottom: .24em;
}
.wxParse-h5 {
font-weight: 400;
font-size: 13px;
margin-bottom: .14em;
}
.wxParse-h6 {
font-weight: 400;
font-size: 12px;
margin-bottom: .04em;
}
.wxParse-h1, .wxParse-h2, .wxParse-h3, .wxParse-h4, .wxParse-h5, .wxParse-h6, .wxParse-b, .wxParse-strong { font-weight: bolder }
.wxParse-i,.wxParse-cite,.wxParse-em,.wxParse-var,.wxParse-address{font-style:italic}
.wxParse-pre,.wxParse-tt,.wxParse-code,.wxParse-kbd,.wxParse-samp{font-family:monospace}
.wxParse-pre{white-space:pre}
.wxParse-big{font-size:1.17em}
.wxParse-small,.wxParse-sub,.wxParse-sup{font-size:.83em}
.wxParse-sub{vertical-align:sub}
.wxParse-sup{vertical-align:super}
.wxParse-s,.wxParse-strike,.wxParse-del{text-decoration:line-through}
/*wxparse-自定义个性化的css样式*/
/*增加video的css样式*/
.wxParse-strong,wxParse-s{display: inline}
.wxParse-a{
color: deepskyblue;
word-break:break-all;
overflow:auto;
}
.wxParse-video{
text-align: center;
margin: 10px 0;
}
.wxParse-video-video{
width:100%;
}
.wxParse-img{
background-color: #efefef;
overflow: hidden;
width:40px;
height: 40px;
}
.wxParse-blockquote {
margin: 0;
padding:10px 0 10px 5px;
font-family:Courier, Calibri,"宋体";
background:#f5f5f5;
border-left: 3px solid #dbdbdb;
}
.wxParse-code,.wxParse-wxxxcode-style{
display: inline;
background:#f5f5f5;
}
.wxParse-ul{
margin: 20rpx 10rpx;
}
.wxParse-li,.wxParse-li-inner{
display: flex;
align-items: baseline;
margin: 10rpx 0;
}
.wxParse-li-text{
align-items: center;
line-height: 20px;
}
.wxParse-li-circle{
display: inline-flex;
width: 5px;
height: 5px;
background-color: #333;
margin-right: 5px;
}
.wxParse-li-square{
display: inline-flex;
width: 10rpx;
height: 10rpx;
background-color: #333;
margin-right: 5px;
}
.wxParse-li-ring{
display: inline-flex;
width: 10rpx;
height: 10rpx;
border: 2rpx solid #333;
border-radius: 50%;
background-color: #fff;
margin-right: 5px;
}
/*.wxParse-table{
width: 100%;
height: 400px;
}
.wxParse-thead,.wxParse-tfoot,.wxParse-tr{
display: flex;
flex-direction: row;
}
.wxParse-th,.wxParse-td{
display: flex;
width: 580px;
overflow: auto;
}*/
.wxParse-u {
text-decoration: underline;
}
.wxParse-hide{
display: none;
}
.WxEmojiView{
align-items: center;
}
.wxEmoji{
width: 16px;
height:16px;
}
.wxParse-tr{
display: flex;
border-right:1px solid #e0e0e0;
border-bottom:1px solid #e0e0e0;
}
.wxParse-th,
.wxParse-td{
flex:1;
padding:5px;
font-size:28rpx;
border-left:1px solid #e0e0e0;
word-break: break-all;
}
.wxParse-td:last{
border-top:1px solid #e0e0e0;
}
.wxParse-th{
background:#f0f0f0;
border-top:1px solid #e0e0e0;
}
================================================
FILE: pages/auth/login/login.js
================================================
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
username: '',
password: '',
code: '',
loginErrorCount: 0
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
// 页面渲染完成
},
onReady: function () {
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
startLogin: function () {
var that = this;
if (that.data.password.length < 1 || that.data.username.length < 1) {
wx.showModal({
title: '错误信息',
content: '请输入用户名和密码',
showCancel: false
});
return false;
}
wx.request({
url: api.ApiRootUrl + 'auth/login',
data: {
username: that.data.username,
password: that.data.password
},
method: 'POST',
header: {
'content-type': 'application/json'
},
success: function (res) {
if(res.data.code == 200){
that.setData({
'loginErrorCount': 0
});
wx.setStorage({
key:"token",
data: res.data.data.token,
success: function(){
wx.switchTab({
url: '/pages/ucenter/index/index'
});
}
});
}
}
});
},
bindUsernameInput: function (e) {
this.setData({
username: e.detail.value
});
},
bindPasswordInput: function (e) {
this.setData({
password: e.detail.value
});
},
bindCodeInput: function (e) {
this.setData({
code: e.detail.value
});
},
clearInput: function (e) {
switch (e.currentTarget.id) {
case 'clear-username':
this.setData({
username: ''
});
break;
case 'clear-password':
this.setData({
password: ''
});
break;
case 'clear-code':
this.setData({
code: ''
});
break;
}
}
})
================================================
FILE: pages/auth/login/login.json
================================================
{}
================================================
FILE: pages/auth/login/login.wxml
================================================
<view class="container">
<view class="form-box">
<view class="form-item">
<input class="username" value="{{username}}" bindinput="bindUsernameInput" placeholder="账号" auto-focus/>
<image wx:if="{{ username.length > 0 }}" id="clear-username" class="clear" src="/static/images/clear_input.png" catchtap="clearInput"></image>
</view>
<view class="form-item">
<input class="password" value="{{password}}" password bindinput="bindPasswordInput" placeholder="密码"/>
<image class="clear" id="clear-password" wx:if="{{ password.length > 0 }}" src="/static/images/clear_input.png" catchtap="clearInput"></image>
</view>
<view class="form-item-code" wx-if="{{loginErrorCount >= 3}}">
<view class="form-item code-item">
<input class="code" value="{{code}}" bindinput="bindCodeInput" placeholder="验证码"/>
<image class="clear" id="clear-code" wx:if="{{ code.length > 0 }}" src="/static/images/clear_input.png" catchtap="clearInput"></image>
</view>
<image class="code-img" src="https://dl.reg.163.com/cp?pd=yanxuan_web&pkid=SkeBZeG&random=1489903563234"></image>
</view>
<button type="default" class="login-btn" bindtap="startLogin">登录</button>
<view class="form-item-text">
<navigator url="/pages/auth/register/register" class="register">注册账号</navigator>
<navigator url="/pages/auth/reset/reset" class="reset">忘记密码</navigator>
</view>
</view>
</view>
================================================
FILE: pages/auth/login/login.wxss
================================================
.form-box{
width: 100%;
height: auto;
overflow: hidden;
padding: 0 40rpx;
margin-top: 96rpx;
background: #fff;
}
.form-item{
position: relative;
background: #fff;
height: 96rpx;
border-bottom: 1px solid #d9d9d9;
}
.form-item .username, .form-item .password, .form-item .code{
position: absolute;
top: 26rpx;
left: 0;
display: block;
width: 100%;
height: 44rpx;
background: #fff;
color: #333;
font-size: 30rpx;
}
.form-item-code{
margin-top:32rpx;
height: auto;
overflow: hidden;
width: 100%;
}
.form-item-code .form-item{
float: left;
width: 350rpx;
}
.form-item-code .code-img{
float: right;
margin-top: 4rpx;
height: 88rpx;
width: 236rpx;
}
.form-item .clear{
position: absolute;
top: 26rpx;
right: 18rpx;
z-index: 2;
display: block;
background: #fff;
height: 44rpx;
width: 44rpx;
}
.login-btn{
margin: 60rpx 0 40rpx 0;
height: 96rpx;
line-height: 96rpx;
color: #fff;
font-size: 30rpx;
width: 100%;
background: #b4282d;
border-radius: 6rpx;
}
.form-item-text{
height: 35rpx;
width: 100%;
}
.form-item-text .register{
display: block;
height: 34rpx;
float: left;
font-size: 28rpx;
color: #999;
}
.form-item-text .reset{
display: block;
height: 34rpx;
float: right;
font-size: 28rpx;
color: #999;
}
================================================
FILE: pages/auth/register/register.js
================================================
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
username: '',
password: '',
confirmPassword: '',
code: '',
loginErrorCount: 0
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
// 页面渲染完成
},
onReady: function () {
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
startRegister: function () {
var that = this;
if (that.data.password.length < 3 || that.data.username.length < 3) {
wx.showModal({
title: '错误信息',
content: '用户名和密码不得少于3位',
showCancel: false
});
return false;
}
if (that.data.password != that.data.confirmPassword) {
wx.showModal({
title: '错误信息',
content: '确认密码不一致',
showCancel: false
});
return false;
}
wx.request({
url: api.ApiRootUrl + 'auth/register',
data: {
username: that.data.username,
password: that.data.password
},
method: 'POST',
header: {
'content-type': 'application/json'
},
success: function (res) {
if (res.data.code == 200) {
that.setData({
'loginErrorCount': 0
});
wx.setStorage({
key: "token",
data: res.data.data.token,
success: function () {
wx.switchTab({
url: '/pages/ucenter/index/index'
});
}
});
}
console.log(res.data.data.token)
}
});
},
bindUsernameInput: function (e) {
this.setData({
username: e.detail.value
});
},
bindPasswordInput: function (e) {
this.setData({
password: e.detail.value
});
},
bindConfirmPasswordInput: function (e) {
this.setData({
confirmPassword: e.detail.value
});
},
bindCodeInput: function (e) {
this.setData({
code: e.detail.value
});
},
clearInput: function (e) {
switch (e.currentTarget.id) {
case 'clear-username':
this.setData({
username: ''
});
break;
case 'clear-password':
this.setData({
password: ''
});
break;
case 'clear-confirm-password':
this.setData({
confirmPassword: ''
});
break;
case 'clear-code':
this.setData({
code: ''
});
break;
}
}
})
================================================
FILE: pages/auth/register/register.json
================================================
{}
================================================
FILE: pages/auth/register/register.wxml
================================================
<view class="container">
<view class="form-box">
<view class="form-item">
<input class="username" value="{{username}}" bindinput="bindUsernameInput" placeholder="用户名" auto-focus/>
<image wx:if="{{ username.length > 0 }}" id="clear-username" class="clear" src="/static/images/clear_input.png" catchtap="clearInput"></image>
</view>
<view class="form-item">
<input class="password" value="{{password}}" password bindinput="bindPasswordInput" placeholder="密码"/>
<image class="clear" id="clear-password" wx:if="{{ password.length > 0 }}" src="/static/images/clear_input.png" catchtap="clearInput"></image>
</view>
<view class="form-item">
<input class="password" value="{{confirmPassword}}" password bindinput="bindConfirmPasswordInput" placeholder="确认密码"/>
<image class="clear" id="clear-confirm-password" wx:if="{{ confirmPassword.length > 0 }}" src="/static/images/clear_input.png" catchtap="clearInput"></image>
</view>
<view class="form-item-code" >
<view class="form-item code-item">
<input class="code" value="{{code}}" bindinput="bindCodeInput" placeholder="验证码"/>
<image class="clear" id="clear-code" wx:if="{{ code.length > 0 }}" src="/static/images/clear_input.png" catchtap="clearInput"></image>
</view>
<image class="code-img" src="https://dl.reg.163.com/cp?pd=yanxuan_web&pkid=SkeBZeG&random=1489903563234"></image>
</view>
<button type="default" class="login-btn" bindtap="startRegister">注册</button>
</view>
</view>
================================================
FILE: pages/auth/register/register.wxss
================================================
.form-box{
width: 100%;
height: auto;
overflow: hidden;
padding: 0 40rpx;
margin-top: 96rpx;
background: #fff;
}
.form-item{
position: relative;
background: #fff;
height: 96rpx;
border-bottom: 1px solid #d9d9d9;
}
.form-item .username, .form-item .password, .form-item .code{
position: absolute;
top: 26rpx;
left: 0;
display: block;
width: 100%;
height: 44rpx;
background: #fff;
color: #333;
font-size: 30rpx;
}
.form-item-code{
margin-top:32rpx;
height: auto;
overflow: hidden;
width: 100%;
}
.form-item-code .form-item{
float: left;
width: 350rpx;
}
.form-item-code .code-img{
float: right;
margin-top: 4rpx;
height: 88rpx;
width: 236rpx;
}
.form-item .clear{
position: absolute;
top: 26rpx;
right: 18rpx;
z-index: 2;
display: block;
background: #fff;
height: 44rpx;
width: 44rpx;
}
.login-btn{
margin: 60rpx 0 40rpx 0;
height: 96rpx;
line-height: 96rpx;
color: #fff;
font-size: 30rpx;
width: 100%;
background: #b4282d;
border-radius: 6rpx;
}
.form-item-text{
height: 35rpx;
width: 100%;
}
.form-item-text .register{
display: block;
height: 34rpx;
float: left;
font-size: 28rpx;
color: #999;
}
.form-item-text .reset{
display: block;
height: 34rpx;
float: right;
font-size: 28rpx;
color: #999;
}
================================================
FILE: pages/auth/reset/reset.js
================================================
var app = getApp();
Page({
data: {
username: '',
code: ''
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
// 页面渲染完成
},
onReady: function () {
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
startLogin: function(){
var that = this;
},
bindUsernameInput: function(e){
this.setData({
username: e.detail.value
});
},
bindCodeInput: function(e){
this.setData({
code: e.detail.value
});
},
clearInput: function(e){
switch (e.currentTarget.id){
case 'clear-username':
this.setData({
username: ''
});
break;
case 'clear-code':
this.setData({
code: ''
});
break;
}
}
})
================================================
FILE: pages/auth/reset/reset.json
================================================
{}
================================================
FILE: pages/auth/reset/reset.wxml
================================================
<view class="container">
<view class="form-box">
<view class="form-item">
<input class="username" value="{{username}}" bindinput="bindUsernameInput" placeholder="请输入账号" auto-focus/>
<image wx:if="{{ username.length > 0 }}" id="clear-username" class="clear" src="/static/images/clear_input.png" catchtap="clearInput"></image>
</view>
<view class="form-item-code" >
<view class="form-item code-item">
<input class="code" value="{{code}}" bindinput="bindCodeInput" placeholder="验证码"/>
<image class="clear" id="clear-code" wx:if="{{ code.length > 0 }}" src="/static/images/clear_input.png" catchtap="clearInput"></image>
</view>
<image class="code-img" src="https://dl.reg.163.com/cp?pd=yanxuan_web&pkid=SkeBZeG&random=1489903563234"></image>
</view>
<button type="default" class="login-btn" bindtap="startNext">下一步</button>
</view>
</view>
================================================
FILE: pages/auth/reset/reset.wxss
================================================
.form-box{
width: 100%;
height: auto;
overflow: hidden;
padding: 0 40rpx;
margin-top: 96rpx;
background: #fff;
}
.form-item{
position: relative;
background: #fff;
height: 96rpx;
border-bottom: 1px solid #d9d9d9;
}
.form-item .username, .form-item .code{
position: absolute;
top: 26rpx;
left: 0;
display: block;
width: 100%;
height: 44rpx;
background: #fff;
color: #333;
font-size: 30rpx;
}
.form-item-code{
margin-top:32rpx;
height: auto;
overflow: hidden;
width: 100%;
}
.form-item-code .form-item{
float: left;
width: 350rpx;
}
.form-item-code .code-img{
float: right;
margin-top: 4rpx;
height: 88rpx;
width: 236rpx;
}
.form-item .clear{
position: absolute;
top: 26rpx;
right: 18rpx;
z-index: 2;
display: block;
background: #fff;
height: 44rpx;
width: 44rpx;
}
.login-btn{
margin: 60rpx 0 40rpx 0;
height: 96rpx;
line-height: 96rpx;
color: #fff;
font-size: 30rpx;
width: 100%;
background: #b4282d;
border-radius: 6rpx;
}
================================================
FILE: pages/brand/brand.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp();
Page({
data: {
brandList: [],
page: 1,
size: 10,
totalPages: 1
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.getBrandList();
},
getBrandList: function () {
wx.showLoading({
title: '加载中...',
});
let that = this;
util.request(api.BrandList, { page: that.data.page, size: that.data.size }).then(function (res) {
if (res.errno === 0) {
that.setData({
brandList: that.data.brandList.concat(res.data.data),
totalPages: res.data.totalPages
});
}
wx.hideLoading();
});
},
onReachBottom (){
if (this.data.totalPages > this.data.page) {
this.setData({
page: this.data.page + 1
});
} else {
return false;
}
this.getBrandList();
},
onReady: function () {
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/brand/brand.json
================================================
{}
================================================
FILE: pages/brand/brand.wxml
================================================
<view class="container">
<view class="brand-list" >
<navigator url="../brandDetail/brandDetail?id={{item.id}}" class="item" wx:for="{{brandList}}" wx:key="id">
<view class="img-bg">
<image src="{{item.app_list_pic_url}}" background-size="cover"></image>
</view>
<view class="txt-box">
<view class="line">
<text class="name" >{{item.name}}</text>
<text class="s">|</text>
<text class="price">{{item.floor_price}}元起</text>
</view>
</view>
</navigator >
</view>
</view>
================================================
FILE: pages/brand/brand.wxss
================================================
.brand-list .item{
display: block;
width: 750rpx;
height: 416rpx;
position: relative;
margin-bottom: 4rpx;
}
.brand-list .item .img-bg{
position: absolute;
left:0;
top:0;
z-index: 0;
width: 750rpx;
height: 417rpx;
overflow: hidden;
}
.brand-list .item .img-bg image{
width: 750rpx;
height: 416rpx;
}
.brand-list .item .txt-box{
position: absolute;
left:0;
top:0;
display: table;
z-index: 0;
width: 750rpx;
height: 417rpx;
}
.brand-list .item .line{
display: table-cell;
vertical-align: middle;
text-align: center;
height: 63rpx;
line-height: 63rpx;
}
.brand-list .item .line text{
font-size: 35rpx;
font-weight: 700;
text-shadow: 1rpx 1rpx rgba(0,0,0,.32);
color: #fff;
}
.brand-list .item .line .s{
padding: 0 10rpx;
font-size: 40rpx;
}
================================================
FILE: pages/brandDetail/brandDetail.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp();
Page({
data: {
id: 0,
brand: {},
goodsList: [],
page: 1,
size: 1000
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
var that = this;
that.setData({
id: parseInt(options.id)
});
this.getBrand();
},
getBrand: function () {
let that = this;
util.request(api.BrandDetail, { id: that.data.id }).then(function (res) {
if (res.errno === 0) {
that.setData({
brand: res.data.brand
});
that.getGoodsList();
}
});
},
getGoodsList() {
var that = this;
util.request(api.GoodsList, { brandId: that.data.id, page: that.data.page, size: that.data.size})
.then(function (res) {
if (res.errno === 0) {
that.setData({
goodsList: res.data.goodsList
});
}
});
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/brandDetail/brandDetail.json
================================================
{
}
================================================
FILE: pages/brandDetail/brandDetail.wxml
================================================
<view class="container">
<view class="brand-info">
<view class="name">
<image class="img" src="{{brand.app_list_pic_url}}" background-size="cover"></image>
<view class="info-box">
<view class="info">
<text class="txt">{{brand.name}}</text>
<text class="line"></text>
</view>
</view>
</view>
<view class="desc">
{{brand.simple_desc}}
</view>
</view>
<view class="cate-item">
<view class="b">
<block wx:for="{{goodsList}}" wx:for-index="iindex" wx:for-item="iitem">
<navigator class="item {{iindex % 2 == 0 ? 'item-b' : ''}}" url="../goods/goods?id={{iitem.id}}">
<image class="img" src="{{iitem.list_pic_url}}" background-size="cover"></image>
<text class="name">{{iitem.name}}</text>
<text class="price">¥{{iitem.retail_price}}</text>
</navigator>
</block>
</view>
</view>
</view>
================================================
FILE: pages/brandDetail/brandDetail.wxss
================================================
page{
background: #f4f4f4;
}
.brand-info .name{
width: 100%;
height: 290rpx;
position: relative;
}
.brand-info .img{
position: absolute;
top:0;
left:0;
width: 100%;
height: 290rpx;
}
.brand-info .info-box{
position: absolute;
top:0;
left:0;
width: 100%;
height: 290rpx;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
.brand-info .info{
display: block;
}
.brand-info .txt{
display: block;
height: 37.5rpx;
font-size: 37.5rpx;
color: #fff;
}
.brand-info .line{
margin: 0 auto;
margin-top: 16rpx;
display: block;
height: 2rpx;
width: 145rpx;
background: #fff;
}
.brand-info .desc{
background: #fff;
width: 100%;
height: auto;
overflow: hidden;
padding: 41.5rpx 31.25rpx;
font-size: 30rpx;
color: #666;
line-height: 41.5rpx;
text-align: center;
}
.cate-item .b{
width: 750rpx;
height: auto;
overflow: hidden;
border-top: 1rpx solid #f4f4f4;
margin-top: 20rpx;
}
.cate-item .b .item{
float: left;
background: #fff;
width: 375rpx;
padding-bottom: 33.333rpx;
border-bottom: 1rpx solid #f4f4f4;
height: auto;
overflow: hidden;
text-align: center;
}
.cate-item .b .item-b{
border-right: 1rpx solid #f4f4f4;
}
.cate-item .item .img{
margin-top: 10rpx;
width: 302rpx;
height: 302rpx;
}
.cate-item .item .name{
display: block;
width: 365.625rpx;
height: 35rpx;
padding: 0 20rpx;
overflow: hidden;
margin: 11.5rpx 0 22rpx 0;
text-align: center;
font-size: 30rpx;
color: #333;
}
.cate-item .item .price{
display: block;
width: 365.625rpx;
height: 30rpx;
text-align: center;
font-size: 30rpx;
color: #b4282d;
}
================================================
FILE: pages/cart/cart.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp();
Page({
data: {
cartGoods: [],
cartTotal: {
"goodsCount": 0,
"goodsAmount": 0.00,
"checkedGoodsCount": 0,
"checkedGoodsAmount": 0.00
},
isEditCart: false,
checkedAllStatus: true,
editCartList: []
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
this.getCartList();
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
getCartList: function () {
let that = this;
util.request(api.CartList).then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
cartGoods: res.data.cartList,
cartTotal: res.data.cartTotal
});
}
that.setData({
checkedAllStatus: that.isCheckedAll()
});
});
},
isCheckedAll: function () {
//判断购物车商品已全选
return this.data.cartGoods.every(function (element, index, array) {
if (element.checked == true) {
return true;
} else {
return false;
}
});
},
checkedItem: function (event) {
let itemIndex = event.target.dataset.itemIndex;
let that = this;
if (!this.data.isEditCart) {
util.request(api.CartChecked, { productIds: that.data.cartGoods[itemIndex].product_id, isChecked: that.data.cartGoods[itemIndex].checked ? 0 : 1 }, 'POST').then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
cartGoods: res.data.cartList,
cartTotal: res.data.cartTotal
});
}
that.setData({
checkedAllStatus: that.isCheckedAll()
});
});
} else {
//编辑状态
let tmpCartData = this.data.cartGoods.map(function (element, index, array) {
if (index == itemIndex){
element.checked = !element.checked;
}
return element;
});
that.setData({
cartGoods: tmpCartData,
checkedAllStatus: that.isCheckedAll(),
'cartTotal.checkedGoodsCount': that.getCheckedGoodsCount()
});
}
},
getCheckedGoodsCount: function(){
let checkedGoodsCount = 0;
this.data.cartGoods.forEach(function (v) {
if (v.checked === true) {
checkedGoodsCount += v.number;
}
});
console.log(checkedGoodsCount);
return checkedGoodsCount;
},
checkedAll: function () {
let that = this;
if (!this.data.isEditCart) {
var productIds = this.data.cartGoods.map(function (v) {
return v.product_id;
});
util.request(api.CartChecked, { productIds: productIds.join(','), isChecked: that.isCheckedAll() ? 0 : 1 }, 'POST').then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
cartGoods: res.data.cartList,
cartTotal: res.data.cartTotal
});
}
that.setData({
checkedAllStatus: that.isCheckedAll()
});
});
} else {
//编辑状态
let checkedAllStatus = that.isCheckedAll();
let tmpCartData = this.data.cartGoods.map(function (v) {
v.checked = !checkedAllStatus;
return v;
});
that.setData({
cartGoods: tmpCartData,
checkedAllStatus: that.isCheckedAll(),
'cartTotal.checkedGoodsCount': that.getCheckedGoodsCount()
});
}
},
editCart: function () {
var that = this;
if (this.data.isEditCart) {
this.getCartList();
this.setData({
isEditCart: !this.data.isEditCart
});
} else {
//编辑状态
let tmpCartList = this.data.cartGoods.map(function (v) {
v.checked = false;
return v;
});
this.setData({
editCartList: this.data.cartGoods,
cartGoods: tmpCartList,
isEditCart: !this.data.isEditCart,
checkedAllStatus: that.isCheckedAll(),
'cartTotal.checkedGoodsCount': that.getCheckedGoodsCount()
});
}
},
updateCart: function (productId, goodsId, number, id) {
let that = this;
util.request(api.CartUpdate, {
productId: productId,
goodsId: goodsId,
number: number,
id: id
}, 'POST').then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
//cartGoods: res.data.cartList,
//cartTotal: res.data.cartTotal
});
}
that.setData({
checkedAllStatus: that.isCheckedAll()
});
});
},
cutNumber: function (event) {
let itemIndex = event.target.dataset.itemIndex;
let cartItem = this.data.cartGoods[itemIndex];
let number = (cartItem.number - 1 > 1) ? cartItem.number - 1 : 1;
cartItem.number = number;
this.setData({
cartGoods: this.data.cartGoods
});
this.updateCart(cartItem.product_id, cartItem.goods_id, number, cartItem.id);
},
addNumber: function (event) {
let itemIndex = event.target.dataset.itemIndex;
let cartItem = this.data.cartGoods[itemIndex];
let number = cartItem.number + 1;
cartItem.number = number;
this.setData({
cartGoods: this.data.cartGoods
});
this.updateCart(cartItem.product_id, cartItem.goods_id, number, cartItem.id);
},
checkoutOrder: function () {
//获取已选择的商品
let that = this;
var checkedGoods = this.data.cartGoods.filter(function (element, index, array) {
if (element.checked == true) {
return true;
} else {
return false;
}
});
if (checkedGoods.length <= 0) {
return false;
}
wx.navigateTo({
url: '../shopping/checkout/checkout'
})
},
deleteCart: function () {
//获取已选择的商品
let that = this;
let productIds = this.data.cartGoods.filter(function (element, index, array) {
if (element.checked == true) {
return true;
} else {
return false;
}
});
if (productIds.length <= 0) {
return false;
}
productIds = productIds.map(function (element, index, array) {
if (element.checked == true) {
return element.product_id;
}
});
util.request(api.CartDelete, {
productIds: productIds.join(',')
}, 'POST').then(function (res) {
if (res.errno === 0) {
console.log(res.data);
let cartList = res.data.cartList.map(v => {
console.log(v);
v.checked = false;
return v;
});
that.setData({
cartGoods: cartList,
cartTotal: res.data.cartTotal
});
}
that.setData({
checkedAllStatus: that.isCheckedAll()
});
});
}
})
================================================
FILE: pages/cart/cart.json
================================================
{
"backgroundColor": "#f4f4f4"
}
================================================
FILE: pages/cart/cart.wxml
================================================
<view class="container">
<view class="service-policy">
<view class="item">30天无忧退货</view>
<view class="item">48小时快速退款</view>
<view class="item">满88元免邮费</view>
</view>
<view class="no-cart" wx:if="{{cartGoods.length <= 0}}">
<view class="c">
<image src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/noCart-a8fe3f12e5.png" />
<text>去添加点什么吧</text>
</view>
</view>
<view class="cart-view" wx:if="{{cartGoods.length > 0}}">
<view class="list">
<view class="group-item">
<view class="goods">
<view class="item {{isEditCart ? 'edit' : ''}}" wx:for="{{cartGoods}}" wx:key="{{item.id}}">
<view class="checkbox {{item.checked ? 'checked' : ''}}" bindtap="checkedItem" data-item-index="{{index}}"></view>
<view class="cart-goods">
<image class="img" src="{{item.list_pic_url}}"></image>
<view class="info">
<view class="t">
<text class="name">{{item.goods_name}}</text>
<text class="num">x{{item.number}}</text>
</view>
<view class="attr">{{ isEditCart ? '已选择:' : ''}}{{item.goods_specifition_name_value}}</view>
<view class="b">
<text class="price">¥{{item.retail_price}}</text>
<view class="selnum">
<view class="cut" bindtap="cutNumber" data-item-index="{{index}}">-</view>
<input value="{{item.number}}" class="number" disabled="true" type="number" />
<view class="add" bindtap="addNumber" data-item-index="{{index}}">+</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<!--<view class="group-item">
<view class="header">
<view class="promotion">
<text class="tag">满赠</text>
<text class="txt">再加26元, 3件赠1件蔓越莓干</text>
<image class="icon" src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/go-b67cb9718d.png"></image>
</view>
<view class="get">领赠品</view>
</view>
<view class="goods">
<view class="item">
<view class="checkbox" ></view>
<view class="cart-goods">
<image class="img" src="http://yanxuan.nosdn.127.net/04e05e9de3a471b1f6479dd137b459a8.png"></image>
<view class="info">
<view class="t">
<text class="name">秋冬保暖加厚细羊毛被</text>
<text class="num">x1</text>
</view>
<view class="attr">220*240cm</view>
<view class="b">
<text class="price">¥199.99</text>
<view class="open">优惠活动</view>
</view>
</view>
</view>
</view>
</view>
</view>-->
</view>
<view class="cart-bottom">
<view class="checkbox {{checkedAllStatus ? 'checked' : ''}}" bindtap="checkedAll">全选({{cartTotal.checkedGoodsCount}})</view>
<view class="total">{{!isEditCart ? '¥'+cartTotal.checkedGoodsAmount : ''}}</view>
<view class="delete" bindtap="editCart">{{!isEditCart ? '编辑' : '完成'}}</view>
<view class="checkout" bindtap="deleteCart" wx:if="{{isEditCart}}">删除所选</view>
<view class="checkout" bindtap="checkoutOrder" wx:if="{{!isEditCart}}">下单</view>
</view>
</view>
</view>
================================================
FILE: pages/cart/cart.wxss
================================================
page{
height: 100%;
min-height: 100%;
background: #f4f4f4;
}
.container{
background: #f4f4f4;
width: 100%;
height: auto;
min-height: 100%;
overflow: hidden;
}
.service-policy{
width: 750rpx;
height: 73rpx;
background: #f4f4f4;
padding: 0 31.25rpx;
display: flex;
flex-flow: row nowrap;
align-items: center;
justify-content: space-between;
}
.service-policy .item{
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/servicePolicyRed-518d32d74b.png) 0 center no-repeat;
background-size: 10rpx;
padding-left: 15rpx;
display: flex;
align-items: center;
font-size: 25rpx;
color: #666;
}
.no-cart{
width: 100%;
height: auto;
margin: 0 auto;
}
.no-cart .c{
width: 100%;
height: auto;
margin-top: 200rpx;
}
.no-cart .c image{
margin: 0 auto;
display: block;
text-align: center;
width: 258rpx;
height: 258rpx;
}
.no-cart .c text{
margin: 0 auto;
display: block;
width: 258rpx;
height: 29rpx;
line-height: 29rpx;
text-align: center;
font-size: 29rpx;
color: #999;
}
.cart-view{
width: 100%;
height: auto;
overflow: hidden;
}
.cart-view .list{
height: auto;
width: 100%;
overflow: hidden;
margin-bottom: 120rpx;
}
.cart-view .group-item{
height: auto;
width: 100%;
background: #fff;
margin-bottom: 18rpx;
}
.cart-view .item{
height: 164rpx;
width: 100%;
overflow: hidden;
}
.cart-view .item .checkbox{
float: left;
height: 34rpx;
width: 34rpx;
margin: 65rpx 18rpx 65rpx 26rpx;
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/checkbox-0e09baa37e.png) no-repeat;
background-size: 34rpx;
}
.cart-view .item .checkbox.checked{
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/checkbox-checked-822e54472a.png) no-repeat;
background-size: 34rpx;
}
.cart-view .item .cart-goods{
float: left;
height: 164rpx;
width: 672rpx;
border-bottom: 1px solid #f4f4f4;
}
.cart-view .item .img{
float: left;
height:125rpx;
width: 125rpx;
background: #f4f4f4;
margin: 19.5rpx 18rpx 19.5rpx 0;
}
.cart-view .item .info{
float: left;
height:125rpx;
width: 503rpx;
margin: 19.5rpx 26rpx 19.5rpx 0;
}
.cart-view .item .t{
margin: 8rpx 0;
height: 28rpx;
font-size: 25rpx;
color: #333;
overflow: hidden;
}
.cart-view .item .name{
height: 28rpx;
max-width: 310rpx;
line-height: 28rpx;
font-size: 25rpx;
color: #333;
overflow: hidden;
}
.cart-view .item .num{
height: 28rpx;
line-height: 28rpx;
float: right;
}
.cart-view .item .attr{
margin-bottom: 17rpx;
height: 24rpx;
line-height: 24rpx;
font-size: 22rpx;
color: #666;
overflow: hidden;
}
.cart-view .item .b{
height: 28rpx;
line-height: 28rpx;
font-size: 25rpx;
color: #333;
overflow: hidden;
}
.cart-view .item .price{
float: left;
}
.cart-view .item .open{
height: 28rpx;
width: 150rpx;
display: block;
float: right;
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/arrowDown-d48093db25.png) right center no-repeat;
background-size: 25rpx;
font-size: 25rpx;
color: #333;
}
.cart-view .item.edit .t{
display: none;
}
.cart-view .item.edit .attr{
text-align: right;
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/arrow-right1-e9828c5b35.png) right center no-repeat;
padding-right: 25rpx;
background-size: 12rpx 20rpx;
margin-bottom: 24rpx;
height: 39rpx;
line-height: 39rpx;
font-size: 24rpx;
color: #999;
overflow: hidden;
}
.cart-view .item.edit .b{
display: flex;
height: 52rpx;
overflow: hidden;
}
.cart-view .item.edit .price{
line-height: 52rpx;
height: 52rpx;
flex: 1;
}
.cart-view .item .selnum{
display: none;
}
.cart-view .item.edit .selnum{
width: 235rpx;
height: 52rpx;
border: 1rpx solid #ccc;
display: flex;
}
.selnum .cut{
width: 70rpx;
height: 100%;
text-align: center;
line-height: 50rpx;
}
.selnum .number{
flex: 1;
height: 100%;
text-align: center;
line-height: 68.75rpx;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
float: left;
}
.selnum .add{
width: 80rpx;
height: 100%;
text-align: center;
line-height: 50rpx;
}
.cart-view .group-item .header{
width: 100%;
height: 94rpx;
line-height: 94rpx;
padding: 0 26rpx;
border-bottom: 1px solid #f4f4f4;
}
.cart-view .promotion .icon{
display: inline-block;
height: 24rpx;
width: 15rpx;
}
.cart-view .promotion{
margin-top: 25.5rpx;
float: left;
height: 43rpx;
width: 480rpx;
/*margin-right: 84rpx;*/
line-height: 43rpx;
font-size: 0;
}
.cart-view .promotion .tag{
border: 1px solid #f48f18;
height: 37rpx;
line-height: 31rpx;
padding: 0 9rpx;
margin-right: 10rpx;
color: #f48f18;
font-size: 24.5rpx;
}
.cart-view .promotion .txt{
height: 43rpx;
line-height: 43rpx;
padding-right: 10rpx;
color: #333;
font-size: 29rpx;
overflow: hidden;
}
.cart-view .get{
margin-top: 18rpx;
float: right;
height: 58rpx;
padding-left: 14rpx;
border-left: 1px solid #d9d9d9;
line-height: 58rpx;
font-size: 29rpx;
color: #333;
}
.cart-bottom{
position: fixed;
bottom:0;
left:0;
height: 100rpx;
width: 100%;
background: #fff;
display: flex;
}
.cart-bottom .checkbox{
height: 34rpx;
padding-left: 60rpx;
line-height: 34rpx;
margin: 33rpx 18rpx 33rpx 26rpx;
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/checkbox-0e09baa37e.png) no-repeat;
background-size: 34rpx;
font-size: 29rpx;
}
.cart-bottom .checkbox.checked{
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/checkbox-checked-822e54472a.png) no-repeat;
background-size: 34rpx;
}
.cart-bottom .total{
height: 34rpx;
flex: 1;
margin: 33rpx 10rpx;
font-size: 29rpx;
}
.cart-bottom .delete{
height: 34rpx;
width: auto;
margin: 33rpx 18rpx;
font-size: 29rpx;
}
.cart-bottom .checkout{
height: 100rpx;
width: 210rpx;
text-align: center;
line-height: 100rpx;
font-size: 29rpx;
background: #b4282d;
color: #fff;
}
================================================
FILE: pages/catalog/catalog.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
data: {
navList: [],
categoryList: [],
currentCategory: {},
scrollLeft: 0,
scrollTop: 0,
goodsCount: 0,
scrollHeight: 0
},
onLoad: function (options) {
this.getCatalog();
},
getCatalog: function () {
//CatalogList
let that = this;
wx.showLoading({
title: '加载中...',
});
util.request(api.CatalogList).then(function (res) {
that.setData({
navList: res.data.categoryList,
currentCategory: res.data.currentCategory
});
wx.hideLoading();
});
util.request(api.GoodsCount).then(function (res) {
that.setData({
goodsCount: res.data.goodsCount
});
});
},
getCurrentCategory: function (id) {
let that = this;
util.request(api.CatalogCurrent, { id: id })
.then(function (res) {
that.setData({
currentCategory: res.data.currentCategory
});
});
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
getList: function () {
var that = this;
util.request(api.ApiRootUrl + 'api/catalog/' + that.data.currentCategory.cat_id)
.then(function (res) {
that.setData({
categoryList: res.data,
});
});
},
switchCate: function (event) {
var that = this;
var currentTarget = event.currentTarget;
if (this.data.currentCategory.id == event.currentTarget.dataset.id) {
return false;
}
this.getCurrentCategory(event.currentTarget.dataset.id);
}
})
================================================
FILE: pages/catalog/catalog.json
================================================
{}
================================================
FILE: pages/catalog/catalog.wxml
================================================
<view class="container">
<view class="search">
<navigator url="/pages/search/search" class="input">
<image class="icon"></image>
<text class="txt">商品搜索, 共{{goodsCount}}款好物</text>
</navigator>
</view>
<view class="catalog">
<scroll-view class="nav" scroll-y="true">
<view class="item {{ currentCategory.id == item.id ? 'active' : ''}}" wx:for="{{navList}}" data-id="{{item.id}}" data-index="{{index}}" bindtap="switchCate">{{item.name}}</view>
</scroll-view>
<scroll-view class="cate" scroll-y="true">
<navigator url="url" class="banner">
<image class="image" src="{{currentCategory.wap_banner_url}}"></image>
<view class="txt">{{currentCategory.front_name}}</view>
</navigator>
<view class="hd">
<text class="line"></text>
<text class="txt">{{currentCategory.name}}分类</text>
<text class="line"></text>
</view>
<view class="bd">
<navigator url="/pages/category/category?id={{item.id}}" class="item {{(index+1) % 3 == 0 ? 'last' : ''}}" wx:for="{{currentCategory.subCategoryList}}">
<image class="icon" src="{{item.wap_banner_url}}"></image>
<text class="txt">{{item.name}}</text>
</navigator>
</view>
</scroll-view>
</view>
</view>
================================================
FILE: pages/catalog/catalog.wxss
================================================
page {
height: 100%;
}
.container {
background: #f9f9f9;
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
}
.search {
height: 88rpx;
width: 100%;
padding: 0 30rpx;
background: #fff;
display: flex;
align-items: center;
}
.search .input {
width: 690rpx;
height: 56rpx;
background: #ededed;
border-radius: 8rpx;
display: flex;
align-items: center;
justify-content: center;
}
.search .icon {
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/search2-2fb94833aa.png) center no-repeat;
background-size: 100%;
width: 28rpx;
height: 28rpx;
}
.search .txt {
height: 42rpx;
line-height: 42rpx;
color: #666;
padding-left: 10rpx;
font-size: 30rpx;
}
.catalog {
flex: 1;
width: 100%;
background: #fff;
display: flex;
border-top: 1px solid #fafafa;
}
.catalog .nav {
width: 162rpx;
height: 100%;
}
.catalog .nav .item {
text-align: center;
line-height: 90rpx;
width: 162rpx;
height: 90rpx;
color: #333;
font-size: 28rpx;
border-left: 6rpx solid #fff;
}
.catalog .nav .item.active {
color: #ab2b2b;
font-size: 36rpx;
border-left: 6rpx solid #ab2b2b;
}
.catalog .cate {
border-left: 1px solid #fafafa;
flex: 1;
height: 100%;
padding: 0 30rpx 0 30rpx;
}
.banner {
display: block;
height: 222rpx;
width: 100%;
position: relative;
}
.banner .image {
position: absolute;
top: 30rpx;
left: 0;
border-radius: 4rpx;
height: 192rpx;
width: 100%;
}
.banner .txt {
position: absolute;
top: 30rpx;
text-align: center;
color: #fff;
font-size: 28rpx;
left: 0;
height: 192rpx;
line-height: 192rpx;
width: 100%;
}
.catalog .hd {
height: 108rpx;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.catalog .hd .txt {
font-size: 24rpx;
text-align: center;
color: #333;
padding: 0 10rpx;
width: auto;
}
.catalog .hd .line {
width: 40rpx;
height: 1px;
background: #d9d9d9;
}
.catalog .bd {
height: auto;
width: 100%;
overflow: hidden;
}
.catalog .bd .item {
display: block;
float: left;
height: 216rpx;
width: 144rpx;
margin-right: 34rpx;
}
.catalog .bd .item.last {
margin-right: 0;
}
.catalog .bd .item .icon {
height: 144rpx;
width: 144rpx;
}
.catalog .bd .item .txt {
display: block;
text-align: center;
font-size: 24rpx;
color: #333;
height: 72rpx;
width: 144rpx;
}
================================================
FILE: pages/category/category.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
data: {
// text:"这是一个页面"
navList: [],
goodsList: [],
id: 0,
currentCategory: {},
scrollLeft: 0,
scrollTop: 0,
scrollHeight: 0,
page: 1,
size: 10000
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
var that = this;
if (options.id) {
that.setData({
id: parseInt(options.id)
});
}
wx.getSystemInfo({
success: function (res) {
that.setData({
scrollHeight: res.windowHeight
});
}
});
this.getCategoryInfo();
},
getCategoryInfo: function () {
let that = this;
util.request(api.GoodsCategory, { id: this.data.id })
.then(function (res) {
if (res.errno == 0) {
that.setData({
navList: res.data.brotherCategory,
currentCategory: res.data.currentCategory
});
//nav位置
let currentIndex = 0;
let navListCount = that.data.navList.length;
for (let i = 0; i < navListCount; i++) {
currentIndex += 1;
if (that.data.navList[i].id == that.data.id) {
break;
}
}
if (currentIndex > navListCount / 2 && navListCount > 5) {
that.setData({
scrollLeft: currentIndex * 60
});
}
that.getGoodsList();
} else {
//显示错误信息
}
});
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
console.log(1);
},
onHide: function () {
// 页面隐藏
},
getGoodsList: function () {
var that = this;
util.request(api.GoodsList, {categoryId: that.data.id, page: that.data.page, size: that.data.size})
.then(function (res) {
that.setData({
goodsList: res.data.goodsList,
});
});
},
onUnload: function () {
// 页面关闭
},
switchCate: function (event) {
if (this.data.id == event.currentTarget.dataset.id) {
return false;
}
var that = this;
var clientX = event.detail.x;
var currentTarget = event.currentTarget;
if (clientX < 60) {
that.setData({
scrollLeft: currentTarget.offsetLeft - 60
});
} else if (clientX > 330) {
that.setData({
scrollLeft: currentTarget.offsetLeft
});
}
this.setData({
id: event.currentTarget.dataset.id
});
this.getCategoryInfo();
}
})
================================================
FILE: pages/category/category.json
================================================
{}
================================================
FILE: pages/category/category.wxml
================================================
<view class="container">
<view class="cate-nav">
<scroll-view scroll-x="true" class="cate-nav-body" style="width: 750rpx;" scroll-left="{{scrollLeft}}">
<view wx:for="{{navList}}" class="item {{ id == item.id ? 'active' : ''}}" data-id="{{item.id}}" data-index="{{index}}" bindtap="switchCate">
<view class="name">{{item.name}}</view>
</view>
</scroll-view>
</view>
<scroll-view scroll-y="true" scroll-top="{{scrollTop}}" style="height:{{scrollHeight}};">
<view class="cate-item">
<view class="h">
<text class="name">{{currentCategory.name}}</text>
<text class="desc">{{currentCategory.front_name}}</text>
</view>
<view class="b">
<navigator class="item {{(iindex + 1) % 2 == 0 ? 'item-b' : ''}}" url="/pages/goods/goods?id={{iitem.id}}" wx:for="{{goodsList}}" wx:for-item="iitem" wx:for-index="iindex" >
<image class="img" src="{{iitem.list_pic_url}}" background-size="cover"></image>
<text class="name">{{iitem.name}}</text>
<text class="price">¥{{iitem.retail_price}}</text>
</navigator>
</view>
</view>
</scroll-view>
</view>
================================================
FILE: pages/category/category.wxss
================================================
.container{
background: #f9f9f9;
}
.cate-nav{
position: fixed;
left:0;
top:0;
z-index: 1000;
}
.cate-nav-body{
height: 84rpx;
white-space: nowrap;
background: #fff;
border-top: 1px solid rgba(0,0,0,.15);
overflow: hidden;
}
.cate-nav .item{
display: inline-block;
height: 84rpx;
min-width: 130rpx;
padding: 0 15rpx;
}
.cate-nav .item .name{
display: block;
height: 84rpx;
padding: 0 20rpx;
line-height: 84rpx;
color: #333;
font-size: 30rpx;
width: auto;
}
.cate-nav .item.active .name{
color: #ab2b2b;
border-bottom: 2px solid #ab2b2b;
}
.cate-item{
margin-top: 94rpx;
height: auto;
overflow: hidden;
}
.cate-item .h{
height: 145rpx;
width: 750rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.cate-item .h .name{
display: block;
height: 35rpx;
margin-bottom: 18rpx;
font-size: 30rpx;
color: #333;
}
.cate-item .h .desc{
display: block;
height: 24rpx;
font-size: 24rpx;
color: #999;
}
.cate-item .b{
width: 750rpx;
padding: 0 6.25rpx;
height: auto;
overflow: hidden;
}
.cate-item .b .item{
float: left;
background: #fff;
width: 365rpx;
margin-bottom: 6.25rpx;
padding-bottom: 33.333rpx;
height: auto;
overflow: hidden;
text-align: center;
}
.cate-item .b .item-b{
margin-left: 6.25rpx;
}
.cate-item .item .img{
width: 302rpx;
height: 302rpx;
}
.cate-item .item .name{
display: block;
width: 365.625rpx;
height: 35rpx;
margin: 11.5rpx 0 22rpx 0;
text-align: center;
overflow: hidden;
padding: 0 20rpx;
font-size: 30rpx;
color: #333;
}
.cate-item .item .price{
display: block;
width: 365.625rpx;
height: 30rpx;
text-align: center;
font-size: 30rpx;
color: #b4282d;
}
================================================
FILE: pages/comment/comment.js
================================================
var app = getApp();
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
data: {
comments: [],
allCommentList: [],
picCommentList: [],
typeId: 0,
valueId: 0,
showType: 0,
allCount: 0,
hasPicCount: 0,
allPage: 1,
picPage: 1,
size: 20
},
getCommentCount: function () {
let that = this;
util.request(api.CommentCount, { valueId: that.data.valueId, typeId: that.data.typeId}).then(function (res) {
if (res.errno === 0) {
that.setData({
allCount: res.data.allCount,
hasPicCount: res.data.hasPicCount
});
}
});
},
getCommentList: function(){
let that = this;
util.request(api.CommentList, {
valueId: that.data.valueId,
typeId: that.data.typeId,
size: that.data.size,
page: (that.data.showType == 0 ? that.data.allPage : that.data.picPage),
showType: that.data.showType
}).then(function (res) {
if (res.errno === 0) {
if (that.data.showType == 0) {
that.setData({
allCommentList: that.data.allCommentList.concat(res.data.data),
allPage: res.data.currentPage,
comments: that.data.allCommentList.concat(res.data.data)
});
} else {
that.setData({
picCommentList: that.data.picCommentList.concat(res.data.data),
picPage: res.data.currentPage,
comments: that.data.picCommentList.concat(res.data.data)
});
}
}
});
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.setData({
typeId: options.typeId,
valueId: options.valueId
});
this.getCommentCount();
this.getCommentList();
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
switchTab: function () {
this.setData({
showType: this.data.showType == 1 ? 0 :1
});
this.getCommentList();
},
onReachBottom: function(){
console.log('onPullDownRefresh');
if ( this.data.showType == 0) {
if (this.data.allCount / this.data.size < this.data.allPage) {
return false;
}
this.setData({
'allPage' : this.d
gitextract_vsm6etqj/
├── .gitignore
├── README.md
├── app.js
├── app.json
├── app.wxss
├── config/
│ └── api.js
├── lib/
│ └── wxParse/
│ ├── html2json.js
│ ├── htmlparser.js
│ ├── showdown.js
│ ├── wxDiscode.js
│ ├── wxParse.js
│ ├── wxParse.wxml
│ └── wxParse.wxss
├── pages/
│ ├── auth/
│ │ ├── login/
│ │ │ ├── login.js
│ │ │ ├── login.json
│ │ │ ├── login.wxml
│ │ │ └── login.wxss
│ │ ├── register/
│ │ │ ├── register.js
│ │ │ ├── register.json
│ │ │ ├── register.wxml
│ │ │ └── register.wxss
│ │ └── reset/
│ │ ├── reset.js
│ │ ├── reset.json
│ │ ├── reset.wxml
│ │ └── reset.wxss
│ ├── brand/
│ │ ├── brand.js
│ │ ├── brand.json
│ │ ├── brand.wxml
│ │ └── brand.wxss
│ ├── brandDetail/
│ │ ├── brandDetail.js
│ │ ├── brandDetail.json
│ │ ├── brandDetail.wxml
│ │ └── brandDetail.wxss
│ ├── cart/
│ │ ├── cart.js
│ │ ├── cart.json
│ │ ├── cart.wxml
│ │ └── cart.wxss
│ ├── catalog/
│ │ ├── catalog.js
│ │ ├── catalog.json
│ │ ├── catalog.wxml
│ │ └── catalog.wxss
│ ├── category/
│ │ ├── category.js
│ │ ├── category.json
│ │ ├── category.wxml
│ │ └── category.wxss
│ ├── comment/
│ │ ├── comment.js
│ │ ├── comment.json
│ │ ├── comment.wxml
│ │ └── comment.wxss
│ ├── commentPost/
│ │ ├── commentPost.js
│ │ ├── commentPost.json
│ │ ├── commentPost.wxml
│ │ └── commentPost.wxss
│ ├── goods/
│ │ ├── goods.js
│ │ ├── goods.json
│ │ ├── goods.wxml
│ │ └── goods.wxss
│ ├── hotGoods/
│ │ ├── hotGoods.js
│ │ ├── hotGoods.json
│ │ ├── hotGoods.wxml
│ │ └── hotGoods.wxss
│ ├── index/
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxss
│ ├── logs/
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
│ ├── newGoods/
│ │ ├── newGoods.js
│ │ ├── newGoods.json
│ │ ├── newGoods.wxml
│ │ └── newGoods.wxss
│ ├── pay/
│ │ ├── pay.js
│ │ ├── pay.json
│ │ ├── pay.wxml
│ │ └── pay.wxss
│ ├── payResult/
│ │ ├── payResult.js
│ │ ├── payResult.json
│ │ ├── payResult.wxml
│ │ └── payResult.wxss
│ ├── search/
│ │ ├── search.js
│ │ ├── search.json
│ │ ├── search.wxml
│ │ └── search.wxss
│ ├── shopping/
│ │ ├── address/
│ │ │ ├── address.js
│ │ │ ├── address.json
│ │ │ ├── address.wxml
│ │ │ └── address.wxss
│ │ ├── addressAdd/
│ │ │ ├── addressAdd.js
│ │ │ ├── addressAdd.json
│ │ │ ├── addressAdd.wxml
│ │ │ └── addressAdd.wxss
│ │ └── checkout/
│ │ ├── checkout.js
│ │ ├── checkout.json
│ │ ├── checkout.wxml
│ │ └── checkout.wxss
│ ├── topic/
│ │ ├── topic.js
│ │ ├── topic.json
│ │ ├── topic.wxml
│ │ └── topic.wxss
│ ├── topicComment/
│ │ ├── topicComment.js
│ │ ├── topicComment.json
│ │ ├── topicComment.wxml
│ │ └── topicComment.wxss
│ ├── topicDetail/
│ │ ├── topicDetail.js
│ │ ├── topicDetail.json
│ │ ├── topicDetail.wxml
│ │ └── topicDetail.wxss
│ └── ucenter/
│ ├── address/
│ │ ├── address.js
│ │ ├── address.json
│ │ ├── address.wxml
│ │ └── address.wxss
│ ├── addressAdd/
│ │ ├── addressAdd.js
│ │ ├── addressAdd.json
│ │ ├── addressAdd.wxml
│ │ └── addressAdd.wxss
│ ├── collect/
│ │ ├── collect.js
│ │ ├── collect.json
│ │ ├── collect.wxml
│ │ └── collect.wxss
│ ├── coupon/
│ │ ├── coupon.js
│ │ ├── coupon.json
│ │ ├── coupon.wxml
│ │ └── coupon.wxss
│ ├── express/
│ │ ├── express.js
│ │ ├── express.json
│ │ ├── express.wxml
│ │ └── express.wxss
│ ├── feedback/
│ │ ├── feedback.js
│ │ ├── feedback.json
│ │ ├── feedback.wxml
│ │ └── feedback.wxss
│ ├── footprint/
│ │ ├── footprint.js
│ │ ├── footprint.json
│ │ ├── footprint.wxml
│ │ └── footprint.wxss
│ ├── index/
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxss
│ ├── order/
│ │ ├── order.js
│ │ ├── order.json
│ │ ├── order.wxml
│ │ └── order.wxss
│ └── orderDetail/
│ ├── orderDetail.js
│ ├── orderDetail.json
│ ├── orderDetail.wxml
│ └── orderDetail.wxss
├── services/
│ ├── pay.js
│ └── user.js
└── utils/
└── util.js
SYMBOL INDEX (119 symbols across 28 files)
FILE: lib/wxParse/html2json.js
function makeMap (line 35) | function makeMap(str) {
function q (line 42) | function q(v) {
function removeDOCTYPE (line 46) | function removeDOCTYPE(html) {
function html2json (line 54) | function html2json(html, bindName) {
function transEmojiStr (line 197) | function transEmojiStr(str){
function emojisInit (line 232) | function emojisInit(reg='',baseSrc="/wxParse/emojis/",emojis){
FILE: lib/wxParse/htmlparser.js
function HTMLParser (line 35) | function HTMLParser(html, handler) {
function makeMap (line 175) | function makeMap(str) {
FILE: lib/wxParse/showdown.js
function getDefaultOpts (line 12) | function getDefaultOpts(simple) {
function validate (line 307) | function validate(extension, name) {
function escapeCharactersCallback (line 506) | function escapeCharactersCallback(wholeMatch, m1) {
function _constructor (line 746) | function _constructor() {
function _parseExtension (line 778) | function _parseExtension(ext, name) {
function legacyExtensionLoading (line 842) | function legacyExtensionLoading(ext, name) {
function listen (line 874) | function listen(name, callback) {
function rTrimInputText (line 889) | function rTrimInputText(text) {
function replaceLink (line 1259) | function replaceLink(wm, link) {
function replaceMail (line 1267) | function replaceMail(wholeMatch, m1) {
function headerId (line 1874) | function headerId(m) {
function writeImageTag (line 1910) | function writeImageTag (wholeMatch, altText, linkId, url, width, height,...
function processListItems (line 2014) | function processListItems (listStr, trimTrailing) {
function parseConsecutiveLists (line 2102) | function parseConsecutiveLists(list, listType, trimTrailing) {
function parseStyles (line 2396) | function parseStyles(sLine) {
function parseHeaders (line 2408) | function parseHeaders(header, style) {
function parseCells (line 2419) | function parseCells(cell, style) {
function buildTable (line 2424) | function buildTable(headers, cells) {
FILE: lib/wxParse/wxDiscode.js
function strNumDiscode (line 2) | function strNumDiscode(str){
function strGreeceDiscode (line 44) | function strGreeceDiscode(str){
function strcharacterDiscode (line 104) | function strcharacterDiscode(str){
function strOtherDiscode (line 119) | function strOtherDiscode(str){
function strMoreDiscode (line 177) | function strMoreDiscode(str){
function strDiscode (line 185) | function strDiscode(str){
function urlToHttpUrl (line 193) | function urlToHttpUrl(url,rep){
FILE: lib/wxParse/wxParse.js
function wxParse (line 23) | function wxParse(bindName = 'wxParseData', type='html', data='<div class...
function wxParseImgTap (line 47) | function wxParseImgTap(e) {
function wxParseImgLoad (line 62) | function wxParseImgLoad(e) {
function calMoreImageInfo (line 71) | function calMoreImageInfo(e, idx, that, bindName) {
function wxAutoImageCal (line 88) | function wxAutoImageCal(originalWidth, originalHeight,that,bindName) {
function wxParseTemArray (line 116) | function wxParseTemArray(temArrayName,bindNameReg,total,that){
function emojisInit (line 136) | function emojisInit(reg='',baseSrc="/wxParse/emojis/",emojis){
FILE: pages/brand/brand.js
method onReachBottom (line 30) | onReachBottom (){
FILE: pages/brandDetail/brandDetail.js
method getGoodsList (line 35) | getGoodsList() {
FILE: pages/commentPost/commentPost.js
method onClose (line 19) | onClose() {
method onPost (line 24) | onPost() {
method bindInpuntValue (line 51) | bindInpuntValue(event){
FILE: pages/hotGoods/hotGoods.js
method getGoodsList (line 31) | getGoodsList (){
FILE: pages/newGoods/newGoods.js
method getGoodsList (line 31) | getGoodsList() {
FILE: pages/pay/pay.js
method requestPayParam (line 33) | requestPayParam() {
method startPay (line 58) | startPay() {
FILE: pages/payResult/payResult.js
method payOrder (line 33) | payOrder() {
FILE: pages/search/search.js
method getSearchKeyword (line 39) | getSearchKeyword() {
method getSearchResult (line 113) | getSearchResult(keyword) {
method onKeywordConfirm (line 176) | onKeywordConfirm(event) {
FILE: pages/shopping/address/address.js
method getAddressList (line 20) | getAddressList (){
method addressAddOrUpdate (line 30) | addressAddOrUpdate (event) {
method selectAddress (line 36) | selectAddress(event){
FILE: pages/shopping/addressAdd/addressAdd.js
method bindinputMobile (line 28) | bindinputMobile(event) {
method bindinputName (line 35) | bindinputName(event) {
method bindinputAddress (line 42) | bindinputAddress (event){
method bindIsDefault (line 49) | bindIsDefault(){
method getAddressDetail (line 56) | getAddressDetail() {
method setRegionDoneStatus (line 66) | setRegionDoneStatus() {
method chooseRegion (line 77) | chooseRegion() {
method selectRegionType (line 136) | selectRegionType(event) {
method selectRegion (line 157) | selectRegion(event) {
method doneSelectRegion (line 210) | doneSelectRegion() {
method cancelSelectRegion (line 233) | cancelSelectRegion() {
method getRegionList (line 240) | getRegionList(regionId) {
method cancelAddress (line 261) | cancelAddress(){
method saveAddress (line 266) | saveAddress(){
FILE: pages/shopping/checkout/checkout.js
method selectAddress (line 65) | selectAddress() {
method addAddress (line 70) | addAddress() {
FILE: pages/topicDetail/topicDetail.js
method getCommentList (line 41) | getCommentList(){
method postComment (line 53) | postComment (){
FILE: pages/ucenter/address/address.js
method getAddressList (line 20) | getAddressList (){
method addressAddOrUpdate (line 30) | addressAddOrUpdate (event) {
method deleteAddress (line 36) | deleteAddress(event){
FILE: pages/ucenter/addressAdd/addressAdd.js
method bindinputMobile (line 28) | bindinputMobile(event) {
method bindinputName (line 35) | bindinputName(event) {
method bindinputAddress (line 42) | bindinputAddress (event){
method bindIsDefault (line 49) | bindIsDefault(){
method getAddressDetail (line 56) | getAddressDetail() {
method setRegionDoneStatus (line 66) | setRegionDoneStatus() {
method chooseRegion (line 77) | chooseRegion() {
method selectRegionType (line 136) | selectRegionType(event) {
method selectRegion (line 157) | selectRegion(event) {
method doneSelectRegion (line 210) | doneSelectRegion() {
method cancelSelectRegion (line 233) | cancelSelectRegion() {
method getRegionList (line 240) | getRegionList(regionId) {
method cancelAddress (line 261) | cancelAddress(){
method saveAddress (line 266) | saveAddress(){
FILE: pages/ucenter/collect/collect.js
method getCollectList (line 11) | getCollectList() {
method openGoods (line 38) | openGoods(event) {
FILE: pages/ucenter/express/express.js
method getExpressInfo (line 24) | getExpressInfo() {
method updateExpress (line 35) | updateExpress() {
FILE: pages/ucenter/footprint/footprint.js
method getFootprintList (line 12) | getFootprintList() {
method deleteItem (line 23) | deleteItem (event){
FILE: pages/ucenter/index/index.js
method showLoginDialog (line 38) | showLoginDialog() {
method onCloseLoginDialog (line 44) | onCloseLoginDialog () {
method onDialogBody (line 50) | onDialogBody () {
method onWechatLogin (line 54) | onWechatLogin(e) {
FILE: pages/ucenter/order/order.js
method getOrderList (line 13) | getOrderList(){
method payOrder (line 24) | payOrder(){
FILE: pages/ucenter/orderDetail/orderDetail.js
method getOrderDetail (line 18) | getOrderDetail() {
method payTimer (line 34) | payTimer() {
method payOrder (line 46) | payOrder() {
FILE: services/pay.js
function payOrder (line 11) | function payOrder(orderId) {
FILE: services/user.js
function loginByWeixin (line 12) | function loginByWeixin() {
function checkLogin (line 43) | function checkLogin() {
FILE: utils/util.js
function formatTime (line 3) | function formatTime(date) {
function formatNumber (line 16) | function formatNumber(n) {
function request (line 24) | function request(url, data = {}, method = "GET") {
function get (line 80) | function get(url, data = {}) {
function post (line 84) | function post(url, data = {}) {
function checkSession (line 91) | function checkSession() {
function login (line 107) | function login() {
function getUserInfo (line 124) | function getUserInfo() {
function redirect (line 142) | function redirect(url) {
function showErrorToast (line 157) | function showErrorToast(msg) {
Condensed preview — 152 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (413K chars).
[
{
"path": ".gitignore",
"chars": 20,
"preview": "project.config.json\n"
},
{
"path": "README.md",
"chars": 2234,
"preview": "### NideShop商城(微信小程序端)\n\n+ 界面高仿网易严选商城(主要是2016年wap版)\n+ 测试数据采集自网易严选商城\n+ 功能和数据库参考ecshop\n+ 服务端api基于Node.js+ThinkJS+MySQL\n+ 计划"
},
{
"path": "app.js",
"chars": 394,
"preview": "App({\n onLaunch: function () {\n try {\n this.globalData.userInfo = JSON.parse(wx.getStorageSync('userInfo'));\n "
},
{
"path": "app.json",
"chars": 2631,
"preview": "{\n \"pages\": [\n \"pages/index/index\",\n \"pages/catalog/catalog\",\n \"pages/newGoods/newGoods\",\n \"pages/hotGoods/"
},
{
"path": "app.wxss",
"chars": 324,
"preview": "/**app.wxss**/\n.container {\n box-sizing: border-box;\n background-color: #f4f4f4;\n font-family: PingFangSC-Light,helve"
},
{
"path": "config/api.js",
"chars": 2549,
"preview": "const ApiRootUrl = 'http://127.0.0.1:8360/api/';\n\nmodule.exports = {\n IndexUrl: ApiRootUrl + 'index/index', //首页数据接口\n "
},
{
"path": "lib/wxParse/html2json.js",
"chars": 7704,
"preview": "/**\n * author: Di (微信小程序开发工程师)\n * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)\n * 垂直微信小程序开发交流社区\n"
},
{
"path": "lib/wxParse/htmlparser.js",
"chars": 4983,
"preview": "/**\n * author: Di (微信小程序开发工程师)\n * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)\n * 垂直微信小程序开发交流社区\n"
},
{
"path": "lib/wxParse/showdown.js",
"chars": 72175,
"preview": "/**\n * author: Di (微信小程序开发工程师)\n * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)\n * 垂直微信小程序开发交流社区\n"
},
{
"path": "lib/wxParse/wxDiscode.js",
"chars": 6683,
"preview": "// HTML 支持的数学符号\nfunction strNumDiscode(str){\n str = str.replace(/∀/g, '∀');\n str = str.replace(/∂/g, '"
},
{
"path": "lib/wxParse/wxParse.js",
"chars": 3973,
"preview": "/**\n * author: Di (微信小程序开发工程师)\n * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)\n * 垂直微信小程序开发交流社区\n"
},
{
"path": "lib/wxParse/wxParse.wxml",
"chars": 35797,
"preview": "\n<!--**\n * author: Di (微信小程序开发工程师)\n * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)\n * 垂直微信小程序开发交"
},
{
"path": "lib/wxParse/wxParse.wxss",
"chars": 3923,
"preview": "\n/**\n * author: Di (微信小程序开发工程师)\n * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)\n * 垂直微信小程序开发交流社区"
},
{
"path": "pages/auth/login/login.js",
"chars": 1991,
"preview": "var api = require('../../../config/api.js');\nvar app = getApp();\nPage({\n data: {\n username: '',\n password: '',\n "
},
{
"path": "pages/auth/login/login.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/auth/login/login.wxml",
"chars": 1438,
"preview": "<view class=\"container\">\n <view class=\"form-box\">\n\n \t<view class=\"form-item\">\n \t\t<input class=\"username\" value="
},
{
"path": "pages/auth/login/login.wxss",
"chars": 1435,
"preview": ".form-box{\n width: 100%;\n height: auto;\n overflow: hidden;\n padding: 0 40rpx;\n margin-top: 96rpx;\n bac"
},
{
"path": "pages/auth/register/register.js",
"chars": 2498,
"preview": "var api = require('../../../config/api.js');\nvar app = getApp();\nPage({\n data: {\n username: '',\n password: '',\n "
},
{
"path": "pages/auth/register/register.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/auth/register/register.wxml",
"chars": 1535,
"preview": "<view class=\"container\">\n <view class=\"form-box\">\n\n \t<view class=\"form-item\">\n \t\t<input class=\"username\" value="
},
{
"path": "pages/auth/register/register.wxss",
"chars": 1435,
"preview": ".form-box{\n width: 100%;\n height: auto;\n overflow: hidden;\n padding: 0 40rpx;\n margin-top: 96rpx;\n bac"
},
{
"path": "pages/auth/reset/reset.js",
"chars": 837,
"preview": "var app = getApp();\nPage({\n data: {\n username: '',\n code: ''\n },\n onLoad: function (options) {\n // 页面初始化 opt"
},
{
"path": "pages/auth/reset/reset.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/auth/reset/reset.wxml",
"chars": 896,
"preview": "<view class=\"container\">\n <view class=\"form-box\">\n\n \t<view class=\"form-item\">\n \t\t<input class=\"username\" value="
},
{
"path": "pages/auth/reset/reset.wxss",
"chars": 1110,
"preview": ".form-box{\n width: 100%;\n height: auto;\n overflow: hidden;\n padding: 0 40rpx;\n margin-top: 96rpx;\n bac"
},
{
"path": "pages/brand/brand.js",
"chars": 1067,
"preview": "var util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\nvar app = getApp();\nPage({\n data: "
},
{
"path": "pages/brand/brand.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/brand/brand.wxml",
"chars": 647,
"preview": "<view class=\"container\">\n <view class=\"brand-list\" >\n <navigator url=\"../brandDetail/brandDetail?id={{item.id}"
},
{
"path": "pages/brand/brand.wxss",
"chars": 871,
"preview": ".brand-list .item{\n display: block;\n width: 750rpx;\n height: 416rpx;\n position: relative;\n margin-bottom:"
},
{
"path": "pages/brandDetail/brandDetail.js",
"chars": 1126,
"preview": "var util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\n\n\nvar app = getApp();\n\nPage({\n dat"
},
{
"path": "pages/brandDetail/brandDetail.json",
"chars": 8,
"preview": "{\n \n}"
},
{
"path": "pages/brandDetail/brandDetail.wxml",
"chars": 1061,
"preview": "<view class=\"container\">\n <view class=\"brand-info\">\n <view class=\"name\">\n <image class=\"img\" src=\"{"
},
{
"path": "pages/brandDetail/brandDetail.wxss",
"chars": 1760,
"preview": "page{\n background: #f4f4f4;\n}\n.brand-info .name{\n width: 100%;\n height: 290rpx;\n position: relative;\n}\n\n.bra"
},
{
"path": "pages/cart/cart.js",
"chars": 6824,
"preview": "var util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\n\nvar app = getApp();\n\nPage({\n data"
},
{
"path": "pages/cart/cart.json",
"chars": 36,
"preview": "{\n \"backgroundColor\": \"#f4f4f4\"\n}"
},
{
"path": "pages/cart/cart.wxml",
"chars": 3894,
"preview": "<view class=\"container\">\n <view class=\"service-policy\">\n <view class=\"item\">30天无忧退货</view>\n <view class=\"item\">48"
},
{
"path": "pages/cart/cart.wxss",
"chars": 6673,
"preview": "page{\n height: 100%;\n min-height: 100%;\n background: #f4f4f4;\n}\n.container{\n background: #f4f4f4;\n width:"
},
{
"path": "pages/catalog/catalog.js",
"chars": 1706,
"preview": "var util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\n\nPage({\n data: {\n navList: [],\n"
},
{
"path": "pages/catalog/catalog.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/catalog/catalog.wxml",
"chars": 1347,
"preview": "<view class=\"container\">\n <view class=\"search\">\n <navigator url=\"/pages/search/search\" class=\"input\">\n <image c"
},
{
"path": "pages/catalog/catalog.wxss",
"chars": 2439,
"preview": "page {\n height: 100%;\n}\n\n.container {\n background: #f9f9f9;\n height: 100%;\n width: 100%;\n display: flex;\n flex-dir"
},
{
"path": "pages/category/category.js",
"chars": 2528,
"preview": "var util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\n\nPage({\n data: {\n // text:\"这是一个"
},
{
"path": "pages/category/category.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/category/category.wxml",
"chars": 1241,
"preview": "<view class=\"container\">\n <view class=\"cate-nav\">\n <scroll-view scroll-x=\"true\" class=\"cate-nav-body\" style=\"w"
},
{
"path": "pages/category/category.wxss",
"chars": 1848,
"preview": ".container{\n background: #f9f9f9;\n}\n.cate-nav{\n position: fixed;\n left:0;\n top:0;\n z-index: 1000;\n}\n\n.cat"
},
{
"path": "pages/comment/comment.js",
"chars": 2587,
"preview": "var app = getApp();\nvar util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\n\nPage({\n data:"
},
{
"path": "pages/comment/comment.json",
"chars": 4,
"preview": "{\n\n}"
},
{
"path": "pages/comment/comment.wxml",
"chars": 1270,
"preview": "<view class=\"comments\">\n <view class=\"h\">\n <view class=\"item {{ showType == 0 ? 'active' : ''}}\" bindtap=\"swit"
},
{
"path": "pages/comment/comment.wxss",
"chars": 2506,
"preview": ".comments{\n width: 100%;\n height: auto;\n padding-left:30rpx;\n background: #fff;\n margin: 20rpx 0;\n}\n\n.com"
},
{
"path": "pages/commentPost/commentPost.js",
"chars": 1355,
"preview": "var app = getApp();\nvar util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\nPage({\n data: "
},
{
"path": "pages/commentPost/commentPost.json",
"chars": 38,
"preview": "{\n \"navigationBarTitleText\": \"填写留言\"\n}"
},
{
"path": "pages/commentPost/commentPost.wxml",
"chars": 476,
"preview": "<view class=\"container\">\n <view class=\"post-comment\">\n <view class=\"input-box\">\n <textarea class=\"con"
},
{
"path": "pages/commentPost/commentPost.wxss",
"chars": 948,
"preview": "page, .container {\n height: 100%;\n background: #f4f4f4;\n}\n\n.post-comment {\n width: 750rpx;\n height: auto;\n overflow"
},
{
"path": "pages/goods/goods.js",
"chars": 8364,
"preview": "var app = getApp();\nvar WxParse = require('../../lib/wxParse/wxParse.js');\nvar util = require('../../utils/util.js');\nva"
},
{
"path": "pages/goods/goods.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/goods/goods.wxml",
"chars": 5761,
"preview": "<view class=\"container\">\n <swiper class=\"goodsimgs\" indicator-dots=\"true\" autoplay=\"true\" interval=\"3000\" duration=\"100"
},
{
"path": "pages/goods/goods.wxss",
"chars": 11622,
"preview": ".container {\n margin-bottom: 100rpx;\n}\n\n.goodsimgs {\n width: 750rpx;\n height: 750rpx;\n}\n\n.goodsimgs image {\n width: "
},
{
"path": "pages/hotGoods/hotGoods.js",
"chars": 2450,
"preview": "var util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\nvar app = getApp();\n\nPage({\n data:"
},
{
"path": "pages/hotGoods/hotGoods.json",
"chars": 8,
"preview": "{\n \n}"
},
{
"path": "pages/hotGoods/hotGoods.wxml",
"chars": 1781,
"preview": "<view class=\"container\">\n <view class=\"brand-info\">\n <view class=\"name\">\n <image class=\"img\" src=\"{{bannerInfo."
},
{
"path": "pages/hotGoods/hotGoods.wxss",
"chars": 3213,
"preview": "page{\n background: #f4f4f4;\n}\n\n.brand-info .name{\n width: 100%;\n height: 278rpx;\n position: relative;\n}\n\n.br"
},
{
"path": "pages/index/index.js",
"chars": 1300,
"preview": "const util = require('../../utils/util.js');\nconst api = require('../../config/api.js');\nconst user = require('../../ser"
},
{
"path": "pages/index/index.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/index/index.wxml",
"chars": 4594,
"preview": "<!--index.wxml-->\n<view class=\"container\">\n <view class=\"search\">\n <navigator url=\"/pages/search/search\" class=\"inpu"
},
{
"path": "pages/index/index.wxss",
"chars": 5788,
"preview": "\n.search {\n height: 88rpx;\n width: 100%;\n padding: 0 30rpx;\n background: #fff;\n display: flex;\n align-items: cente"
},
{
"path": "pages/logs/logs.js",
"chars": 266,
"preview": "//logs.js\nvar util = require('../../utils/util.js')\nPage({\n data: {\n logs: []\n },\n onLoad: function () {\n this."
},
{
"path": "pages/logs/logs.json",
"chars": 42,
"preview": "{\n \"navigationBarTitleText\": \"查看启动日志\"\n}"
},
{
"path": "pages/logs/logs.wxml",
"chars": 173,
"preview": "<!--logs.wxml-->\n<view class=\"container log-list\">\n <block wx:for=\"{{logs}}\" wx:for-item=\"log\">\n <text class=\"log-it"
},
{
"path": "pages/logs/logs.wxss",
"chars": 106,
"preview": ".log-list {\n display: flex;\n flex-direction: column;\n padding: 40rpx;\n}\n.log-item {\n margin: 10rpx;\n}\n"
},
{
"path": "pages/newGoods/newGoods.js",
"chars": 2453,
"preview": "var util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\nvar app = getApp();\n\nPage({\n data:"
},
{
"path": "pages/newGoods/newGoods.json",
"chars": 8,
"preview": "{\n \n}"
},
{
"path": "pages/newGoods/newGoods.wxml",
"chars": 1781,
"preview": "<view class=\"container\">\n <view class=\"brand-info\">\n <view class=\"name\">\n <image class=\"img\" src=\"{{bannerInfo."
},
{
"path": "pages/newGoods/newGoods.wxss",
"chars": 3213,
"preview": "page{\n background: #f4f4f4;\n}\n\n.brand-info .name{\n width: 100%;\n height: 278rpx;\n position: relative;\n}\n\n.br"
},
{
"path": "pages/pay/pay.js",
"chars": 1330,
"preview": "var app = getApp();\nvar util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\n\nPage({\n data:"
},
{
"path": "pages/pay/pay.json",
"chars": 38,
"preview": "{\n \"navigationBarTitleText\": \"支付订单\"\n}"
},
{
"path": "pages/pay/pay.wxml",
"chars": 1022,
"preview": "<view class=\"container\">\n <view class=\"total\">\n <view class=\"label\">订单金额</view>\n <view class=\"txt\">{{actual"
},
{
"path": "pages/pay/pay.wxss",
"chars": 2591,
"preview": "page{\n min-height: 100%;\n width: 100%;\n background: #f4f4f4;\n}\n\n.container{\n padding-top: 20rpx;\n}\n\n.total{\n "
},
{
"path": "pages/payResult/payResult.js",
"chars": 726,
"preview": "var util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\nconst pay = require('../../services"
},
{
"path": "pages/payResult/payResult.json",
"chars": 87,
"preview": "{\n \"navigationBarTitleText\": \"付款结果\",\n \"navigationBarBackgroundColor\": \"#fafafa\"\n}"
},
{
"path": "pages/payResult/payResult.wxml",
"chars": 861,
"preview": "<view class=\"container\">\n <view class=\"pay-result\">\n <view class=\"success\" wx:if=\"{{status == true}}\">\n <view c"
},
{
"path": "pages/payResult/payResult.wxss",
"chars": 853,
"preview": "page {\n min-height: 100%;\n width: 100%;\n background: #fff;\n}\n\n.container {\n height: 100%;\n background: #fff;\n}\n\n.pa"
},
{
"path": "pages/search/search.js",
"chars": 4291,
"preview": "var util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\n\nvar app = getApp()\nPage({\n data: "
},
{
"path": "pages/search/search.json",
"chars": 8,
"preview": "{\n \n}"
},
{
"path": "pages/search/search.wxml",
"chars": 3674,
"preview": "<scroll-view class=\"container\" style=\"height: 100%;\">\n <view class=\"search-header\">\n <view class=\"input-box\">\n "
},
{
"path": "pages/search/search.wxss",
"chars": 5817,
"preview": "page{\n min-height: 100%;\n background-color: #f4f4f4;\n}\n\n.container{\n min-height: 100%;\n background-color: #f4f4f4;\n}"
},
{
"path": "pages/shopping/address/address.js",
"chars": 1104,
"preview": "var util = require('../../../utils/util.js');\nvar api = require('../../../config/api.js');\nvar app = getApp();\n\nPage({\n "
},
{
"path": "pages/shopping/address/address.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/shopping/address/address.wxml",
"chars": 1247,
"preview": "<view class=\"container\">\n <view class=\"address-list\" wx:if=\"{{ addressList.length > 0 }}\">\n <view class=\"item\""
},
{
"path": "pages/shopping/address/address.wxss",
"chars": 2176,
"preview": "page{\n height: 100%;\n width: 100%;\n background: #f4f4f4;\n}\n\n.container{\n height: 100%;\n width: 100%;\n}\n\n.addr"
},
{
"path": "pages/shopping/addressAdd/addressAdd.js",
"chars": 7666,
"preview": "var util = require('../../../utils/util.js');\nvar api = require('../../../config/api.js');\nvar app = getApp();\nPage({\n "
},
{
"path": "pages/shopping/addressAdd/addressAdd.json",
"chars": 8,
"preview": "{\n \n}"
},
{
"path": "pages/shopping/addressAdd/addressAdd.wxml",
"chars": 1964,
"preview": "<view class=\"add-address\">\n <view class=\"add-form\">\n <view class=\"form-item\">\n <input class=\"input\""
},
{
"path": "pages/shopping/addressAdd/addressAdd.wxss",
"chars": 3085,
"preview": "page{\n height: 100%;\n background: #f4f4f4;\n}\n.add-address .add-form{\n background: #fff;\n width: 100%;\n he"
},
{
"path": "pages/shopping/checkout/checkout.js",
"chars": 2864,
"preview": "var util = require('../../../utils/util.js');\nvar api = require('../../../config/api.js');\nconst pay = require('../../.."
},
{
"path": "pages/shopping/checkout/checkout.json",
"chars": 8,
"preview": "{\n \n}"
},
{
"path": "pages/shopping/checkout/checkout.wxml",
"chars": 3021,
"preview": "<view class=\"container\">\n <view class=\"address-box\">\n <view class=\"address-item\" bindtap=\"selectAddress\" wx:if"
},
{
"path": "pages/shopping/checkout/checkout.wxss",
"chars": 4964,
"preview": "page{\n height: 100%;\n background: #f4f4f4;\n}\n\n.address-box{\n width: 100%;\n height: 166.55rpx;\n background"
},
{
"path": "pages/topic/topic.js",
"chars": 1842,
"preview": "var util = require('../../utils/util.js');\nvar api = require('../../config/api.js');\nvar app = getApp()\nPage({\n data:"
},
{
"path": "pages/topic/topic.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/topic/topic.wxml",
"chars": 849,
"preview": "<view class=\"container\">\n <scroll-view class=\"topic-list\" scroll-y=\"true\" scroll-top=\"{{scrollTop}}\">\n <naviga"
},
{
"path": "pages/topic/topic.wxss",
"chars": 1475,
"preview": "page ,.container{\n width: 750rpx;\n height: 100%;\n overflow: hidden;\n background: #f4f4f4;\n}\n.topic-list{\n "
},
{
"path": "pages/topicComment/topicComment.js",
"chars": 2588,
"preview": "var app = getApp();\nvar util = require('../../utils/util.js');\n\nvar api = require('../../config/api.js');\n\nPage({\n data"
},
{
"path": "pages/topicComment/topicComment.json",
"chars": 4,
"preview": "{\n\n}"
},
{
"path": "pages/topicComment/topicComment.wxml",
"chars": 839,
"preview": "<view class=\"comments\">\n <view class=\"b\">\n <view class=\"item\" wx:for=\"{{comments}}\" wx:key=\"{{item.id}}\">\n <vie"
},
{
"path": "pages/topicComment/topicComment.wxss",
"chars": 1709,
"preview": ".comments{\n width: 100%;\n height: auto;\n padding-left:30rpx;\n background: #fff;\n margin: 20rpx 0;\n}\n\n.com"
},
{
"path": "pages/topicDetail/topicDetail.js",
"chars": 1489,
"preview": "var app = getApp();\nvar WxParse = require('../../lib/wxParse/wxParse.js');\nvar util = require('../../utils/util.js');\nva"
},
{
"path": "pages/topicDetail/topicDetail.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/topicDetail/topicDetail.wxml",
"chars": 2013,
"preview": "<scroll-view class=\"container\">\n <scroll-view class=\"content\">\n <import src=\"../../lib/wxParse/wxParse.wxml\"/> \n "
},
{
"path": "pages/topicDetail/topicDetail.wxss",
"chars": 2976,
"preview": "\n\n\n.content{\n width: 100%;\n height: auto;\n font-size: 0;\n}\n\n.content image{\n display: inline-block;\n widt"
},
{
"path": "pages/ucenter/address/address.js",
"chars": 1347,
"preview": "var util = require('../../../utils/util.js');\nvar api = require('../../../config/api.js');\nvar app = getApp();\n\nPage({\n "
},
{
"path": "pages/ucenter/address/address.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/ucenter/address/address.wxml",
"chars": 1172,
"preview": "<view class=\"container\">\n <view class=\"address-list\" wx:if=\"{{ addressList.length > 0 }}\">\n <view class=\"item\""
},
{
"path": "pages/ucenter/address/address.wxss",
"chars": 2115,
"preview": "page{\n height: 100%;\n width: 100%;\n background: #f4f4f4;\n}\n\n.container{\n height: 100%;\n width: 100%;\n}\n\n.addr"
},
{
"path": "pages/ucenter/addressAdd/addressAdd.js",
"chars": 7668,
"preview": "var util = require('../../../utils/util.js');\nvar api = require('../../../config/api.js');\nvar app = getApp();\nPage({\n "
},
{
"path": "pages/ucenter/addressAdd/addressAdd.json",
"chars": 8,
"preview": "{\n \n}"
},
{
"path": "pages/ucenter/addressAdd/addressAdd.wxml",
"chars": 1964,
"preview": "<view class=\"add-address\">\n <view class=\"add-form\">\n <view class=\"form-item\">\n <input class=\"input\""
},
{
"path": "pages/ucenter/addressAdd/addressAdd.wxss",
"chars": 3085,
"preview": "page{\n height: 100%;\n background: #f4f4f4;\n}\n.add-address .add-form{\n background: #fff;\n width: 100%;\n he"
},
{
"path": "pages/ucenter/collect/collect.js",
"chars": 2012,
"preview": "var util = require('../../../utils/util.js');\nvar api = require('../../../config/api.js');\n\nvar app = getApp();\n\nPage({\n"
},
{
"path": "pages/ucenter/collect/collect.json",
"chars": 6,
"preview": "{\n \n}"
},
{
"path": "pages/ucenter/collect/collect.wxml",
"chars": 517,
"preview": "<view class=\"container\">\n <view class=\"collect-list\">\n <view class=\"item\" bindtap=\"openGoods\" bindtouchstart=\"touch"
},
{
"path": "pages/ucenter/collect/collect.wxss",
"chars": 957,
"preview": "page{\n background: #f4f4f4;\n min-height: 100%;\n}\n\n.container{\n background: #f4f4f4;\n min-height: 100%;\n}\n\n.c"
},
{
"path": "pages/ucenter/coupon/coupon.js",
"chars": 321,
"preview": "var util = require('../../../utils/util.js');\nvar api = require('../../../config/api.js');\n\n\n\nvar app = getApp();\n\nPage("
},
{
"path": "pages/ucenter/coupon/coupon.json",
"chars": 6,
"preview": "{\n \n}"
},
{
"path": "pages/ucenter/coupon/coupon.wxml",
"chars": 1681,
"preview": "<view class=\"container\">\n <view class=\"coupon-form\">\n <view class=\"input-box\">\n <input class=\"coupon-sn\" placeh"
},
{
"path": "pages/ucenter/coupon/coupon.wxss",
"chars": 2736,
"preview": "page{\n background: #f4f4f4;\n min-height: 100%;\n}\n\n.container{\n background: #f4f4f4;\n min-height: 100%;\n p"
},
{
"path": "pages/ucenter/express/express.js",
"chars": 822,
"preview": "var util = require('../../../utils/util.js');\nvar api = require('../../../config/api.js');\nvar app = getApp();\n\nPage({\n "
},
{
"path": "pages/ucenter/express/express.json",
"chars": 38,
"preview": "{\n \"navigationBarTitleText\": \"物流详情\"\n}"
},
{
"path": "pages/ucenter/express/express.wxml",
"chars": 808,
"preview": "<view class=\"container\">\n <view class='express-header'>\n <view class=\"left\">\n <view class=\"txt\">物流单号:{{expressI"
},
{
"path": "pages/ucenter/express/express.wxss",
"chars": 1908,
"preview": "page {\n height: 100%;\n width: 100%;\n background: #f4f4f4;\n}\n\n.container {\n height: 100%;\n width: 100%;\n}\n\n.express-"
},
{
"path": "pages/ucenter/feedback/feedback.js",
"chars": 559,
"preview": "var util = require('../../../utils/util.js');\nvar api = require('../../../config/api.js');\n\n\n\nvar app = getApp();\n\nPage("
},
{
"path": "pages/ucenter/feedback/feedback.json",
"chars": 6,
"preview": "{\n \n}"
},
{
"path": "pages/ucenter/feedback/feedback.wxml",
"chars": 937,
"preview": "<view class=\"container\">\n\n <picker bindchange=\"bindPickerChange\" value=\"{{index}}\" range=\"{{array}}\">\n <view class=\""
},
{
"path": "pages/ucenter/feedback/feedback.wxss",
"chars": 1708,
"preview": "page{\n background: #f4f4f4;\n min-height: 100%;\n}\n\n.container{\n background: #f4f4f4;\n min-height: 100%;\n p"
},
{
"path": "pages/ucenter/footprint/footprint.js",
"chars": 1902,
"preview": "var util = require('../../../utils/util.js');\nvar api = require('../../../config/api.js');\n\n\n\nvar app = getApp();\n\nPage("
},
{
"path": "pages/ucenter/footprint/footprint.json",
"chars": 6,
"preview": "{\n \n}"
},
{
"path": "pages/ucenter/footprint/footprint.wxml",
"chars": 754,
"preview": "<view class=\"container\">\n <view class=\"footprint\">\n <view class=\"day-item\" wx:for=\"{{footprintList}}\" wx:key=\"{{inde"
},
{
"path": "pages/ucenter/footprint/footprint.wxss",
"chars": 1286,
"preview": "page{\n background: #f4f4f4;\n min-height: 100%;\n}\n\n.container{\n background: #f4f4f4;\n min-height: 100%;\n}\n\n.f"
},
{
"path": "pages/ucenter/index/index.js",
"chars": 2340,
"preview": "const util = require('../../../utils/util.js');\nconst api = require('../../../config/api.js');\nconst user = require('../"
},
{
"path": "pages/ucenter/index/index.json",
"chars": 147,
"preview": "{\n \"navigationBarBackgroundColor\": \"#333\",\n \"navigationBarTitleText\": \"我的\",\n \"navigationBarTextStyle\": \"white\",\n \"ba"
},
{
"path": "pages/ucenter/index/index.wxml",
"chars": 3092,
"preview": "<view class=\"container\">\n <view class=\"profile-info\">\n <image bindtap=\"onUserInfoClick\" class=\"avatar\" src=\"{{userIn"
},
{
"path": "pages/ucenter/index/index.wxss",
"chars": 4147,
"preview": "page{\n height: 100%;\n width: 100%;\n background: #f4f4f4;\n}\n.container{\n background: #f4f4f4;\n height: aut"
},
{
"path": "pages/ucenter/order/order.js",
"chars": 699,
"preview": "var util = require('../../../utils/util.js');\nvar api = require('../../../config/api.js');\n\nPage({\n data:{\n orderLis"
},
{
"path": "pages/ucenter/order/order.json",
"chars": 2,
"preview": "{}"
},
{
"path": "pages/ucenter/order/order.wxml",
"chars": 1190,
"preview": "<view class=\"container\">\n <view class=\"orders\">\n <navigator url=\"../orderDetail/orderDetail?id={{item.id}}\" cl"
},
{
"path": "pages/ucenter/order/order.wxss",
"chars": 1699,
"preview": "page{\n height: 100%;\n width: 100%;\n background: #f4f4f4;\n}\n\n.orders{\n height: auto;\n width: 100%;\n ove"
},
{
"path": "pages/ucenter/orderDetail/orderDetail.js",
"chars": 1789,
"preview": "var util = require('../../../utils/util.js');\nvar api = require('../../../config/api.js');\n\nPage({\n data: {\n orderId"
},
{
"path": "pages/ucenter/orderDetail/orderDetail.json",
"chars": 8,
"preview": "{\n \n}"
},
{
"path": "pages/ucenter/orderDetail/orderDetail.wxml",
"chars": 2297,
"preview": "<view class=\"container\">\n <view class=\"order-info\">\n <view class=\"item-a\">下单时间:{{orderInfo.add_time}}</view>\n "
},
{
"path": "pages/ucenter/orderDetail/orderDetail.wxss",
"chars": 4139,
"preview": "page{\n height: 100%;\n width: 100%;\n background: #f4f4f4;\n}\n\n.order-info{\n padding-top: 25rpx;\n background"
},
{
"path": "services/pay.js",
"chars": 947,
"preview": "/**\n * 支付相关服务\n */\n\nconst util = require('../utils/util.js');\nconst api = require('../config/api.js');\n\n/**\n * 判断用户是否登录\n "
},
{
"path": "services/user.js",
"chars": 1213,
"preview": "/**\n * 用户相关服务\n */\n\nconst util = require('../utils/util.js');\nconst api = require('../config/api.js');\n\n\n/**\n * 调用微信登录\n *"
},
{
"path": "utils/util.js",
"chars": 3466,
"preview": "var api = require('../config/api.js')\n\nfunction formatTime(date) {\n var year = date.getFullYear()\n var month = date.ge"
}
]
About this extraction
This page contains the full source code of the tumobi/nideshop-mini-program GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 152 files (373.5 KB), approximately 116.3k tokens, and a symbol index with 119 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.