comparison MoinMoin/wikiutil.py @ 2705:4a4d84273ae1

new function RelPageName to calculate a relative pagename from 2 absolute pagenames
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 21 Aug 2007 18:40:59 +0200
parents c6b5c2d813b6
children d2d4e74978bd
comparison
equal deleted inserted replaced
2704:c6b5c2d813b6 2705:4a4d84273ae1
848 if context: 848 if context:
849 pagename = context + '/' + pagename[CHILD_PREFIX_LEN:] 849 pagename = context + '/' + pagename[CHILD_PREFIX_LEN:]
850 else: 850 else:
851 pagename = pagename[CHILD_PREFIX_LEN:] 851 pagename = pagename[CHILD_PREFIX_LEN:]
852 return pagename 852 return pagename
853
854 def RelPageName(request, context, pagename):
855 """
856 Return the relative pagename for some context.
857
858 @param context: name of the page where "pagename" appears on
859 @param pagename: the absolute page name
860 @rtype: string
861 @return: the relative page name
862 """
863 if context == '':
864 # special case, context is some "virtual root" page with name == ''
865 # every page is a subpage of this virtual root
866 return CHILD_PREFIX + pagename
867 elif pagename.startswith(context + CHILD_PREFIX):
868 # simple child
869 return pagename[len(context):]
870 else:
871 # some kind of sister/aunt
872 context_frags = context.split('/') # A, B, C, D, E
873 pagename_frags = pagename.split('/') # A, B, C, F
874 # first throw away common parents:
875 common = 0
876 for cf, pf in zip(context_frags, pagename_frags):
877 if cf == pf:
878 common += 1
879 else:
880 break
881 context_frags = context_frags[common:] # D, E
882 pagename_frags = pagename_frags[common:] # F
883 go_up = len(context_frags)
884 return PARENT_PREFIX * go_up + '/'.join(pagename_frags)
885
853 886
854 def pagelinkmarkup(pagename): 887 def pagelinkmarkup(pagename):
855 """ return markup that can be used as link to page <pagename> """ 888 """ return markup that can be used as link to page <pagename> """
856 from MoinMoin.parser.text_moin_wiki import Parser 889 from MoinMoin.parser.text_moin_wiki import Parser
857 if re.match(Parser.word_rule + "$", pagename): 890 if re.match(Parser.word_rule + "$", pagename):