TopShelfCraft / Wordsmith

A plugin for Craft CMS to help you manage and manipulate text.
Other
30 stars 20 forks source link

[FR] `highlight`/`wrap` function #16

Open michaelrog opened 5 years ago

michaelrog commented 5 years ago

Function to parse through some text and replace each occurrence of words/substrings of interest with wrapped/"highlighted" text, e.g. foo to <em>foo</em>.

We'd want options to enable or prevent highlighting/wrapping partial words.

Some examples of how this might work:

"This is example text." | highlight(needle='example', html='<span class="highlight">')"This is <span class="highlight">example</span> text."

"This is example text." | wrapWords(words=['this', 'example'], before='~', after='%', caseSensitive=false )"~This% is ~example% text."

"This is example text; this is nifty." | wrap(needle=['this', 'ex'], before='~', after='%', caseSensitive=true )"This is ~ex%ample text; ~this% is nifty."