Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
34bf24b1
Commit
34bf24b1
authored
Jan 25, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve bbcode highlighter and add testcase for it
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
133cca7b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
weblate/trans/checks/markup.py
weblate/trans/checks/markup.py
+7
-8
weblate/trans/tests/test_markup_checks.py
weblate/trans/tests/test_markup_checks.py
+4
-0
No files found.
weblate/trans/checks/markup.py
View file @
34bf24b1
...
@@ -26,7 +26,7 @@ from django.utils.translation import ugettext_lazy as _
...
@@ -26,7 +26,7 @@ from django.utils.translation import ugettext_lazy as _
from
weblate.trans.checks.base
import
TargetCheck
from
weblate.trans.checks.base
import
TargetCheck
BBCODE_MATCH
=
re
.
compile
(
BBCODE_MATCH
=
re
.
compile
(
r'
\
[(?P<
tag>[^]]*)(?=(@[^]]*)?\
](.*?)
\[\
/(?P=
tag)\
])
',
r'
(?P<start>\
[(?P<
tag>[^]]+)(@[^]]*)?\
])(.*?)(?P<e
nd>
\
[
\/(?P=tag)\
])
',
re.MULTILINE
re.MULTILINE
)
)
...
@@ -61,8 +61,8 @@ class BBCodeCheck(TargetCheck):
...
@@ -61,8 +61,8 @@ class BBCodeCheck(TargetCheck):
if
len
(
src_match
)
!=
len
(
tgt_match
):
if
len
(
src_match
)
!=
len
(
tgt_match
):
return
True
return
True
src_tags
=
set
([
x
[
0
]
for
x
in
src_match
])
src_tags
=
set
([
x
[
1
]
for
x
in
src_match
])
tgt_tags
=
set
([
x
[
0
]
for
x
in
tgt_match
])
tgt_tags
=
set
([
x
[
1
]
for
x
in
tgt_match
])
return
src_tags
!=
tgt_tags
return
src_tags
!=
tgt_tags
...
@@ -70,13 +70,12 @@ class BBCodeCheck(TargetCheck):
...
@@ -70,13 +70,12 @@ class BBCodeCheck(TargetCheck):
if
self
.
should_skip
(
unit
):
if
self
.
should_skip
(
unit
):
return
[]
return
[]
ret
=
[]
ret
=
[]
match_objects
=
BBCODE_MATCH
.
finditer
(
source
)
for
match
in
BBCODE_MATCH
.
finditer
(
source
):
for
match
in
match_objects
:
ret
.
append
((
match
.
start
(
'start'
),
match
.
group
(
'start'
)))
if
match
.
start
()
==
match
.
end
():
ret
.
append
((
match
.
start
(
'end'
),
match
.
group
(
'end'
)))
continue
ret
.
append
((
match
.
start
(),
match
.
group
()))
return
ret
return
ret
class
XMLTagsCheck
(
TargetCheck
):
class
XMLTagsCheck
(
TargetCheck
):
'''
'''
Check whether XML in target matches source.
Check whether XML in target matches source.
...
...
weblate/trans/tests/test_markup_checks.py
View file @
34bf24b1
...
@@ -37,6 +37,10 @@ class BBCodeCheckTest(CheckTestCase):
...
@@ -37,6 +37,10 @@ class BBCodeCheckTest(CheckTestCase):
self
.
test_good_matching
=
(
'[a]string[/a]'
,
'[a]string[/a]'
,
''
)
self
.
test_good_matching
=
(
'[a]string[/a]'
,
'[a]string[/a]'
,
''
)
self
.
test_failure_1
=
(
'[a]string[/a]'
,
'[b]string[/b]'
,
''
)
self
.
test_failure_1
=
(
'[a]string[/a]'
,
'[b]string[/b]'
,
''
)
self
.
test_failure_2
=
(
'[a]string[/a]'
,
'string'
,
''
)
self
.
test_failure_2
=
(
'[a]string[/a]'
,
'string'
,
''
)
self
.
test_highlight
=
(
'[a]string[/a]'
,
[(
0
,
'[a]'
),
(
9
,
'[/a]'
)]
)
class
XMLTagsCheckTest
(
CheckTestCase
):
class
XMLTagsCheckTest
(
CheckTestCase
):
...
...
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