Skip to content

Commit

Permalink
Detect "See also" blocks, also when they're on multiple lines
Browse files Browse the repository at this point in the history
  • Loading branch information
cbonte committed Apr 21, 2012
1 parent cf569dd commit 4764b55
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
2 changes: 2 additions & 0 deletions css/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ h5 {

h5,
.table th, .table td,
.unpre,
.example-desc {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
white-space: normal;
}
7 changes: 7 additions & 0 deletions parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def __init__(self, pctxt):
def parse(self, line):
return line

def get_indent(self, line):
indent = 0
length = len(line)
while indent < length and line[indent] == ' ':
indent += 1
return indent


class PContext:
def __init__(self, templates):
Expand Down
8 changes: 0 additions & 8 deletions parser/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,3 @@ def parse(self, line):
content=content
)
return line

def get_indent(self, line):
indent = 0
length = len(line)
while indent < length and line[indent] == ' ':
indent += 1
return indent

32 changes: 29 additions & 3 deletions parser/seealso.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,34 @@
class Parser(parser.Parser):
def __init__(self, pctxt):
parser.Parser.__init__(self, pctxt)
template = pctxt.templates.get_template("parser/seealso.tpl")
self.replace = template.render().strip()
#template = pctxt.templates.get_template("parser/seealso.tpl")
#self.replace = template.render().strip()

def parse(self, line):
return re.sub(r'(See also *:)', self.replace, line)
#return re.sub(r'(See also *:)', self.replace, line)
pctxt = self.pctxt

result = re.search(r'(See also *:)', line)
if result:
label = result.group(0)

desc = re.sub(r'.*See also *:', '', line).strip()

indent = self.get_indent(line)

# Some descriptions are on multiple lines
while pctxt.has_more_lines(1) and self.get_indent(pctxt.get_line(1)) > indent:
desc += " " + pctxt.get_line(1).strip()
pctxt.next()

pctxt.eat_empty_lines()
pctxt.next()
pctxt.stop = True

template = pctxt.templates.get_template("parser/seealso.tpl")
return template.render(
label=label,
desc=desc,
)

return line
4 changes: 3 additions & 1 deletion templates/parser/seealso.tpl
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<span class="label label-see-also">\1</span>
<div class="page-header unpre">
<b>${label}</b> ${desc}
</div>
4 changes: 2 additions & 2 deletions templates/parser/table/row.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
% for extra in col['extra']:
<span class="pull-right">${extra}</span>\
% endfor
${data}</a>
${data}</a>\
% else:
${data}
${data}\
% endif
</td>\
% endfor
Expand Down

0 comments on commit 4764b55

Please sign in to comment.