bunkat/pseudoloc

Multiple delimeters

Opened this issue · 2 comments

Would love to see support for multiple delimiters. Something like:

options.delimiters = [
  '__', 
  {start: '<', end: '>'}, 
  {start: '{{', end: '}}'} 
]

Bonus points for handling nested delimiters (the ones that use start/end atleast)

I don't have any need for this so probably won't be adding it myself. If you decide to add support, I'd be happy to take a pull request.

burin commented

@robertlevy I needed something like this as well, but the way that I am getting away with having multiple delimiters is passing in RegEx that will match multiple things. It doesn't work perfectly, but it may work for you.

Example:

pseudoloc.option.startDelimiter = '(%{|<|</)'; // %{ or < or </
pseudoloc.option.endDelimiter = '(}|>|/>)'; // } or > or />

The reason this works is because the delimiters are prepended/appended to a RegEx.

For me, it doesn't work perfectly, because I have html strings with attributes (<a href="">) that don't get excluded properly. However, strings like <strong> and </strong> get excluded OK.

Hope this helps!