Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
aa
wiki
Commits
f0cafb9c
Commit
f0cafb9c
authored
Apr 27, 2012
by
Alexandre Leray
Browse files
Quick fix of audacity import/export.
Still not satisfying... to be fixed.
parent
812042d2
Changes
3
Hide whitespace changes
Inline
Side-by-side
aawiki/mdx/mdx_sectionedit.py
View file @
f0cafb9c
...
...
@@ -84,7 +84,6 @@ import markdown
import
re
#HASH_HEADER_RE = r'^(?P<level>#{%s})(?P<header>.*?)#*$'
HASH_HEADER_RE
=
r
'^(?P<level>#{%s})[^#](?P<header>.*?)#*$'
DATE_RE
=
r
'\d\d\d\d-\d\d-\d\d'
TIME_RE
=
r
'(\d\d:)?(\d\d):(\d\d)([,.]\d{1,3})?'
...
...
@@ -168,15 +167,15 @@ def spliterator (pattern, text):
# Computes the heading level from the regex match group "level". If not
# present, it means that we are facing a (date)timecode header, hence a
# level 2 header according to our hierarchy.
level
=
len
(
match
.
groupdict
()
[
'level'
]
or
"##"
)
level
=
len
(
match
.
groupdict
()
.
get
(
'level'
)
or
"##"
)
for
match
in
matches
:
if
level
>=
len
(
match
.
groupdict
()
[
'level'
]
or
"##"
):
if
level
>=
len
(
match
.
groupdict
()
.
get
(
'level'
)
or
"##"
):
yield
dict
(
header
=
header
,
body
=
text
[
index
:
match
.
start
()],
start
=
start
,
end
=
match
.
start
(),
level
=
level
)
start
=
match
.
start
()
header
=
text
[
match
.
start
():
match
.
end
()]
index
=
match
.
end
()
level
=
len
(
match
.
groupdict
()
[
'level'
]
or
"##"
)
level
=
len
(
match
.
groupdict
()
.
get
(
'level'
)
or
"##"
)
yield
dict
(
header
=
header
,
body
=
text
[
index
:],
start
=
start
,
end
=
len
(
text
),
level
=
level
)
...
...
@@ -205,6 +204,23 @@ def sectionalize(text, sections=None, offset=0):
... print(section['start'], section['end'])
... print(section['header'] + section['body'])
================================
(0, 187)
<BLANKLINE>
Some text before
# Section 1
some text
### Section 3
Some more text
## Section 2
more text
00:00:10 --> Timed section
more text
### Section 3 again
more text
# Section 1 again
more text
<BLANKLINE>
================================
(18, 159)
# Section 1
some text
...
...
@@ -223,9 +239,12 @@ def sectionalize(text, sections=None, offset=0):
Some more text
<BLANKLINE>
================================
(69,
15
9)
(69, 9
2
)
## Section 2
more text
<BLANKLINE>
================================
(92, 159)
00:00:10 --> Timed section
more text
### Section 3 again
...
...
aawiki/templates/aawiki/annotation_import_confirm.html
View file @
f0cafb9c
{% extends "aawiki/base
_wiki
.html" %}
{% extends "aawiki/base.html" %}
{% block body %}
<form
method=
"post"
enctype=
"multipart/form-data"
...
...
aawiki/views.py
View file @
f0cafb9c
...
...
@@ -154,12 +154,18 @@ def annotation_export(request, slug, section, _format="audacity",
page
=
Page
.
objects
.
get
(
name
=
name
)
section
=
sectionalize
(
page
.
content
)[
int
(
section
)]
pattern
=
re
.
compile
(
DATETIMECODE_HEADER_RE
,
re
.
I
|
re
.
M
|
re
.
X
)
# TODO: Regex should not be defined more once within active archives
TIME_RE
=
r
'(\d\d:)?(\d\d):(\d\d)([,.]\d{1,3})?'
TIMECODE_RE
=
r
'(?P<start>%(TIME_RE)s)[ \t]*-->([ \t]*(?P<end>%(TIME_RE)s))?'
%
locals
()
OTHER_RE
=
r
'.+'
TIMECODE_HEADER_RE
=
r
'^%(TIMECODE_RE)s(%(OTHER_RE)s)?$'
%
locals
()
pattern
=
re
.
compile
(
TIMECODE_HEADER_RE
,
re
.
I
|
re
.
M
|
re
.
X
)
stack
=
[]
for
t
in
spliterator
(
pattern
,
section
[
'header'
]
+
section
[
'body'
],
returnLeading
=
0
):
m
=
pattern
.
match
(
t
[
0
]).
groupdict
()
for
t
in
spliterator
(
pattern
,
section
[
'header'
]
+
section
[
'body'
]):
m
=
pattern
.
match
(
t
[
'header'
]).
groupdict
()
if
force_endtime
:
if
len
(
stack
)
and
stack
[
-
1
][
'end'
]
==
''
:
...
...
@@ -171,7 +177,7 @@ def annotation_export(request, slug, section, _format="audacity",
stack
.
append
({
'start'
:
timecode_tosecs
(
m
[
'start'
]),
'end'
:
end
,
'body'
:
t
[
1
].
strip
(
'
\n
'
),
'body'
:
t
[
'body'
].
strip
(
'
\n
'
),
})
context
=
{
'sections'
:
stack
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment