MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / build_cache

Method build_cache

markdown/inlinepatterns.py:806–835  ·  view source on GitHub ↗

Build the elements for all the regions we found. Elements are built from the data as it is now, so there is nothing to recalculate when Python Markdown asks for them. While pairing, we encounter every token between the regions we found, whether it was useful or not

(self, data: str)

Source from the content-addressed store, hash-verified

804 return cast('etree.Element', el), idx
805
806 def build_cache(self, data: str) -> None:
807 """
808 Build the elements for all the regions we found.
809
810 Elements are built from the data as it is now, so there is nothing to recalculate when Python Markdown
811 asks for them.
812
813 While pairing, we encounter every token between the regions we found, whether it was useful or not.
814 Python Markdown will call us for each of them, so the call after an element is replaced will be for the first
815 token at or after the end of that element. If an element only used part of a delimiter run, the rest
816 of the run is that token.
817 """
818
819 regions = self.regions
820 index = 0
821 position = 0
822 while index < len(regions):
823 el, count = self._build_element(data, index)
824 start, end = regions[index][0], regions[index][3]
825 if data[end:end + 1] in self.delimiters:
826 anchor = end
827 else:
828 position = bisect_left(self.positions, end, position)
829 anchor = self.positions[position] if position < len(self.positions) else end
830 self.cache.append((el, start, end, anchor))
831 index += count
832
833 regions.clear()
834 self.positions.clear()
835 self.cache_index = 0
836
837 def get_cached_result(self, pos: int | None = None) -> tuple[etree.Element, int, int]:
838 """Get the next element from the cache."""

Callers 1

_handle_matchMethod · 0.95

Calls 1

_build_elementMethod · 0.95

Tested by

no test coverage detected