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
99cc0ab8
Commit
99cc0ab8
authored
May 27, 2017
by
gaojiuli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change BLOCK_ELEMENTS from tuple to dict.
parent
9a889e8c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
17 deletions
+19
-17
tomd.py
tomd.py
+19
-17
No files found.
tomd.py
View file @
99cc0ab8
...
@@ -23,22 +23,22 @@ MARKDOWN = {
...
@@ -23,22 +23,22 @@ MARKDOWN = {
'i'
:
(
'*'
,
'*'
)
'i'
:
(
'*'
,
'*'
)
}
}
BlOCK_ELEMENTS
=
(
BlOCK_ELEMENTS
=
{
(
'h1'
,
'<h1.*?>(.*?)</h1>'
)
,
'h1'
:
'<h1.*?>(.*?)</h1>'
,
(
'h2'
,
'<h2.*?>(.*?)</h2>'
)
,
'h2'
:
'<h2.*?>(.*?)</h2>'
,
(
'h3'
,
'<h3.*?>(.*?)</h3>'
)
,
'h3'
:
'<h3.*?>(.*?)</h3>'
,
(
'h4'
,
'<h4.*?>(.*?)</h4>'
)
,
'h4'
:
'<h4.*?>(.*?)</h4>'
,
(
'h5'
,
'<h5.*?>(.*?)</h5>'
)
,
'h5'
:
'<h5.*?>(.*?)</h5>'
,
(
'h6'
,
'<h6.*?>(.*?)</h6>'
)
,
'h6'
:
'<h6.*?>(.*?)</h6>'
,
(
'hr'
,
'<hr/>'
)
,
'hr'
:
'<hr/>'
,
(
'blockquote'
,
'<blockquote.*?>(.*?)</blockquote>'
)
,
'blockquote'
:
'<blockquote.*?>(.*?)</blockquote>'
,
(
'ul'
,
'<ul.*?>(.*?)</ul>'
)
,
'ul'
:
'<ul.*?>(.*?)</ul>'
,
(
'ol'
,
'<ol.*?>(.*?)</ol>'
)
,
'ol'
:
'<ol.*?>(.*?)</ol>'
,
(
'block_code'
,
'<pre.*?><code.*?>(.*?)</code></pre>'
)
,
'block_code'
:
'<pre.*?><code.*?>(.*?)</code></pre>'
,
(
'p'
,
'<p
\
s.*?>(.*?)</p>'
)
,
'p'
:
'<p
\
s.*?>(.*?)</p>'
,
(
'p_with_out_class'
,
'<p>(.*?)</p>'
)
,
'p_with_out_class'
:
'<p>(.*?)</p>'
,
(
'b'
,
'<b>(.*?)</b>'
)
,
'b'
:
'<b>(.*?)</b>'
,
(
'i'
,
'<i>(.*?)</i>'
))
'i'
:
'<i>(.*?)</i>'
}
INLINE_ELEMENTS
=
{
INLINE_ELEMENTS
=
{
'b'
:
'<b>(.*?)</b>'
,
'b'
:
'<b>(.*?)</b>'
,
...
@@ -102,7 +102,7 @@ class Tomd:
...
@@ -102,7 +102,7 @@ class Tomd:
self
.
_markdown
=
re
.
sub
(
element
,
''
,
self
.
_markdown
)
self
.
_markdown
=
re
.
sub
(
element
,
''
,
self
.
_markdown
)
def
parse_block
(
self
):
def
parse_block
(
self
):
for
tag
,
pattern
in
BlOCK_ELEMENTS
:
for
tag
,
pattern
in
BlOCK_ELEMENTS
.
items
()
:
for
m
in
re
.
finditer
(
pattern
,
self
.
html
,
re
.
I
|
re
.
S
|
re
.
M
):
for
m
in
re
.
finditer
(
pattern
,
self
.
html
,
re
.
I
|
re
.
S
|
re
.
M
):
element
=
Element
(
start_pos
=
m
.
start
(),
element
=
Element
(
start_pos
=
m
.
start
(),
end_pos
=
m
.
end
(),
end_pos
=
m
.
end
(),
...
@@ -113,6 +113,8 @@ class Tomd:
...
@@ -113,6 +113,8 @@ class Tomd:
for
e
in
self
.
_elements
:
for
e
in
self
.
_elements
:
if
e
.
start_pos
<
m
.
start
()
and
e
.
end_pos
>
m
.
end
():
if
e
.
start_pos
<
m
.
start
()
and
e
.
end_pos
>
m
.
end
():
can_append
=
False
can_append
=
False
elif
e
.
start_pos
>
m
.
start
()
and
e
.
end_pos
<
m
.
end
():
self
.
_elements
.
remove
(
e
)
if
can_append
:
if
can_append
:
self
.
_elements
.
append
(
element
)
self
.
_elements
.
append
(
element
)
...
...
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