Ошибка, видимо, тупая, но я никак не могу понять, в чём дело(Вот код для того, чтобы создавать html таблицу по разметке типа wiki:
def htmlize(str=''):
# print 'in htmlize',str.encode('koi8-r')
links = re.findall(r'https?://\S',str)
# links += re.findall(r'https://\S',str)
html = ''
inBold = False
inItalic = False
# для таблицы
inTable = False
inRow = False
inCell = False
tegs = {True:''
elif str[count] == '' and count+1'
inBold = not inBold
elif str[count] == '' and count+1'
count +=1
inItalic = not inItalic
elif str[count] == '*' and inBold:
html = html + ''
elif str[count] == '\' and count+1==len(str):
html += '\'
elif str[count] == '\':
html += str[count+1]
count += 1
elif str[count] == '':
html += '>'
count +=1
elif str[count] == '&':
html += '&'
# count +=1
# обработка создания таблиц
elif count+3'
inTable = True
inRow = True
inCell = True
elif inTable and not inRow:
html += ''
inRow = True
inCell = True
elif inCell:
if str[count+2]!='\n':
html+=''
inCell = True
if str[count+2] == '\n':
html+=''
inCell = False
inRow=False
count+1
if str[count+3]!='|':
html+=''
inTable=False
count+=1
elif (count+2>=len(str) and inTable) or (count+3'
inCell = False
if inRow:
html += ''
inRow = False
html+=''
inTable = False
count+=1
else:
html += str[count]
count +=1
for link in links:
html = html.replace(link.replace('&','&'),''+link+'')
return html
Если я запускаю этот код на python 2.7.3 получается:
>>> b="""||a||b||
... ||c||d||
... text
... ||a||b||
... ||d||c||"""
>>> print(htmlize(b))
ab
cdtextab
dc
однако в Django 1.4 в полученной странице я вижу лишь:
ab cd text ab dc
Без некоторых тегов <tr> и </tr>, вся таблица получается в одну строку. В чём может быть дело?Вот как я вызываю htmlize в view.py:
for note in notes:
note.note = htmlize(note.note)
UPD: Если я использую стороннюю библиотеку textile, то, хотя в консоли результат тот же, тем не менее в странице всё равно видна разница:
ishayahu@test_pg_master:/home/ishayahu/tasks % ./manage.py shell
Python 2.7.3 (default, Jan 22 2013, 12:19:56)
[GCC 4.2.1 20070831 patched [FreeBSD]] on freebsd9
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import textile
>>> from todoes.ize import htmlize
>>> a="""||a||b||
... ||c||d||
... text
... ||a||b||
... ||c||d||"""
>>> htmlize(a)
'ab\t\ncd
\ttextab\t
\ncd\t'
>>> textile.textile(a)
'\t\n\t\t\n\t\t\t\n\t\t\ta\n\t\t\t\n
\t\t\tb\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n
\t\t\tc\n\t\t\t\n\t\t\td\n\t\t\t\n\t\t
\n\t\t\n\n\t\t\n\t\t\n\t\t\t\n\t\t\ta\n\t\t\t
\n\t\t\tb\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n
\t\t\tc\n\t\t\t\n\t\t\td\n\t\t\t\n\t\t
\n\t'
>>>