Coder Social home page Coder Social logo

Comments (6)

jin-yufeng avatar jin-yufeng commented on May 13, 2024

可以这样,把node包里DomHandler.js里157行这里加上这段应该就可以过滤掉svg了
1
if(/svg+xml/.test(attrs.src)) {
this._tagStack.push(element);
return;
}
如果要对所有图片设置padding的话可以在options中的tagStyle中设置
{
img:"padding:5px"
}

from mp-html.

solarhell avatar solarhell commented on May 13, 2024

感谢回复 我先试试。
希望以后自定义过滤标签这块也可以开放出来作为选项。
再次感谢!

from mp-html.

solarhell avatar solarhell commented on May 13, 2024

不好意思,需要reopen这个issue。

      // const options = {
      //   tagStyle: {
      //     img: 'padding:5px',
      //   },
      // };
      const parsed = await parser(res.content);

不带option可以得到这样的节点信息:
image
如果带上option解析的话,会报错:

 ERROR 79572 nodejs.TypeError: Cannot read property 'replace' of undefined
    at /xxx/parse-service/node_modules/parser-wxapp/lib/Parser.js:199:17

image

from mp-html.

solarhell avatar solarhell commented on May 13, 2024

这里提供一下我的原文

const htmlStr = '<p>上海要垃圾分类了</p><p>全国都未知沸腾,大家都觉的是个好措施,可以保护环境,造福子孙</p><p>这几天我就感受到了上海朋友的热情,原来都是咨询我分类答主</p><p>不过大多数的问题基本上都集中在以下几个方面:</p><ol><li>隐形眼镜是干垃圾还是湿垃圾?</li><li>隐形眼镜护理盒属于什么垃圾?</li><li>隐形眼镜家是否能给我打折?</li></ol><figure data-size="normal"><noscript><img src="https://pic4.zhimg.com/v2-9e6bd5440738e226c223785ab00e2c4b_b.jpg" data-captio-size="normal" data-rawwidth="700" data-rawheight="424" class="origin_image zh-lightbox-thumb" width="700" data-original="https://pic4.zhimg.com/v2-9e6bd5440738e226c223785ab00e2c4b_r.jpg"/></noscript><img src="data:image/svg+xml;utf8,&lt;svg xmlns=&#39;http://www.w3.org/2000/svg&#39; width=&#39;700&#39; height=&#39;424&#39;&gt;&lt;/svg&gt;" data-caption="" data-size="normal" data-rawwidth="700" data-rawheight="424" class="origin_image zh-lightbox-thumb lazy" width="700" data-original="https://pic4.zhimg.com/v2-9e6bd5440738e226c223785ab00e2c4b_r.jpg" data-actualsrc="https://pic4.zhimg.com/v2-9e6bd5440738e226c223785ab00e2c4b_b.jpg"/></figure><p>其他几个还可以理解,最后一个是什么鬼???</p><p>不管第四个,我们今天来说一下隐形眼镜相关的垃圾分类问题。</p>tps://pic1.zhimg.com/v2-d6be8b81731516447c118d44049f02e8_b.jpg" data-caption="" data-size="normal" data-rawwidth="640" data-rawheight="427" class="origin_image zh-lightbox-thumb" width="640" data-original="https://pic1.zhimg.com/v2-d6be8b81731516447c118d44049f02e8_r.jpg"/></noscript><img src="data:image/svg+xml;utf8,&lt;svg xmlns=&#39;http://www.w3.org/2000/svg&#39; width=&#39;640&#39; height=&#39;427&#39;&gt;&lt;/svg&gt;" data-caption="" data-size="normal" data-rawwidth="640" data-rawheight="427" class="origin_image zh-lightbox-thumb lazy" width="640" data-original="https://pic1.zhimg.com/v2-d6be8b81731516447c118d44049f02e8_r.jpg" data-actualsrc="https://pic1.zhimg.com/v2-d6be8b81731516447c118d44049f02e8_b.jpg"/></figure><p>隐形眼镜大家使用的时候,觉水的原因,如果大家有接触过脱水后的隐形眼镜的话,就知道,隐形眼镜跟小塑料片似得,一捏就破损了,为什么很多长周期的,比如年抛半年抛产品佩戴到后期就非常容易题,有的时候甚至不是因为佩带者使用,而是在镜盒里自己就碎了。</p><figure data-size="normal"><noscript><img src="https://pic3.zhimg.com/v2-743333a770214e1caption="" data-size="normal" data-rawwidth="800" data-rawheight="344" class="origin_image zh-lightbox-thumb" width="800" data-original="https://pic3.zhimg.com/v2-743333a770214e13b2f471ef55135f86_r.jpg"/></noscript><img src="data:image/svg+xml;utf8,&lt;svg xmlns=&#39;http://www.w3.org/2000/svg&#39; width=&#39;800&#39; height=&#39;344&#39;&gt;&lt;/svg&gt;" data-caption="" data-size="normal" data-rawwidth="800" data-rawheight="344" class="origin_image zh-lightbox-thumb lazy" width="800" data-original="https://pic3.zhimg.com/v2-743333a770214e13b2f471ef55135f86_r.jpg" data-actualsrc="https://pic3.zhimg.com/v2-743333a770214e13b2f471ef55135f86_b.jpg"/></figure><p>按照垃圾分类的标准来看,我们大致可以隐形眼镜规划到,可回收物或者是干垃圾这个范围。</p><p>但是从rmal"><noscript><img src="https://pic1.zhimg.com/v2-163714e70eeedb5c583613076d0164e4_b.jpg" data-caption="" data-size="normal" data-rawwidth="870" data-rawheight="970" class="origin_image zh-lightbox-thumb" width="870" data-original="https://pic1.zhimg.com/v2-163714e70eeedb5c583613076d0164e4_r.jpg"/></noscript><img src="data:image/svg+xml;utf8,&lt;svg xmlns=&#39;http://www.w3.org/2000/svg&#39; width=&#39;870&#39; height=&#39;970&#39;&gt;&lt;/svg&gt;" data-caption="" data-size="normal" data-rawwidth="870" data-rawheight="970" class="origin_image zh-lightbox-thumb lazy" width="870" data-original="https://pic1.zhimg.com/v2-163714e70eeedb5c583613076d0164e4_r.jpg" data-actualsrc="https://pic1.zhimg.com/v2-163714e70eeedb5c583613076d0164e4_b.jpg"/></figure><p>为了防止我分错,于是我又到上海发布的微信里去查询了一下</p><p>果然</p><figure data-size="normal"><noscript><img src="https://pic2.zhimg.com/v2-f7ebd94pg" data-caption="" data-size="normal" data-rawwidth="1125" data-rawheight="2436" class="origin_image zh-lightbox-thumb" width="1125" data-original="https://pic2.zhimg.com/v2-f7ebd9467049db051e3021381983df19_r.jpg"/></noscript><img src="data:image/svg+xml;utf8,&lt;svg xmlns=&#39;http://www.w3.org/2000/svg&#39; width=&#39;1125&#39; height=&#39;2436&#39;&gt;&lt;/svg&gt;" data-caption="" data-size="normal" data-rawwidth="1125" data-rawheight="2436" class="origin_image zh-lightbox-thumb lazy" width="1125" data-original="https://pic2.zhimg.com/v2-f7ebd9467049db051e3021381983df19_r.jpg" data-actualsrc="https://pic2.zhimg.com/v2-f7ebd9467049db051e3021381983df19_b.jpg"/></figure><p>官方定义,隐形眼镜虽然是湿的,但是<b>它是干垃圾。</b></p><figure data-size="nrc="https://pic2.zhimg.com/v2-4bc018c4e1e2f4d29898aaad4b9415a5_b.jpg" data-caption="" data-size="normal" data-rawwidth="975" data-rawheight="664" class="origin_image zh-lightbox-thumb" width="975" data-original="https://pic2.zhimg.com/v2-4bc018c4e1e2f4d29898aaad4b9415a5_r.jpg"/></noscript><img src="data:image/svg+xml;utf8,&lt;svg xmlns=&#39;http://www.w3.org/2000/svg&#39; width=&#39;975&#39; height=&#39;664&#39;&gt;&lt;/svg&gt;" data-caption="" data-size="normal" data-rawwidth="975" data-rawheight="664" class="origin_image zh-lightbox-thumb lazy" width="975" data-original="https://pic2.zhimg.com/v2-4bc018c4e1e2f4d29898aaad4b9415a5_r.jpg" data-actualsrc="https://pic2.zhimg.com/v2-4bc018c4e1e2f4d29898aaad4b9415a5_b.jpg"/></figure><p>像这种隐形眼镜的一次盒,就属于<b>可回收物了</b></p><p>包括年抛和半年抛的那种瓶子,以及护理液盒子,都属于<b>可回收物或者有害垃圾的范畴。</b></p><p>虽然我们日常使用没有问题,当然,最好的方式就是戴眼镜,不用扔这些东西了~</p><p></p>';

from mp-html.

jin-yufeng avatar jin-yufeng commented on May 13, 2024

1
咦?

from mp-html.

solarhell avatar solarhell commented on May 13, 2024

是我调用出错了,少传了'html'参数,我再试一下,不好意思,麻烦您了!

from mp-html.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.