stripHtmlIfNeeded static method

String stripHtmlIfNeeded(
  1. String text

Returns the input text with spaces instead of HTML tags or HTML escapes, which is helpful for text directionality estimation. Note: This function should not be used in other contexts. It does not deal well with many things: comments, script, elements, style elements, dir attribute,> in quoted attribute values, etc. But it does handle well enough the most common use cases. Since the worst that can happen as a result of these shortcomings is that the wrong directionality will be estimated, we have not invested in improving this.


static String stripHtmlIfNeeded(String text) {
  // The regular expression is simplified for an HTML tag (opening or
  // closing) or an HTML escape. We might want to skip over such expressions
  // when estimating the text directionality.
  return text.replaceAll(RegExp(r'<[^>]*>|&[^;]+;'), ' ');