Encode characters in blocks as html entities
This commit is contained in:
parent
003a592319
commit
76cc5f78c5
|
@ -1,3 +1,4 @@
|
||||||
|
from html import escape
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from eorg.const import Token, ESCAPE
|
from eorg.const import Token, ESCAPE
|
||||||
from eorg import tokens
|
from eorg import tokens
|
||||||
|
@ -14,7 +15,7 @@ def src(doc, code, cls="", root=True):
|
||||||
except pygments.util.ClassNotFound as e:
|
except pygments.util.ClassNotFound as e:
|
||||||
lexer = get_lexer_by_name(code.attrs.get("language", "text"))
|
lexer = get_lexer_by_name(code.attrs.get("language", "text"))
|
||||||
|
|
||||||
return highlight(code.value, lexer, HtmlFormatter(linenos=True))
|
return highlight(escape(code.value), lexer, HtmlFormatter(linenos=True))
|
||||||
|
|
||||||
|
|
||||||
def img(doc, item, cls="", root=True):
|
def img(doc, item, cls="", root=True):
|
||||||
|
@ -47,7 +48,7 @@ def parse_text_html(doc, token, cls="", root=True):
|
||||||
def blockquote(doc, token, cls="", root=True):
|
def blockquote(doc, token, cls="", root=True):
|
||||||
return "<blockquote%s>%s</blockquote>\n" % (
|
return "<blockquote%s>%s</blockquote>\n" % (
|
||||||
cls,
|
cls,
|
||||||
token.value.replace("\n", "<br />"),
|
escape(token.value).replace("\n", "<br />"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from eorg.parser import parse
|
||||||
from eorg.generate import html
|
from eorg.generate import html
|
||||||
|
|
||||||
|
|
||||||
def test_basic():
|
def test_table():
|
||||||
document = """| Header 1 | Header 2 |
|
document = """| Header 1 | Header 2 |
|
||||||
| row 1 | row 2 |
|
| row 1 | row 2 |
|
||||||
"""
|
"""
|
||||||
|
@ -14,8 +14,15 @@ def test_basic():
|
||||||
assert doc.doc[0].token == tokens.TABLE
|
assert doc.doc[0].token == tokens.TABLE
|
||||||
r1 = doc.doc[0].value.strip()
|
r1 = doc.doc[0].value.strip()
|
||||||
r2 = document.strip()
|
r2 = document.strip()
|
||||||
print(r1)
|
|
||||||
print(r2)
|
|
||||||
assert r1 == r2
|
assert r1 == r2
|
||||||
|
|
||||||
|
def test_example():
|
||||||
|
document = """#+BEGIN_EXAMPLE
|
||||||
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="view-source:https://edwardtufte.github.io/tufte-css/tufte.css" />
|
||||||
|
#+END_EXAMPLE"""
|
||||||
|
doc = parse(StringIO(document))
|
||||||
|
assert doc.doc[0].token == tokens.EXAMPLE
|
||||||
|
r1 = doc.doc[0].value.strip()
|
||||||
|
r2 = document.strip()
|
||||||
|
assert r1 == r2
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue