Source code for text_data.core
"""Core utilities for text_data.
This is mostly where the Rust backend is stored.
"""
import functools
import html
from typing import Any, Callable
from text_data_rs import PositionalIndex, ngrams_from_documents # noqa: F401
def _escape_html(raw_text: str) -> str:
"""Escapes HTML to get rid of Jupyter rendering problems."""
# the first part of this is built on the idea that if the content
# contains html we shouldn't necessarily see that
# the extra symbols are because of weird pretty printing behavior from
# jupyter (see https://stackoverflow.com/questions/16089089/escaping-dollar-sign-in-ipython-notebook)
return (
html.escape(raw_text)
# https://blogueun.wordpress.com/2014/01/04/escaping-in-mathjax/
.replace("$", "<span class='tex2jax_ignore'>$</span>")
)