function asTextContent()

in js/src/android-serialize.ts [123:146]


function asTextContent(
  part: Expression,
  entities: Record<string, string>,
  onError: (error: SerializeError) => void
): string {
  if (part.fn === 'entity') {
    if (!part.$) {
      const error = `android: Invalid entity: ${JSON.stringify(part)}`
      onError(new SerializeError(error))
    }
    if (part.opt) {
      const error = `android: Unsupported options on entity &${part.$};`
      onError(new SerializeError(error))
    }
    const key = `_entity_${++xmlEntityKey}_`
    entities[key] = `&${part.$ ?? ''};`
    return key
  }
  if (typeof part.attr?.source === 'string') return part.attr.source
  if (part.fn && part.fn !== 'html') {
    onError(new SerializeError(`android: Unsupported function ${part.fn}`))
  }
  return part.$ ?? escape(part._ ?? '')
}