Skip to content

Commit

Permalink
Fix issue #2: encode anchor names in links
Browse files Browse the repository at this point in the history
  • Loading branch information
cbonte committed Jan 25, 2013
1 parent 343ecdf commit 580be78
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions haproxy-dconv.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
from parser import remove_indent from parser import remove_indent
from parser import * from parser import *


from urllib import quote

VERSION = "" VERSION = ""
HAPROXY_GIT_VERSION = False HAPROXY_GIT_VERSION = False


Expand Down Expand Up @@ -139,7 +141,7 @@ def createLinks():
if keyword in keyword_conflicts: if keyword in keyword_conflicts:
chapter_list = "" chapter_list = ""
for chapter in keyword_conflicts[keyword]: for chapter in keyword_conflicts[keyword]:
chapter_list += '<li><a href="#%s (%s)">%s</a></li>' % (keyword, chapters[chapter]['title'], chapters[chapter]['title']) chapter_list += '<li><a href="#%s">%s</a></li>' % (quote("%s (%s)" % (keyword, chapters[chapter]['title'])), chapters[chapter]['title'])
document = document.replace('&quot;' + keyword + '&quot;', document = document.replace('&quot;' + keyword + '&quot;',
'&quot;<span class="dropdown">' + '&quot;<span class="dropdown">' +
'<a class="dropdown-toggle" data-toggle="dropdown" href="#">' + '<a class="dropdown-toggle" data-toggle="dropdown" href="#">' +
Expand All @@ -152,14 +154,14 @@ def createLinks():
'</ul>' + '</ul>' +
'</span>&quot;') '</span>&quot;')
else: else:
document = document.replace('&quot;' + keyword + '&quot;', '&quot;<a href="#' + keyword + '">' + keyword + '</a>&quot;') document = document.replace('&quot;' + keyword + '&quot;', '&quot;<a href="#' + quote(keyword) + '">' + keyword + '</a>&quot;')
if keyword.startswith("option "): if keyword.startswith("option "):
shortKeyword = keyword[len("option "):] shortKeyword = keyword[len("option "):]
keywordsCount[shortKeyword] = document.count('&quot;' + shortKeyword + '&quot;') keywordsCount[shortKeyword] = document.count('&quot;' + shortKeyword + '&quot;')
if (shortKeyword in keyword_conflicts) and (not keywordsCount[shortKeyword]): if (shortKeyword in keyword_conflicts) and (not keywordsCount[shortKeyword]):
# The keyword is never used, we can remove it from the conflicts list # The keyword is never used, we can remove it from the conflicts list
del keyword_conflicts[shortKeyword] del keyword_conflicts[shortKeyword]
document = document.replace('&quot;' + shortKeyword + '&quot;', '&quot;<a href="#' + keyword + '">' + shortKeyword + '</a>&quot;') document = document.replace('&quot;' + shortKeyword + '&quot;', '&quot;<a href="#' + quote(keyword) + '">' + shortKeyword + '</a>&quot;')


def documentAppend(text, retline = True): def documentAppend(text, retline = True):
global document global document
Expand Down
3 changes: 2 additions & 1 deletion parser/keyword.py
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
import re import re
import parser import parser
from urllib import quote


class Parser(parser.Parser): class Parser(parser.Parser):
def __init__(self, pctxt): def __init__(self, pctxt):
Expand Down Expand Up @@ -70,7 +71,7 @@ def parse(self, line):


parameters = self.colorize(parameters) parameters = self.colorize(parameters)


res += '<div class="keyword">%s<b><a name="%s"></a><a href="#%s-%s">%s</a></b>%s%s</div>' % (prefix, keyword, toplevel, keyword, keyword, parameters, suffix) res += '<div class="keyword">%s<b><a name="%s"></a><a href="#%s">%s</a></b>%s%s</div>' % (prefix, keyword, quote("%s-%s" % (toplevel, keyword)), keyword, parameters, suffix)
pctxt.next() pctxt.next()
pctxt.stop = True pctxt.stop = True
elif line.startswith("/*"): elif line.startswith("/*"):
Expand Down
3 changes: 2 additions & 1 deletion templates/parser/table/row.tpl
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,4 @@
<% from urllib import quote %>
<tr>\ <tr>\
% for col in columns: % for col in columns:
<% data = col['data'] %>\ <% data = col['data'] %>\
Expand All @@ -21,7 +22,7 @@
%>\ %>\
<td ${style}>\ <td ${style}>\
% if "keyword" in col: % if "keyword" in col:
<a href="#${col['toplevel']}-${col['keyword']}">\ <a href="#${quote("%s-%s" % (col['toplevel'], col['keyword']))}">\
% for extra in col['extra']: % for extra in col['extra']:
<span class="pull-right">${extra}</span>\ <span class="pull-right">${extra}</span>\
% endfor % endfor
Expand Down

0 comments on commit 580be78

Please sign in to comment.