I want to do a secondary filtering when the template is rendered as a static HTML file.
How to match whether the textNode
in the a
label is equal to the variable. If it is equal, the entire a label will be removed.
<a class="tags-cloud-link" href="/tags/common/" rel="tag">mathjax test<span class="tags-cloud-count">1</span></a>
<a class="tags-cloud-link" href="/tags/markdown/" rel="tag">markdown<span class="tags-cloud-count">1</span></a>
<a class="tags-cloud-link" href="/tags/mathjax-test/" rel="tag">common<span class="tags-cloud-count">1</span></a>
If my variable is mathjax test
, the result of match replacement should be
<a class="tags-cloud-link" href="/tags/markdown/" rel="tag">markdown<span class="tags-cloud-count">1</span></a>
<a class="tags-cloud-link" href="/tags/mathjax-test/" rel="tag">common<span class="tags-cloud-count">1</span></a>
let htmlText = `<a class="tags-cloud-link" href="/tags/common/" rel="tag">mathjax test<span class="tags-cloud-count">1</span></a><a class="tags-cloud-link" href="/tags/markdown/" rel="tag">markdown<span class="tags-cloud-count">1</span></a><a class="tags-cloud-link" href="/tags/mathjax-test/" rel="tag">common<span class="tags-cloud-count">1</span></a>`;
let $2 = 'mathjax test';
//let $2 = 'markdown';
//let $2 = 'common'
if (/<a class="tags-cloud-link"(.*?)> {How to use variables $2 = mathjax test} <span(.*?)>(.*?)<\/span><\/a>/gi.test(htmlText)) {
console.log('new htmlText');
//`<a class="tags-cloud-link" href="/tags/markdown/" rel="tag">markdown<span class="tags-cloud-count">1</span></a><a class="tags-cloud-link" href="/tags/mathjax-test/" rel="tag">common<span class="tags-cloud-count">1</span></a>`
}