o k`@sddlZddlZddlTddlTddlmZmZddlmZm Z ddl m Z m Z m Z mZmZddlmZmZmZmZmZmZmZmZddlmZmZddlmZmZdd lm Z m!Z!gd Z"d d Z#d0d dZ$ddZ%d0ddZ&Gddde'Z(Gddde'Z)Gddde*Z+Gddde*Z,Gddde,Z-Gddde,Z.Gdd d e.Z/Gd!d"d"e*Z0Gd#d$d$e*Z1d%d&Z2d0d'd(Z3d0d)d*Z4d+d,Z5  d1d.d/Z6dS)2N)*)get_relative_resourceget_resource_url)arityas_int)exception_to_unicode shorten_line to_unicode unicode_quote unquote_label)ElementFragmentMarkupTracHTMLSanitizerescape plaintexttag to_fragment)_tag_) WikiSystem parse_args) WikiParserparse_processor_args) Formatter MacroErrorProcessorErrorconcat_path_query_fragment extract_link format_toformat_to_htmlformat_to_oneliner"split_url_into_path_query_fragmentwiki_to_outlinecCst|tr t|St|SN) isinstancer rr )markupr'5/usr/lib/python3/dist-packages/trac/wiki/formatter.py_markup_to_unicode.s r)cCs tjt||o t|ddS)Nzsystem-messageclass_)rdivstrongpre)msgtextr'r'r(system_message5sr1cCsjd}}|d}|dkr|d|||d}}|d}|dkr0|d|||d}}|||fS)aSplit a target along `?` and `#` in `(path, query, fragment)`. >>> split_url_into_path_query_fragment('http://path?a=1&b=2#frag?ment') ('http://path', '?a=1&b=2', '#frag?ment') >>> split_url_into_path_query_fragment('http://path#frag?ment') ('http://path', '', '#frag?ment') >>> split_url_into_path_query_fragment('http://path?a=1&b=2') ('http://path', '?a=1&b=2', '') >>> split_url_into_path_query_fragment('http://path') ('http://path', '', '') #rN?)find)targetqueryfragmentidxr'r'r(r":s   r"cCsNt|\}}}|r||rdnd|d7}|r|}|||dkr$dS|S)a=Assemble `path`, `query` and `fragment` into a proper URL. Can be used to re-assemble an URL decomposed using `split_url_into_path_query_fragment` after modification. >>> concat_path_query_fragment('/wiki/page', '?version=1') '/wiki/page?version=1' >>> concat_path_query_fragment('/wiki/page#a', '?version=1', '#b') '/wiki/page?version=1#b' >>> concat_path_query_fragment('/wiki/page?version=1#a', '?format=txt') '/wiki/page?version=1&format=txt#a' >>> concat_path_query_fragment('/wiki/page?version=1', '&format=txt') '/wiki/page?version=1&format=txt' >>> concat_path_query_fragment('/wiki/page?version=1', 'format=txt') '/wiki/page?version=1&format=txt' >>> concat_path_query_fragment('/wiki/page?version=1#a', '?format=txt', '#') '/wiki/page?version=1&format=txt' &r4z?&r3r2)r"lstrip)pathr7r8pqfr'r'r(rPs rc@eZdZdZdS)rzException raised on incorrect macro usage. The exception is trapped by the wiki formatter and the message is rendered in a `pre` tag, wrapped in a div with class `system-message`. :since: 1.0.11 N__name__ __module__ __qualname____doc__r'r'r'r(rkrc@r@)rzException raised on incorrect processor usage. The exception is trapped by the wiki formatter and the message is rendered in a `pre` tag, wrapped in a div with class `system-message`. :since: 0.12 NrAr'r'r'r(rurFrc@seZdZedZedejejBZd6ddZ ddZ dd Z d d Z d d Z ddZddZddZddZddZddZddZddZddZd d!Zed"ejejBZed#ejejBejBZd$d%Zd&d'Zd(d)Zd*d+Z d,d-Z!d7d/d0Z"d1d2Z#d8d4d5Z$dS)9 WikiProcessorz(^(.*)$z ^\s*<(?:div|table)(?:\s+[^>]+)?>Nc Cs||_|j|_||_||_d|_d|_|j|j|j|j |j |j |j |j |j |j|j|jd }|jddddd||_t|jj|jjd|_|||_|jst|jjD]1}|p\gD](}|j|krt|drn|j|_n tt dt!"dd ||_t#|d d |_nq]qU|jst$|j}|j%D]}|&|jd kr|j'|_nq|js|(|j} | r| |_|j'|_|js|j|_t)d |d|_dSdS)zFind the processor by name :param formatter: the formatter embedding a call for this processor :param name: the name of the processor :param args: extra parameters for the processor (''since 0.11'') N) html htmlcommentdefaultcommentr,rtlspanSpantdthtrtableT)rHrIrKrMrN) safe_schemes safe_origins expand_macrozCPre-0.11 macros with the %(method)s method are no longer supported. render_macro)method is_inlineFz,No macro or processor named '%(name)s' foundname)* formatterenvr[argserrormacro_provider_html_processor_htmlcomment_processor_default_processor_comment_processor_div_processor_rtl_processor_span_processor _td_processor _th_processor _tr_processor_table_processor_html_is_inlineget inline_checkrwikirSrT _sanitizer processorrmacro_providers get_macroshasattr_macro_processor TracErrorrrcodegetattrMimeview renderersget_quality_ratio_mimeview_processor get_mimetyper) selfr\r[r^builtin_processorsr` macro_namemimeviewrenderermimetyper'r'r(__init__s         zWikiProcessor.__init__cCsB|r|dd}|d}|dkr|d|}|dvSdS)NrY )arMbdoimgbigsmallfontttibusstrikeemr-dfnrwr>sampkbdvarciteabbracronymsubsup)r;r5lower)r~r0rr9r'r'r(rls   zWikiProcessor._html_is_inlinecCdSNr2r'r~r0r'r'r(rdz WikiProcessor._comment_processorcCs<|jrd|jvrt|jjd|_||Stj|ddS)Nlinenoz text/plainror*) r^ryr\r]r}r[r|rr.rr'r'r(rcs  z WikiProcessor._default_processorcCs t|jjr t|S|j|Sr$)rr]render_unsafe_contentrrpsanitizerr'r'r(ras  zWikiProcessor._html_processorcCs d|vr ttdStd|S)Nz--zGError: Forbidden character sequence "--" in htmlcomment wiki code blockz )r1rrrr'r'r(rbs  z$WikiProcessor._htmlcomment_processorcCsbtt|di|jp i}t|jjs#tt|}|j||j|_|}| ||j|j j ||S)Nr') rxrr^rr]rrpsanitize_attrsattribappendr\context)r~eltnamerr0elt sanitized_eltr'r'r(_elt_processors  zWikiProcessor._elt_processorcCs(|jsi|_|jdd|dt|S)Nclasswikipager,)r^ setdefaultrr rr'r'r(reszWikiProcessor._div_processorcCs6|jsi|_d|jdd|jd<|dt|S)Nzrtl rr2r,)r^rmrstriprr rr'r'r(rfszWikiProcessor._rtl_processorcCs4|jdurt|dd\}|_d|}|dt|S)NT)strictz, rM)r^rjoinrr!)r~r0r^r'r'r(rgs  zWikiProcessor._span_processorcC |d|S)NrO_tablecell_processorrr'r'r(rh zWikiProcessor._td_processorcCr)NrPrrr'r'r(rirzWikiProcessor._th_processorc CsNz|d|j|}|j|WSty&}z t|WYd}~Sd}~ww)NrQ)r _format_rowr\ open_tablerr1)r~r0rer'r'r(rjs zWikiProcessor._tr_processorc CsZ|jsi|_|jddz |d|j|WSty,}z t|WYd}~Sd}~ww)NrrorR)r^rr _format_tablerr1)r~r0rr'r'r(rk"szWikiProcessor._table_processorcCs|j||t|Sr$)r\open_table_rowrr )r~rr0r'r'r(r+s z"WikiProcessor._tablecell_processorz.*?]*>\s* ((?:]*>)? (.*?) (?:)?)\s* \s*$ cCs`|j|rttd|jd|j|}|s ttd|jdt||jdkr,dSdS)Nz)!#%(name)s must contain at most one tablerZzF!#%(name)s must contain at least one table cell (and table cells only)rRrY) _has_multiple_tables_researchrrr[_inner_table_rematchrgroup)r~r0rr'r'r(_parse_inner_table=s   z WikiProcessor._parse_inner_tablecC0|rt}t||||||}|Sr$ioStringIOrformatrgetvaluer~r]rr0outr'r'r(rH zWikiProcessor._format_rowcCrr$rrr'r'r(rOrzWikiProcessor._format_tablecCsR|jjd|j|jt|jjdkr|j|j|j||jS|j|j|j|S)Nz&Executing Wiki macro %s by provider %s) r]logdebugr[r`rrUr\r^rr'r'r(ruXs zWikiProcessor._macro_processorcCsg}|jj}|jr|jn|j}|rQd|vrQt|dddd}|j|dt|ddp6|j d}|j|dd d |vrL|j|d d | d|rY|j|d t j d dt |jj||j||dS)NrrY)min)ridr2r-)rmarks)r) lexer_optionsz wiki-coder*) annotations)r\rchildr^copyrpop set_hintsstr_unique_anchorrrr,ryr]renderr[)r~r0rrr^rrr'r'r(r|bs(       z!WikiProcessor._mimeview_processorFcCs6|jrttdt|jd|j}n||}|pdS)Nz(Error: Failed to load processor %(name)srZr2)r_r1rrrwr[rq)r~r0 in_paragraphr'r'r(processvs  zWikiProcessor.processcCst|jr ||S|jSr$)callablernrr'r'r(rXs  zWikiProcessor.is_inlineTcCsd}d}t|tr-|j}|dkr&|jdd}|r#d|vr#|j}n5d}n2|dkr,d}n+t|}t |j |}|rO| drLd| dvrL| d }n d}n t |j |rXd}|rdtj d d |}|S|rn|rnd t|}|S) NFr,rr2rwTrRrYrz code-blockr*z

