Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
785ddb5d
Commit
785ddb5d
authored
Aug 31, 2012
by
David Ormsbee
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #584 from MITx/feature/victor/double-double-html
Fix inline html bug.
parents
717223be
fe50f944
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
5 deletions
+42
-5
common/lib/xmodule/xmodule/stringify.py
+12
-4
common/lib/xmodule/xmodule/tests/test_stringify.py
+30
-1
No files found.
common/lib/xmodule/xmodule/stringify.py
View file @
785ddb5d
...
...
@@ -12,9 +12,17 @@ def stringify_children(node):
fixed from
http://stackoverflow.com/questions/4624062/get-all-text-inside-a-tag-in-lxml
'''
parts
=
([
node
.
text
]
+
list
(
chain
(
*
([
etree
.
tostring
(
c
),
c
.
tail
]
for
c
in
node
.
getchildren
())
)))
# Useful things to know:
# node.tostring() -- generates xml for the node, including start
# and end tags. We'll use this for the children.
# node.text -- the text after the end of a start tag to the start
# of the first child
# node.tail -- the text after the end this tag to the start of the
# next element.
parts
=
[
node
.
text
]
for
c
in
node
.
getchildren
():
parts
.
append
(
etree
.
tostring
(
c
,
with_tail
=
True
))
# filter removes possible Nones in texts and tails
return
''
.
join
(
filter
(
None
,
parts
))
common/lib/xmodule/xmodule/tests/test_stringify.py
View file @
785ddb5d
from
nose.tools
import
assert_equals
from
nose.tools
import
assert_equals
,
assert_true
,
assert_false
from
lxml
import
etree
from
xmodule.stringify
import
stringify_children
...
...
@@ -8,3 +8,32 @@ def test_stringify():
xml
=
etree
.
fromstring
(
html
)
out
=
stringify_children
(
xml
)
assert_equals
(
out
,
text
)
def
test_stringify_again
():
html
=
"""<html name="Voltage Source Answer" >A voltage source is non-linear!
<div align="center">
<img src="/static/images/circuits/voltage-source.png"/>
\
(V=V_C
\
)
</div>
But it is <a href="http://mathworld.wolfram.com/AffineFunction.html">affine</a>,
which means linear except for an offset.
</html>
"""
html
=
"""<html>A voltage source is non-linear!
<div align="center">
</div>
But it is <a href="http://mathworld.wolfram.com/AffineFunction.html">affine</a>,
which means linear except for an offset.
</html>
"""
xml
=
etree
.
fromstring
(
html
)
out
=
stringify_children
(
xml
)
print
"output:"
print
out
# Tracking strange content repeating bug
# Should appear once
assert_equals
(
out
.
count
(
"But it is "
),
1
)
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