2929from textile .utils import (decode_high , encode_high , encode_html , generate_tag ,
3030 has_raw_text , is_rel_url , is_valid_url , list_type , normalize_newlines ,
3131 parse_attributes , pba )
32+ from textile .objects import Block
3233
3334
3435try :
@@ -577,18 +578,19 @@ def block(self, text):
577578 # tag specified on this line.
578579 if match :
579580 tag , atts , ext , cite , content = match .groups ()
580- ( outer_tag , outer_atts , inner_tag , inner_atts ,
581- content ) = self . fBlock ( ** match . groupdict ())
582- inner_block = generate_tag ( inner_tag , content , inner_atts )
581+ block = Block ( self , ** match . groupdict ())
582+ inner_block = generate_tag ( block . inner_tag , block . content ,
583+ block . inner_atts )
583584 # code tags and raw text won't be indented inside outer_tag.
584- if inner_tag != 'code' and not has_raw_text (inner_block ):
585+ if block . inner_tag != 'code' and not has_raw_text (inner_block ):
585586 inner_block = "\n \t \t {0}\n \t " .format (inner_block )
586587 if ext :
587- line = content
588+ line = block . content
588589 else :
589- line = generate_tag (outer_tag , inner_block , outer_atts )
590+ line = generate_tag (block .outer_tag , inner_block ,
591+ block .outer_atts )
590592 # pre tags and raw text won't be indented.
591- if outer_tag != 'pre' and not has_raw_text (line ):
593+ if block . outer_tag != 'pre' and not has_raw_text (line ):
592594 line = "\t {0}" .format (line )
593595 # no tag specified
594596 else :
@@ -598,13 +600,13 @@ def block(self, text):
598600 line = '{0}\n {1}' .format (out .pop (), line )
599601 whitespace = ' \t \n \r \f \v '
600602 if ext or not line [0 ] in whitespace :
601- (outer_tag , outer_atts , inner_tag , inner_atts ,
602- content ) = self .fBlock (tag , atts , ext , cite , line )
603- if tag == 'p' and not has_raw_text (content ):
604- line = content
603+ block = Block (self , tag , atts , ext , cite , line )
604+ if block .tag == 'p' and not has_raw_text (block .content ):
605+ line = block .content
605606 else :
606- line = generate_tag (outer_tag , content , outer_atts )
607- if outer_tag != 'pre' and not has_raw_text (line ):
607+ line = generate_tag (block .outer_tag , block .content ,
608+ block .outer_atts )
609+ if block .outer_tag != 'pre' and not has_raw_text (line ):
608610 line = "\t {0}" .format (line )
609611 else :
610612 line = self .graf (line )
@@ -622,113 +624,10 @@ def block(self, text):
622624 graf = ''
623625
624626 if ext :
625- out .append (generate_tag (outer_tag , out .pop (), outer_atts ))
627+ out .append (generate_tag (block .outer_tag , out .pop (),
628+ block .outer_atts ))
626629 return '\n \n ' .join (out )
627630
628- def fBlock (self , tag , atts , ext , cite , content ):
629- att = atts
630- attributes = parse_attributes (att )
631- outer_tag = ''
632- inner_tag = ''
633- outer_atts = OrderedDict ()
634- inner_atts = OrderedDict ()
635- eat = False
636-
637- if tag == 'p' :
638- # is this an anonymous block with a note definition?
639- notedef_re = re .compile (r"""
640- ^note\# # start of note def marker
641- (?P<label>[^%<*!@\#^([{{ {space}.]+) # label
642- (?P<link>[*!^]?) # link
643- (?P<att>{cls}) # att
644- \.? # optional period.
645- [{space}]+ # whitespace ends def marker
646- (?P<content>.*)$ # content""" .format (
647- space = regex_snippets ['space' ], cls = cls_re_s ),
648- flags = re .X | re .U )
649- notedef = notedef_re .sub (self .fParseNoteDefs , content )
650-
651- # It will be empty if the regex matched and ate it.
652- if '' == notedef :
653- content = notedef
654- return (outer_tag , outer_atts , inner_tag , inner_atts , content )
655-
656- fns = re .search (r'fn(?P<fnid>{0}+)' .format (regex_snippets ['digit' ]),
657- tag , flags = re .U )
658- if fns :
659- tag = 'p'
660- fnid = self .fn .get (fns .group ('fnid' ), None )
661- if fnid is None :
662- fnid = '{0}{1}' .format (self .linkPrefix ,
663- self ._increment_link_index ())
664-
665- # If there is an author-specified ID goes on the wrapper & the
666- # auto-id gets pushed to the <sup>
667- supp_id = OrderedDict ()
668-
669- # if class has not been previously specified, set it to "footnote"
670- if 'class' not in attributes :
671- attributes .update ({'class' : 'footnote' })
672-
673- # if there's no specified id, use the generated one.
674- if 'id' not in attributes :
675- attributes .update ({'id' : 'fn{0}' .format (fnid )})
676- else :
677- supp_id = parse_attributes ('(#fn{0})' .format (fnid ))
678-
679-
680- if '^' not in att :
681- sup = generate_tag ('sup' , fns .group ('fnid' ), supp_id )
682- else :
683- fnrev = generate_tag ('a' , fns .group ('fnid' ), {'href' :
684- '#fnrev{0}' .format (fnid )})
685- sup = generate_tag ('sup' , fnrev , supp_id )
686-
687- content = '{0} {1}' .format (sup , content )
688-
689- if tag == 'bq' :
690- if cite :
691- cite = self .shelveURL (cite )
692- cite_att = OrderedDict (cite = cite )
693- cite = ' cite="{0}"' .format (cite )
694- else :
695- cite = ''
696- cite_att = OrderedDict ()
697- cite_att .update (attributes )
698- outer_tag = 'blockquote'
699- outer_atts = cite_att
700- inner_tag = 'p'
701- inner_atts = attributes
702- eat = False
703-
704- elif tag == 'bc' or tag == 'pre' :
705- i_tag = ''
706- if tag == 'bc' :
707- i_tag = 'code'
708- content = self .shelve (encode_html ('{0}\n ' .format (
709- content .rstrip ("\n " ))))
710- outer_tag = 'pre'
711- outer_atts = attributes
712- inner_tag = i_tag
713- inner_atts = attributes
714- eat = False
715-
716- elif tag == 'notextile' :
717- content = self .shelve (content )
718-
719- elif tag == '###' :
720- eat = True
721-
722- else :
723- outer_tag = tag
724- outer_atts = attributes
725-
726- if not eat :
727- content = self .graf (content )
728- else :
729- content = ''
730- return (outer_tag , outer_atts , inner_tag , inner_atts , content )
731-
732631 def footnoteRef (self , text ):
733632 # somehow php-textile gets away with not capturing the space.
734633 return re .compile (r'(?<=\S)\[(?P<id>{0}+)(?P<nolink>!?)\]'
0 commit comments