%s

)r%r rrrrmchildrenr)rer_code_block_rer_block_elem_rerM)r~r0rcontent_for_spaninterrupt_paragraphtagnamer+rr'r'r( ensure_inlines4     zWikiProcessor.ensure_inliner$F)T)%rBrCrDrcompilerIMrrrlrdrcrarbrrerfrgrhrirjrkr MULTILINEDOTALLrVERBOSErrrrrur|rrXrr'r'r'r(rGsD   L        rGc @seZdZdZdZddZddZddddd d d d d ZddZddZ ddZ ddZ ddZ dddZ dddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Zd=d>Zd?d@Z dAdBZ!dCdDZ"dEdFZ#dGdHZ$dIdJZ%dKdLZ&dMdNZ'ddPdQZ(ddRdSZ)dTdUZ*dVdWZ+dXdYZ,dd[d\Z-d]d^Z.d_d`Z/dadbZ0dcddZ1dedfZ2dgdhZ3ddidjZ4ddldmZ5dndoZ6dpdqZ7drdsZ8dtduZ9dvdwZ:ddxdyZ;dzd{ZdddZ?dddZ@ddZAddZBddZCddZDdddZEddZFddZGddZHddZIddZJddZKeLMdeLjNZOdddZPdddZQdS)rz[Base Wiki formatter. Parses and formats wiki text, in a given `RenderingContext`. rJcCs||_||_|jjdd|j|_|j|_|j|_|j|_t|j|_ t |j|_ i|_ g|_ d|_|j jsAt|j j|_dSdS)NT)disable_warnings)r]rrrreqhrefresourcepermrror wikiparser_anchors _open_tags _safe_schemesrsetrS)r~r]rr'r'r(rs   zFormatter.__init__cCt|Sr$)r")r~r6r'r'r( split_linkzFormatter.split_link)zz )zz)zz)zz)zz)zz)MM_BOLDWC_BOLD MM_ITALIC WC_ITALIC MM_UNDERLINE MM_STRIKE MM_SUBSCRIPTMM_SUPERSCRIPTcCt|ts |j|}|dS)z2Retrieve opening tag for direct or indirect `tag`.rr%tuple_indirect_tagsr~rr'r'r( _get_open_tag  zFormatter._get_open_tagcCr)z2Retrieve closing tag for direct or indirect `tag`.rYrrr'r'r(_get_close_tagr zFormatter._get_close_tagcCs ||jvS)z8Do we currently have any open tag with `tag` as end-tag?)rrr'r'r( tag_open_ps zFormatter.tag_open_pccs"|jr|jV|jsdSdSr$)rrr~r'r'r(pop_tagss zFormatter.pop_tagscCs$|D] }|j||qdSr$)r rwriter rr'r'r( flush_tagss zFormatter.flush_tagsNcCs2|r |j||f|S|j|||}|S)zqOpen an inline style tag. If `tag_close` is not specified, `tag_open` is an indirect tag (0.12) )rrr)r~tag_open tag_closer'r'r(open_tags  zFormatter.open_tagcCsd}tt|jdddD]8}|j|}|||7}||k||f|kft|rE|j|=t|t|jD] }|||j|7}q5|Sq |S)zgOpen a inline style tag. If `close_tag` is not specified, it's an indirect tag (0.12) r2rYr)rangelenrr boolr)r~r close_tagtmprrjr'r'r(rs   zFormatter.close_tagcCs2|jr |js |||r||S||S)z4Handle binary inline style tags (indirect way, 0.12)) _list_stack in_list_item close_listr rr)r~rrr'r'r(_indirect_tag_handlers    zFormatter._indirect_tag_handlerc sjr js d}d}|r0|r0jd}jd}||kr+d}nd}d}n|r7d}d}n |r>d}d}nd}d}g} | fdd |D| fd d |Dd | S) Nrr)rr)rrr')r)rc3|]}|VqdSr$)r.0rr r'r( %z2Formatter._bolditalic_formatter..c3rr$)rrr r'r(r &r!r2)rrrr rindexextendr) r~r fullmatch bold_open italic_openbold_idx italic_idx close_tags open_tagsrr'r r(_bolditalic_formatter s.      zFormatter._bolditalic_formattercC ||dS)Nrrr~rr$r'r'r(_bold_formatter)rzFormatter._bold_formattercCr,)Nrr-r.r'r'r(_bold_wc_formatter,rzFormatter._bold_wc_formattercCr,)Nrr-r.r'r'r(_italic_formatter/rzFormatter._italic_formattercCr,)Nrr-r.r'r'r(_italic_wc_formatter2rzFormatter._italic_wc_formattercCr,)Nrr-r.r'r'r(_underline_formatter5rzFormatter._underline_formattercCr,)Nrr-r.r'r'r(_strike_formatter8rzFormatter._strike_formattercCr,)Nrr-r.r'r'r(_subscript_formatter;rzFormatter._subscript_formattercCr,)Nrr-r.r'r'r(_superscript_formatter>rz Formatter._superscript_formattercCt|dS)Ninlinerrwrr.r'r'r(_inlinecode_formatterAzFormatter._inlinecode_formattercCr7)Ninline2r9r.r'r'r(_inlinecode2_formatterDr;z Formatter._inlinecode2_formattercCs*|||fr |||S||||S)z,Generic handler for simple binary style tags)r rr)r~rrrr'r'r(simple_tag_handlerIs  zFormatter.simple_tag_handlercCr)N
r'r.r'r'r(_linebreak_wc_formatterUrz!Formatter._linebreak_wc_formattercCs<ddlm}||j|j|}||kr|d||S|S)NrChromemailto:)trac.web.chromerBr] format_emailsr_make_mail_link)r~rr$rBomatchr'r'r(_email_formatterZs zFormatter._email_formattercCs|dkrdS|dkr dSdS)Nr:z&d|d}n8|drI|j|}n-t|j|} t |j | |j}| j rvt t | j || }| jdkrld|}|| j||||Stj|t ||| dS||pd|pd|||S)N//:/ro)rr2) startswithr;r romake_label_from_targetrrrrrr]rrrrealmrNrr) r~rr$rUrPr6rXr<r7r8rr'r'r(rY}s@          zFormatter._make_lhref_linkc Cs4|jjd||}||jjvr1|jj|}t|dkr'||||t|d|S||||t|dS|dkrkddlm}||j}|j rI||} } n| |j |} | |j |} | | f||fkrg| d||S| pj| S| dr|jdusz||jvr||d ||St|S||||p||||pt|S) N intertracFmailtorrArCr[r\)r]configrmrlink_resolversrrrDrBnever_obfuscate_mailtorErrFr^r_make_ext_link_make_intertrac_link_make_interwiki_link) r~rPr6rrXr$resolverrBchromeotargetolabelr'r'r(rNs6        zFormatter._make_linkcCs*|||}|r||d||dSdS)NrrY)get_intertrac_urlrg)r~rPr6rXresr'r'r(rhs zFormatter._make_intertrac_linkcCs|jjd}||d}td|d}|s!|dkr!d}td}|rF||d|}d |t|f}|r@td ||d }||fS|}||fSdS) Nraz.urlzTrac project %(name)srZtraczhttps://trac.edgewall.orgzThe Trac Projectz.titlez%s/intertrac/%sz%(target)s in %(name)s)r6r[)r]rdrmrrr )r~rPr6raurlr[titler'r'r(rns  zFormatter.get_intertrac_urlcCsh|r0|d|}|r2|}|jjd}d||t|df}||||||p/|SdSdS)Nit_raz%s:%s) groupdictrmstripr]rdrrh)r~rPr6rXr$it_groupaliasrar'r'r(shorthand_intertrac_helpers z$Formatter.shorthand_intertrac_helpercCsHddlm}||j}||vr |||\}}|r"||||SdSdS)Nr) InterWikiMap)trac.wiki.interwikiryr]rqrg)r~rPr6rXry interwikirqrrr'r'r(ris  zFormatter._make_interwiki_linkr2cCsR|jjp|jjj}||stjtjddd|d||pddStj|||p&ddS)N​iconr*zext-linkr+rrr)rrr)r] project_urlabs_hrefbaser^rrrM)r~rqr0rr local_urlr'r'r(rgs   zFormatter._make_ext_linkcCs"tjtjddd|d||pddS)Nr|r}r*z mail-linkr~)rrrM)r~rqr0rrr'r'r(rFs zFormatter._make_mail_linkcCs8|d}|dp d}|rt|j|j|}d||fS)N anchorname anchorlabelr2z*%s)rr!r]r)r~rr$anchorrXr'r'r(_anchor_formatters  zFormatter._anchor_formattercCs>d}|}||jvr|t|}|d7}||jvs d|j|<|S)NrYT)rr)r~rr anchor_baser'r'r(rs   zFormatter._unique_anchorcCs|dd}|drtj|}|r|||Stj|}|rd|d}|d}d}|ddk}|d ks=|dkr@d}nt|||ddf|}|j rRd}|durd|r]t|d }| |||Stj |}| ||S) Nrz=# macroname macroargsFrr4br MacroList) r^r_set_anchor_wc_rerr _macro_rerrrGr__macro_formatter_creolelink_rerZ)r~rr$ macro_or_linkr[r^macro macrolistr'r'r(_macrolink_formatters,           zFormatter._macrolink_formatterFc Cs|d}|r|ddkr|ddpd}n|d}|dkr&||St|ddp7t|d dp7t|d d }z ||||WStya}zttd ||d t |WYd}~Sd}~wt y}z"|j j d |||jt|ddttd||d t |WYd}~Sd}~ww)Nrrr4rrrrTin_table in_def_listzMacro %(name)s(%(args)s) failed)r[r^zMacro %s(%s) failed for %s:%s tracebackz&Error: Macro %(name)s(%(args)s) failed)rremit_linebreakrxrrrr1rr Exceptionr]rr_rr) r~rr$r only_inliner[r^rrr'r'r(r!s@         zFormatter._macro_formattercCsR|r'd|vrdnd}||d}|ddkr'|ddvr |dnd}d |Sd S) Nr\=rYrclearr)leftrightbothz
r?)splitr)r~r^sepkvrr'r'r(r7s   zFormatter.emit_linebreakc Cs|}|d}t|}|dpd}|d}||r'|d| }t|j|j|d}|r9|dd}nt|dd} tj d| }|rT|d sT|dd vrXd |}| |}|rht|j|j|d }|||fS) Nhdepthhanchorr2htextFrY)keeplinebreaksrz.-rT) rurrendswithr!r]rrr _anchor_rerisdigitr) r~rr$shortenrdepthrrheading sans_markupr'r'r(_parse_headingBs$     zFormatter._parse_headingcCsX||||||||d\}}}|jd||||fdS)NFz%%s) close_tableclose_paragraphclose_indentationrclose_def_listrrrr~rr$rrrr'r'r(_heading_formatterYs  zFormatter._heading_formattercCs:g}|jD] }||kr n||q||||_dS)zAppend a new tab if needed and truncate tabs deeper than `depth` given: -*-----*--*---*-- setting: * results in: -*-----*-*------- N) _tabstopsr)r~rtabstopstsr'r'r(_set_tabes    zFormatter._set_tabc Cst|d}||}d|_d}}|tjvrd}nWd}|d}|dkr(d}nI|dkr/d }nB|r<|d krReturn the space offset associated to the deepest opened list.rrY)rr r'r'r(_get_list_depthszFormatter._get_list_depthc sfdd}fddfdd}kr"|dSjr8jd\}}|kr1n||js%rrdkrtjrmjd\} } rW| krW|| |dS| krb| fjd<jd dS|dSdSdS) Ncsvjfrdnd}dur)dnd}jd||ddS)Nz class="%s"r2z start="%s"rIz>

  • )rrrrrrrr) class_attr start_attr)rlclassnew_typer~rr'r( open_lists  z,Formatter._set_list_depth..open_listcsjddS)Nz
  • )rrrr'r r'r( close_itemsz-Formatter._set_list_depth..close_itemcs$jjd|dS)N)rrrr)tp)rr~r'r(rs z-Formatter._set_list_depth..close_listrrz
  • )rrrr) r~rrrrrr deepest_typedeepest_offsetold_type old_offsetr')rrrrr~rr(rs.       zFormatter._set_list_depthrcCs||dSr$)r)r~rr'r'r(rzFormatter.close_listcCsL|jrd}n|d}|d|d}|dt|j|j|7}d|_|S)Nzz
    z::z
    %s
    T)rrr5r!r]r)r~rr$r definitionr'r'r(_definition_formatterszFormatter._definition_formattercCs|jr |jdd|_dS)Nz
    F)rrrr r'r'r(rs  zFormatter.close_def_listcCst|d}|jr>|jd\}}||kr-|jD]\}}||kr+d|_||dSqn|||dkr5dndkr>d|_dS|jsF||dS)NidepthrTr2rr)rrrrrr_set_quote_depth)r~rr$rltyperrr'r'r(_indent_formatters"  zFormatter._indent_formattercCs|ddSNr)rr r'r'r(rrzFormatter.close_indentationcCs|jr|jdSdS)z?Return the space offset associated to the deepest opened quote.rr) _quote_stackr r'r'r(_get_quote_depthszFormatter._get_quote_depthc sfdd}fdd}|kr4|jddd}|r3|}|kr1|||s%n/jrGjd}||krAn|js7sc|dkrcjr_jd}||kr^|jd<n|||dkrld_dSdS)NcsZfdd}r'td|dD]}||qdS||dS)Ncs6j||rdnd}jd|dS)Nz class="citation"r2z )rrrrr)dr)citationr~r'r(open_one_quotes   zFFormatter._set_quote_depth..open_quote..open_one_quoterY)rrrr)rrrr quote_depthr~r'r( open_quotes  z.Formatter._set_quote_depth..open_quotecs*jjddS)N )rrrrrrr'r r'r( close_quotes z/Formatter._set_quote_depth..close_quoterrT)rrrrrin_quote) r~rrrrrtabrrr'rr(rs8       zFormatter._set_quote_depthcsd_|d}|d}t|}d}|ddkr%|d8}|ddkr1|d8}d}|d }|durL|rD|dd krDd_|d8}|sLd Sd }|dkrXd t|}|d} | tjkojj| d k} t dj| d} | o~| dd k} d} | r| sd} n+| rd} n&| r| d}| | d}||krj|j|krd krnnd} | r|d| 7}d||f}j rd fddD}d|j |f}|_ |S)NrYtable_cell_septable_cell_lastrOrrrrPr\r2z colspan="%d"rz ([^!])=?\|\|rrcenterz style="text-align: %s"z<%s%s>c3rr$)r rr r'r(r Ksz2Formatter._table_cell_formatter..z %s%s)rrcontinue_tablerrcontinue_table_rowrendlinerrr in_table_cellrr )r~rr$ separatoris_lastnumpipescellcolspanattrs after_sep alignleftnext_sep alignright textalign first_extra last_extrarOr)r'r r(_table_cell_formattersb      $  zFormatter._table_cell_formattercCsr||jdd|d}|r*t|d||}t|d}|d|d}||p/dd|_ d|_ dS) NTforcetable_row_paramsrQr2r>rY) rclose_table_rowrrGrr)rr5rrr)r~rr$paramsrQ processedr'r'r(_table_row_sep_formatterQs   z"Formatter._table_row_sep_formattercCs8|js|||d|_|jddSdS)NrYz )rrrrrrr r'r'r(r]szFormatter.open_tablecCs,|js|d|_|jd|dSdS)NrYz) in_table_rowrrr)r~r r'r'r(res zFormatter.open_table_rowcCsR|jr$|jr|r$d|_|jr||jd|jd|_|jdd|_dS)Nrrr2z)rrrrrr)r~rr'r'r(r ks  zFormatter.close_table_rowcCs,|jr|jdd|jdd|_dSdS)NTrz
    r)rr rrr r'r'r(rus    zFormatter.close_tablecCs |js|jdd|_dSdS)Nz

    rY)paragraph_openrrr r'r'r(open_paragraph}s  zFormatter.open_paragraphcCs(||jr|jdd|_dSdS)Nz

    r)rrrrr r'r'r(rs   zFormatter.close_paragraphcCrr$)r)r~rr'r'r(rrzFormatter.parse_processor_argscs|rMjd7_jdkr:|d}|r't||d}t||_nd_g_|d|tj _ dSj |jsKtd_dSdS| tj krjd8_jdkrjrjjdvrmjrj rtfddjDrtj fdd jD_j d d j}j|}jt|dSj |dSjstj|}|r|d_ |d}t||d}t||_dSj |td_dSj |dS) NrYrrJr)rPrOrQc3s"|] }| p |jVqdSr$)r^ code_prefixrlr r'r(r s   z.Formatter.handle_code_block..csg|]}|dqSr$r'r) code_indentr'r( sz/Formatter.handle_code_block..r2 ) in_code_blockrrrrGcode_processorcode_bufr5r STARTBLOCKrrruENDBLOCKr[rrallrr_exec_processorrrr) _processor_rer)r~r startmatchr[r^ code_textr rr')rr~r(handle_code_blocksZ            zFormatter.handle_code_blockcCs(|jdkr|tj|jdksdSdSr)rr"rrr r'r'r(close_code_blockss  zFormatter.close_code_blocksc Csz||WSty$}zttd|jdt|WYd}~Sd}~wtyQ}z"|jj d|j|j t |ddttd|jdt|WYd}~Sd}~ww)NzProcessor %(name)s failedrZzProcessor %s failed for %s:%sTrz Error: Processor %(name)s failed) rrr1rr[rrr]rr_rr)r~rqr0rr'r'r(rs*   zFormatter._exec_processorcCsJ||d}|js||kr|||j||dddS)Nr rY)rr5 _quote_bufferrrr)r~rrr'r'r(handle_quote_blocks   zFormatter.handle_quote_blockcCsn|jr5tdd|jDrdd|jD|_|jdt|j|j|j|j||jdg|_dSdS)Ncss"|] }| p |ddvVqdS)rz> Nr'rrr'r'r(r s z.Formatter.close_quote_block..cSs(g|]}|t|o |ddkdqS)rrN)rr&r'r'r(rs z/Formatter.close_quote_block..z
    r)r$rrrrr]rr)r~escape_newlinesr'r'r(close_quote_blocks   zFormatter.close_quote_blockcCs|D]>\}}|rD||jjvrD|ddkr"t|ddS||jjvr6|jj|}||||St|d|}|||SqdS)Nr!rYz _%s_formatter)rtitemsrhelper_patternsrexternal_handlersrx)r~r$ityperexternal_handlerinternal_handlerr'r'r( handle_matchs   zFormatter.handle_matchcCs||}|r t|SdS)z2Replace one match with its corresponding expansionN)r0r))r~r$ replacementr'r'r(replaces zFormatter.replacez[\v\f]cCst|tr t|jd|}||_Gdddt}|p||_g|_g|_ g|_ g|_ g|_ d|_ d|_d|_d|_d|_d|_d|_d|_|S)Nrc@seZdZddZdS)z Formatter.reset..NullOutcSsdSr$r')r~datar'r'r(rrz&Formatter.reset..NullOut.writeN)rBrCrDrr'r'r'r(NullOuts r4rr2)r%rrr _normalize_resourceobjectrrrrrr$rrrrrrrr)r~r6rr4r'r'r(resets&  zFormatter.resetcCsH|||}t|tr|}|D]}d}tj|vr tj|}|jr*| ||q| dr7| |q| ||rE| ||q|dddkrh||||||jdq|dkr|||||q|dd}| d sg|_| d s|jr|d |_d |_||_t|jj|j|}|js||js||jr| d s||j r|j!s|d|_!d }|js|js|j st"|r|#|r|j$r|%&d sd |}|j|||'q|(| ||||||dS) Nr rrz----z
    r2 z rFrr?))r8r%r splitlinesrr_startblock_rerrr"rur^r%r(rrrrrrrr2rrrrrrrrrulesrrrrrrrrr r#)r~r0rr'rblock_start_matchresultrr'r'r(rs                 zFormatter.formatr$)r2r)NNN)rNF)RrBrCrDrEflavorrrrrr r r rrrrr+r/r0r1r2r3r4r5r6r:r=r>r@rHrJrQrTrZrYrNrhrnrxrirgrFrrrrrrrrrrrrrrrrrrrrrrr rrrrr"r#rr%r(r0r2rrUNICODEr5r8rr'r'r'r(rs      #        )  .3    1  rc@sfeZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ dddZdS)OneLinerFormatterz A special version of the wiki formatter that only implement a subset of the wiki formatting functions. This version is useful for rendering short wiki-formatted messages on a single line onelinercC|Sr$r'r.r'r'r(r}rz!OneLinerFormatter._list_formattercCrDr$r'r.r'r'r(rrz#OneLinerFormatter._indent_formattercC t|dSr?rr.r'r'r(_citation_formatter z%OneLinerFormatter._citation_formattercCrEr?rFr.r'r'r(rrHz$OneLinerFormatter._heading_formattercCrEr?rFr.r'r'r(rrHz'OneLinerFormatter._definition_formattercCrDr$r'r.r'r'r(rrz'OneLinerFormatter._table_cell_formattercCrrr'r.r'r'r(rrz*OneLinerFormatter._table_row_sep_formattercCr)Nrr'r.r'r'r(r@rz)OneLinerFormatter._linebreak_wc_formattercCsV|d}|dkr dS|d}||rt||||Sd||r'dfSdfS)Nrrrrz[[%s%s]]z(...)r2rrrXrrr~rr$rr[r^r'r'r(rs    z"OneLinerFormatter._macro_formatterFc CsN|sdS|||}d}d}t}|D]H}tj|vr*tj|r*|d7}q|tjkrG|rF|d8}|dkrF|dkrD| dd}q|rY|sX| drX|dd}q| |dq| dt d }|rrt |}t|jj|j|}|dd }|d r|dd d }|j |||dkr|j d dSdS) NrrYrKz [...] z#!rrz[...]u[…]z...u…)r8rrrur:rrr;rrr^rrrrrrr<r2rrr) r~r0rrrrqbufrr>r'r'r(rsJ         zOneLinerFormatter.formatNr)rBrCrDrEr@rrrGrrrrr@rrr'r'r'r(rBts rBc@s8eZdZdZdZddZdddZdd d Zd dZdS)OutlineFormatterz@Special formatter that generates an outline of all the headings.outlinecCsB|d}|dkr dS|d}||rt||||SdS)Nrrrrr2rIrJr'r'r(rs    z!OutlineFormatter._macro_formatterNcCsLtj|vrtj|r|jd7_dS|tjkr$|jd8_dSdS)NrY)rrr;rrru)r~rr r'r'r(r"s  z"OutlineFormatter.handle_code_blockrYTc Cs||_d}g|_t||||kr||}}td|}td|}|d}|d|jD]\}} }||ks:||kr;q-||kr]t||D]} ||d| d|d| ddqDnU||krt|d|ddD]} ||d| dd |d| d qk||d|dd |d|ddn||d|dd |d|dd|}||d|d | |fq-t|d|ddD]} ||d| dd |d| d qdS) Nz rOrYrrz
      z
    1. rz
    2. z
    z%s )rrNrrrmaxrr) r~r0r max_depth min_depthrwhitespace_indent curr_depthrrrr'r'r(rsb        zOutlineFormatter.formatcCs:||||j\}}}tdd|}|j|||fdS)Nzr2)rrrrrNrrr'r'r(rs  z#OutlineFormatter._heading_formatterr$)rOrYT) rBrCrDrEr@rr"rrr'r'r'r(rMs  %rMc@s$eZdZdZdZddZddZdS) LinkFormatterz,Special formatter that focuses on TracLinks.linkcCrrr'r.r'r'r(r rz LinkFormatter._heading_formattercCs2||}||_t|jj|}|r||SdS)z>Return the Wiki match found at the beginning of the `wikitext`N)r8rrrrr<r0)r~wikitextrr'r'r(r s  zLinkFormatter.matchN)rBrCrDrEr@rrr'r'r'r(rUs  rUc@&eZdZdZdZddZd ddZdS) HtmlFormatterzFormat parsed wiki text to HTMLrJcC.||_||_t|trt||}||_dSr$r]rr%rrparsewikidomr~r]rr]r'r'r(r   zHtmlFormatter.__init__FcC.t}t|j|j|j||t|S)zpGenerate HTML elements. newlines in the wikidom will be preserved if `escape_newlines` is set. ) rrrr]rrr]rr)r~r'rr'r'r(generate$s  zHtmlFormatter.generateNrrBrCrDrEr@rrar'r'r'r(rYs rYc@rX) InlineHtmlFormatterznFormat parsed wiki text to inline elements HTML. Block level content will be discarded or compacted. rCcCrZr$r[r^r'r'r(r8r_zInlineHtmlFormatter.__init__FcCr`)zGenerate HTML inline elements. If `shorten` is set, the generation will stop once enough characters have been emitted. ) rrrBr]rrr]rr)r~rrr'r'r(ra?s  zInlineHtmlFormatter.generateNrrbr'r'r'r(rc0s rccKsD|dur |dd}|dkrt|||fi|St|||fi|S)N wiki_flavorrHrC)get_hintr!r )r]r@rr]optionsr'r'r(rLs  rcC0|stS|dur|dd}t||||S)Npreserve_newlinesF)rrerYra)r]rr]r'r'r'r(r T  r cCrg)N shorten_linesF)rrercra)r]rr]rr'r'r(r![rir!cCs|stSt|||Sr$)rrUr)r]rr]r'r'r(rbsrFc Csb|stS|p|j|p |j}}ddlm} | ||d} t} t|| || ||t| S)zB:deprecated: will be removed in 1.0 and replaced by something elser) web_context)absurls) rrrrDrkrrrMrr) rWr]dbrlrQrRrabs_refrrkrrr'r'r(r#js   r#r$)NFNNN)7rr trac.core trac.mimeview trac.resourcerr trac.utilrrtrac.util.textrrr r r trac.util.htmlr r rrrrrrtrac.util.translationrr trac.wiki.apirrtrac.wiki.parserrr__all__r)r1r"rrvrrr7rGrrBrMrUrYrcrr r!rr#r'r'r'r(sR(    &WQA