1 from match
import Match
3 def markup_link_syntax(text
):
4 """ markup the link-syntax ` => somewhere ` in the text block """
6 & Match(r
"(?m)(^|\s)\=\>\"([^
\"]*)\"")
7 >> r"\
1<link
>\
2</link
>"
8 & Match(r"(?m
)(^|\s
)\
=\
>\'([^
\']*)\'")
9 >> r"\
1<link
>\
2</link
>"
10 & Match(r"(?m
)(^|\s
)\
=\
>\
s(\w
[\w
.]*\w\
(\d
+\
))")
11 >> r"\
1<link
>\
2</link
>"
12 & Match(r"(?m
)(^|\s
)\
=\
>\
s([^\s\
,\
.\
!\?]+)")
13 >> r"\
1<link
>\
2</link
>")
16 """ using a structure having a '.comment' item - it does pick it up
17 and enhances its text with new markups so that they can be represented
18 in xml. Use self.xml_text() to get markup text (knows 'this function') """
19 def __init__(self, header = None):
21 self.text = None # xml'text
22 def get_filename(self):
23 if self.header is None:
25 return self.header.get_filename()
26 def parse(self, header = None):
27 if header is not None:
29 if self.header is None:
31 comment = self.header.comment
33 comment = self.header.get_otherlines()
38 for line in comment.split("\n"):
40 if line & check(r"^\s?\s?\s?
[*]\s
+[*]\
s(.*)"):
42 if mode: text += "</"+mode+">"
43 mode = "ul
" ; text += "<"+mode+">"
45 text += "<li
><p
> "+self.markup_para_line(line)+" </p
></li
>\n"
46 elif line & check(r"^\s?\s?\s?
[*](.*)"):
48 if mode: text += "</"+mode+">"
49 mode = "para
" ; text += "<"+mode+">"
51 if line.strip() == "":
52 text += "</para
><para
>"+"\n"
54 text += " "+self.markup_para_line(line)+"\n"
57 if mode: text += "</"+mode+">"
58 mode = "screen
" ; text += "<"+mode+">"
59 text += " "+self.markup_screen_line(line)+"\n"
60 if mode: text += "</"+mode+">"+"\n"
62 & Match(r"(<para
>)(\s
*[R
]eturns
)") >>r"\
1This function\
2"
63 & Match(r"(?s
)<para
>\s
*</para
><para
>") >> "<para
>"
64 & Match(r"(?s
)<screen
>\s
*</screen
>") >> "")
66 def markup_screen_line(self, line):
67 return self.markup_line(line.replace("&","&
;")
70 def markup_para_line(self, line):
71 return markup_link_syntax(self.markup_line(line))
72 def markup_line(self, line):
74 .replace("<c
>","<code
>")
75 .replace("</c
>","</code
>"))
76 def xml_text(self, functionname = None):
78 if not self.parse(): return None
80 if functionname is not None:
81 def function(text): return "<function
>"+text+"</function
> function
"
83 .replace("this function
", "the
"+function(functionname))
84 .replace("This function
", "The
"+function(functionname)))