Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tomd
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Чумбаев Максим
tomd
Commits
e2efb208
Commit
e2efb208
authored
Oct 17, 2018
by
Madmadmax
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Features:
Add html entities Add <small> to tag list Remove excess line breaks
parent
94590f8e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
1 deletion
+55
-1
tomd.py
tomd.py
+55
-1
No files found.
tomd.py
View file @
e2efb208
...
@@ -81,7 +81,53 @@ INLINE_ELEMENTS = {
...
@@ -81,7 +81,53 @@ INLINE_ELEMENTS = {
'tbody'
:
'<tbody.*?>((.|
\n
)*)</tbody>'
,
'tbody'
:
'<tbody.*?>((.|
\n
)*)</tbody>'
,
}
}
DELETE_ELEMENTS
=
[
'<span.*?>'
,
'</span>'
,
'<div.*?>'
,
'</div>'
,
'<br clear="none"/>'
,
'<center.*?>'
,
'</center>'
]
DELETE_ELEMENTS
=
[
'<span.*?>'
,
'</span>'
,
'<div.*?>'
,
'</div>'
,
'<br clear="none"/>'
,
'<center.*?>'
,
'</center>'
,
'<small>'
,
'</small>'
]
HTML_ENTITIES
=
{
"&"
:
"&"
,
"<"
:
"<"
,
">"
:
">"
,
" "
:
" "
,
"¡"
:
"¡"
,
"¢"
:
"¢"
,
"£"
:
"£"
,
"¤"
:
"¤"
,
"¥"
:
"¥"
,
"¦"
:
"¦"
,
"§"
:
"§"
,
"¨"
:
"¨"
,
"©"
:
"©"
,
"«"
:
"«"
,
"¬"
:
"¬"
,
"­"
:
""
,
"®"
:
"®"
,
"¯"
:
"¯"
,
"°"
:
"°"
,
"±"
:
"±"
,
"²"
:
"²"
,
"³"
:
"³"
,
"´"
:
"´"
,
"¶"
:
"¶"
,
"¸"
:
"¸"
,
"¹"
:
"¹"
,
"»"
:
"»"
,
"¼"
:
"¼"
,
"½"
:
"½"
,
"¾"
:
"¾"
,
"¿"
:
"¿"
,
"×"
:
"×"
,
"÷"
:
"÷"
,
}
class
Element
:
class
Element
:
...
@@ -107,6 +153,9 @@ class Element:
...
@@ -107,6 +153,9 @@ class Element:
self
.
content
=
self
.
content
.
replace
(
'
\r
'
,
''
)
# windows \r character
self
.
content
=
self
.
content
.
replace
(
'
\r
'
,
''
)
# windows \r character
self
.
content
=
self
.
content
.
replace
(
'
\xc2\xa0
'
,
' '
)
# no break space
self
.
content
=
self
.
content
.
replace
(
'
\xc2\xa0
'
,
' '
)
# no break space
self
.
content
=
self
.
content
.
replace
(
'"'
,
'
\"
'
)
# html quote mark
self
.
content
=
self
.
content
.
replace
(
'"'
,
'
\"
'
)
# html quote mark
# replace html entities
for
symbol
in
HTML_ENTITIES
.
keys
():
self
.
content
=
self
.
content
.
replace
(
symbol
,
HTML_ENTITIES
[
symbol
])
for
m
in
re
.
finditer
(
"<img(.*?)en_todo.*?>"
,
self
.
content
):
for
m
in
re
.
finditer
(
"<img(.*?)en_todo.*?>"
,
self
.
content
):
# remove img and change to [ ] and [x]
# remove img and change to [ ] and [x]
...
@@ -230,6 +279,11 @@ class Tomd:
...
@@ -230,6 +279,11 @@ class Tomd:
for
index
,
element
in
enumerate
(
DELETE_ELEMENTS
):
for
index
,
element
in
enumerate
(
DELETE_ELEMENTS
):
self
.
_markdown
=
re
.
sub
(
element
,
''
,
self
.
_markdown
)
self
.
_markdown
=
re
.
sub
(
element
,
''
,
self
.
_markdown
)
# Delete excess line breaks
while
self
.
_markdown
.
startswith
(
'
\n
'
):
self
.
_markdown
=
self
.
_markdown
[
1
:]
return
self
.
_markdown
return
self
.
_markdown
@
property
@
property
...
...
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