Commit 812042d2 authored by Alexandre Leray's avatar Alexandre Leray
Browse files

Fixed a few imports related to last commit

parent da613ad1
......@@ -17,7 +17,7 @@
import re
from aawiki.mdx.mdx_sectionedit import (TIMECODE_HEADER, spliterator)
from aawiki.mdx.mdx_sectionedit import (DATETIMECODE_HEADER_RE, spliterator)
from aawiki.timecode import (timecode_fromsecs, timecode_tosecs)
......@@ -109,7 +109,7 @@ def audacity_to_srt(data, explicit=False):
def srt_to_audacity(data, force_endtime=False):
"""docstring for srt_to_audacity"""
# FIXME: UnicodeDecodeError...
pattern = re.compile(TIMECODE_HEADER, re.I | re.M | re.X)
pattern = re.compile(DATETIMECODE_HEADER_RE, re.I | re.M | re.X)
stack = []
for t in spliterator(pattern, data, returnLeading=0):
......
......@@ -60,6 +60,30 @@ def make_link(rel, target, label, default_link_rel=None, filter_=None):
return a
def aa_make_link(rel, target, label):
a = etree.Element('a')
a.set('href', target)
if rel:
a.set('rel', rel or 'aa:link')
else:
a.set('rel', 'aa:link')
if label:
if label.startswith('|'):
label, filter_ = None, label[1:]
else:
try:
label, filter_ = label.split('|', 1)
except ValueError:
filter_ = None
if filter_:
a.set('data-filter', filter_.strip())
a.text = label or target
return a
#"""
# <a rel="aa:link" href="/pages/Anthology_walk%2Btalk_Brussels">
# <span about="/pages/Anthology_walk%2Btalk_Brussels">
......
......@@ -250,10 +250,9 @@ def sectionalize(text, sections=None, offset=0):
... assert txt1 == txt2
"""
if sections is None:
sections = []
#sections = [dict(header='', body=text, start=0, end=len(text), index=0)]
sections = [dict(header='', body=text, start=0, end=len(text), index=0)]
pattern = re.compile(HASH_HEADER_RE % '1,6', re.M)
pattern = re.compile(HASH_OR_DATETIMECODE_HEADER_RE % '1,6', re.M)
for section in spliterator(pattern, text):
section['index'] = len(sections) # numbers the section
......@@ -294,12 +293,14 @@ class SectionEditPreprocessor(markdown.preprocessors.Preprocessor):
newlines = []
pattern = re.compile(HASH_OR_DATETIMECODE_HEADER_RE % '1,6', re.M)
i = 0
for line in lines:
if pattern.match(line):
newlines.append(line.rstrip() + " {@data-section=%d}" % (i+1))
i += 1
newlines.append(line.rstrip() + " {@data-section=%d}" % i)
else:
newlines.append(line)
return newlines
......
......@@ -1024,14 +1024,15 @@ article.map div#wrapper {
border: 1px solid gray;
padding: 0 5px;
background-color: white;
}
.ui-button .ui-button-text {
display: block;
font-family: 'News Cycle';
font-size: 9px;
letter-spacing: 1px;
text-transform: uppercase;
}
.ui-button .ui-button-text {
display: block;
font-size: 9px;
}
.ui-helper-clearfix:before, .ui-helper-clearfix:after {
content: "";
display: table;
......
......@@ -40,23 +40,30 @@ def pagename_for_url(url):
def wikify(name):
"""
Turns a "raw" name into a URL wiki name (aka slug)
Requires: name may be unicode, str
Returns: str
(1) Spaces turn into underscores.
(2) The First letter is forced to be Uppercase (normalization).
(3) For the rest, non-ascii chars get percentage escaped.
1. Spaces turn into underscores.
2. The First letter is forced to be Uppercase (normalization).
3. For the rest, non-ascii chars get percentage escaped.
(Unicode chars be (properly) encoded to bytes and urllib.quote'd to double escapes like "%23%25" as required)
>>> wikify("my page name")
'My_page_name'
>>> wikify(";/?:@=#&")
'%3B%2F%3F%3A%40%3D%23%26'
"""
name = name.strip()
name = name.replace(" ", "_")
name = name.strip().replace(" ", "_")
if len(name):
name = name[0].upper() + name[1:]
if (type(name) == unicode):
# urllib.quoting(unicode) with accents freaks out so encode to bytes
name = name.encode("utf-8")
name = urllib.quote(name, safe="")
return name
return urllib.quote(name, safe="")
def dewikify(name):
"""
......
......@@ -36,7 +36,7 @@ from aacore.utils import add_resource
from aawiki.utils import (dewikify, convert_line_endings)
from aawiki.mdx import get_markdown
from aawiki.mdx.mdx_sectionedit import (sectionalize, sectionalize_replace,
TIMECODE_HEADER, spliterator)
DATETIMECODE_HEADER_RE, spliterator)
from aawiki.forms import (PageEditForm, AnnotationImportForm)
from aawiki.audacity import audacity_to_srt
from aawiki.timecode import timecode_tosecs
......@@ -154,7 +154,7 @@ def annotation_export(request, slug, section, _format="audacity",
page = Page.objects.get(name=name)
section = sectionalize(page.content)[int(section)]
pattern = re.compile(TIMECODE_HEADER, re.I | re.M | re.X)
pattern = re.compile(DATETIMECODE_HEADER_RE, re.I | re.M | re.X)
stack = []
for t in spliterator(pattern, section['header'] + section['body'],
......@@ -348,7 +348,7 @@ def page_edit(request, slug):
if section == -1:
page.content = page.content.rstrip() + "\n\n" + content
else:
page.content = sectionalize_replace(page.content, section, content, keep_header=keep_header)
page.content = sectionalize_replace(page.content, section, content)
if page.content != old_content:
page.commit(message=message, author=author, is_minor=is_minor)
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment