Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文章中代码块不能正常显示 #14

Open
my3rs opened this issue Apr 18, 2018 · 3 comments
Open

文章中代码块不能正常显示 #14

my3rs opened this issue Apr 18, 2018 · 3 comments

Comments

@my3rs
Copy link

my3rs commented Apr 18, 2018

<pre><code></pre></code>

之间的代码不能在小程序中正常显示

@sunriseydy
Copy link

我有一个解决办法,就是将<pre>标签去掉,只留下<code>,并且将<code>标签中的\r\n换为<p>\n</p>,这样解决了<code>标签中多行代码显示为一行的问题。具体方法是改写小程序中 detail.js 中获取文章内容并交给 wxParse 处理的函数:

WxParse.wxParse('article', 'html', response.data.content.rendered.replace(/<pre>/g, "").replace(/<\/pre>/g, "").replace(/\r\n(?!<\/code>)/g,"<p>\n<\/p>"), self, 5);

效果预览:
20180519004909

我也是刚刚解决这个问题,随后我会写篇博文来具体说明。

@iamxjb
Copy link
Owner

iamxjb commented May 20, 2018

这个思路不错

@sunriseydy
Copy link

哇,感谢作者的认同,今天把这个问题的解决方法总结成一篇博文,地址:解决 WordPress 微信小程序文章内代码显示、图片非 CDN 地址、图片附带链接的问题
同时还解决了其他一些问题,希望能帮到需要的人。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants