
    k7i*              	           S r SSKrSSKJrJrJr  \(       a  SSKJr  SS\S\S   S\S	\	4S
 jjr
S\	S-  S	\	4S jrS\	S-  S	\	S-  4S jrS\	S-  S	\	4S jrg)znMarkup and format conversion utilities.

Pure utility layer for text processing across help and docs systems.
    N)TYPE_CHECKINGAnyOptionalConsoleobjconsoler   preserve_markupreturnc           
         U c  g[        U S5      (       aL  [        U SS5      nUb<  U(       a+  [        US5      (       a  UR                  R                  5       $ [	        X1US9$ [        U S5      (       a  U R
                  R                  5       $ U(       a+  [        U S5      (       a  U R                  R                  5       $ [        U S5      (       a  SS	KJn  U" [        R                  " 5       U(       a  UR                  OS
SSSSSS9nUR                  5        nUR                  U SS9  SSS5        WR                  5       R                  5       $ [        U 5      R                  5       $ ! , (       d  f       NE= f)a  Extract text from Rich renderables or any object.

Parameters
----------
obj : Any
    Object to convert to text.
console : Console | None
    Console for rendering Rich objects.
preserve_markup : bool
    If True, preserve original markdown/RST markup when available.
    When False, always render to plain text.

Returns
-------
str
    Text representation (plain or with markup preserved).
N primary_renderablemarkup)r
   plain__rich_console__r   r   x   FT)filewidthforce_terminalno_color	highlightr   emoji)end)hasattrgetattrr   rstripextract_textr   rich.consoler   ioStringIOr   captureprintgetstr)r   r	   r
   primaryr   plain_consoler!   s          J/home/james-whalen/.local/lib/python3.13/site-packages/cyclopts/_markup.pyr   r      s5   $ {s())#3T:77H#=#=~~,,../RRsGyy!!7311zz  ""s&''(#*'-- 
 ""$, %{{}##%%s8??	 %$s   E((
E6textc                 6    U (       d  gU R                  SS5      $ )zEscape special reStructuredText characters in text.

Parameters
----------
text : str | None
    Text to escape. Can be None.

Returns
-------
str
    Escaped text safe for RST.
r   \z\\replacer(   s    r'   
escape_rstr.   B   s     <<f%%    c                 v   ^  T (       d  T $ [        U 4S jS 5       5      (       a  T $ T R                  SS5      m T $ )a  Escape special markdown characters in text.

If the text appears to already contain markdown formatting (bold, italic,
code, links, or headings), it is returned unchanged. Otherwise, pipe
characters are escaped for table compatibility.

Parameters
----------
text : str | None
    Text to escape. Can be None.

Returns
-------
str | None
    Escaped text safe for markdown, or None if input was None.
c              3   ,   >#    U  H	  oT;   v   M     g 7f)N ).0patternr(   s     r'   	<genexpr>"escape_markdown.<locals>.<genexpr>h   s     
G*Fwd?*Fs   )z**z```z](#|z\|)anyr,   r-   s   `r'   escape_markdownr;   T   s9    " 

G*F
GGG<<U#DKr/   c                     U (       d  gU R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  SS	5      n U R                  S
S5      n U $ )zEscape special HTML characters in text.

Parameters
----------
text : str | None
    Text to escape. Can be None.

Returns
-------
str
    Escaped text safe for HTML.
r   &z&amp;<z&lt;>z&gt;"z&quot;'z&#x27;r+   r-   s    r'   escape_htmlrB   o   s_     <<W%D<<V$D<<V$D<<X&D<<X&DKr/   )NF)__doc__r   typingr   r   r   r   r   boolr$   r   r.   r;   rB   r2   r/   r'   <module>rF      s   
 
 / /$2c 2HY$7 2QU 2be 2j&S4Z &C &$#* t 6cDj S r/   