Ad

TYPOSCRIPT: StdWrap.replacement In Text Fields Only

- 1 answer

I usually search and replace to german quotation marks via stdWrap.

lib content {
    20 < styles.content.get
    20.select.where = colPos = 0
    stdWrap.replacement{
         20 {
            search = #(&quot;)#
            replace = |*| &bdquo;||&ldquo; |*|
            useRegExp = 1
            useOptionSplitReplace = 1
        }
    }
}

Never had problems, but now I want to replace CO2 into CO2. But: Also files and images has CO2 in their names. And this search and replace also replaces strings in path- and filenames.

Does anyone knows, how to limit the stdWrap-function to text fields only (text, header, caption) or exclude specific fields (image, files)?

Thanks for help :)

Martin

Ad

Answer

You can use a regular expression with a lookahead for that:

lib.content {
  20 < styles.content.get
  20.select.where = colPos = 0
  stdWrap.replacement{
    20 {
      search = #(?![^<>]*>)(co2)#i
      replace = CO<sub>2</sub>
      useRegExp = 1
    }
  }
}

The (?![^<>]*>) will make sure any text between < and > will not be replaced.

Ad
source: stackoverflow.com
Ad