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
670a9715
Commit
670a9715
authored
May 27, 2017
by
gaojiuli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support <del> <table> <hr>
parent
c8cab85b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
3 deletions
+77
-3
README.md
README.md
+34
-1
test_tomd.py
test_tomd.py
+20
-0
tomd.py
tomd.py
+23
-2
No files found.
README.md
View file @
670a9715
...
@@ -58,11 +58,30 @@ html="""
...
@@ -58,11 +58,30 @@ html="""
<p><code>inline code</code></p>
<p><code>inline code</code></p>
<pre><code>block code</code></pre>
<pre><code>block code</code></pre>
<p>
<p>
<del>del</del>
<b>bold</b>
<b>bold</b>
<i>italic</i>
<i>italic</i>
<b><i>bold italic</i></b>
<b><i>bold italic</i></b>
</p>
</p>
<hr/>
<table>
<thead>
<tr>
<th>表头1</th>
<th>表头2</th>
</tr>
</thead>
<tbody>
<tr>
<td>表格单元</td>
<td>表格单元</td>
</tr>
<tr>
<td>表格单元</td>
<td>表格单元</td>
</tr></tbody></table>
"""
"""
...
@@ -101,8 +120,22 @@ paragraph
...
@@ -101,8 +120,22 @@ paragraph
`inline code`
`inline code`
block code
~~del~~
**bold**
**bold**
*italic*
*italic*
***bold italic**
*
***bold italic**
*
---
|表头1|表头2
|------
|表格单元|表格单元
|表格单元|表格单元
```
```
test_tomd.py
View file @
670a9715
...
@@ -25,10 +25,30 @@ string = """
...
@@ -25,10 +25,30 @@ string = """
<p><code>inline code</code></p>
<p><code>inline code</code></p>
<pre><code>block code</code></pre>
<pre><code>block code</code></pre>
<p>
<p>
<del>del</del>
<b>bold</b>
<b>bold</b>
<i>italic</i>
<i>italic</i>
<b><i>bold italic</i></b>
<b><i>bold italic</i></b>
</p>
</p>
<hr/>
<table>
<thead>
<tr>
<th>表头1</th>
<th>表头2</th>
</tr>
</thead>
<tbody>
<tr>
<td>表格单元</td>
<td>表格单元</td>
</tr>
<tr>
<td>表格单元</td>
<td>表格单元</td>
</tr></tbody></table>
"""
"""
print
(
Tomd
(
string
)
.
markdown
)
print
(
Tomd
(
string
)
.
markdown
)
tomd.py
View file @
670a9715
...
@@ -20,7 +20,14 @@ MARKDOWN = {
...
@@ -20,7 +20,14 @@ MARKDOWN = {
'inline_p'
:
(
''
,
''
),
'inline_p'
:
(
''
,
''
),
'inline_p_with_out_class'
:
(
''
,
''
),
'inline_p_with_out_class'
:
(
''
,
''
),
'b'
:
(
'**'
,
'**'
),
'b'
:
(
'**'
,
'**'
),
'i'
:
(
'*'
,
'*'
)
'i'
:
(
'*'
,
'*'
),
'del'
:
(
'~~'
,
'~~'
),
'hr'
:
(
'
\n
---'
,
'
\n\n
'
),
'thead'
:
(
'
\n
'
,
'|------
\n
'
),
'tbody'
:
(
'
\n
'
,
'
\n
'
),
'td'
:
(
'|'
,
''
),
'th'
:
(
'|'
,
''
),
'tr'
:
(
''
,
'
\n
'
)
}
}
BlOCK_ELEMENTS
=
{
BlOCK_ELEMENTS
=
{
...
@@ -36,11 +43,19 @@ BlOCK_ELEMENTS = {
...
@@ -36,11 +43,19 @@ BlOCK_ELEMENTS = {
'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>'
,
'thead'
:
'<thead.*?>(.*?)</thead>'
,
# 'tbody': '<tbody.*?>(.*?)</tbody>',
'tr'
:
'<tr>(.*?)</tr>'
,
}
INLINE_ELEMENTS
=
{
INLINE_ELEMENTS
=
{
'td'
:
'<td>(.*?)</td>'
,
'tr'
:
'<tr>(.*?)</tr>'
,
'th'
:
'<th>(.*?)</th>'
,
'b'
:
'<b>(.*?)</b>'
,
'b'
:
'<b>(.*?)</b>'
,
'i'
:
'<i>(.*?)</i>'
,
'i'
:
'<i>(.*?)</i>'
,
'del'
:
'<del>(.*?)</del>'
,
'inline_p'
:
'<p
\
s.*?>(.*?)</p>'
,
'inline_p'
:
'<p
\
s.*?>(.*?)</p>'
,
'inline_p_with_out_class'
:
'<p>(.*?)</p>'
,
'inline_p_with_out_class'
:
'<p>(.*?)</p>'
,
'code'
:
'<code.*?>(.*?)</code>'
,
'code'
:
'<code.*?>(.*?)</code>'
,
...
@@ -85,6 +100,12 @@ class Element:
...
@@ -85,6 +100,12 @@ class Element:
self
.
content
=
re
.
sub
(
pattern
,
'-
\
g<1>'
,
self
.
content
)
self
.
content
=
re
.
sub
(
pattern
,
'-
\
g<1>'
,
self
.
content
)
elif
self
.
tag
==
'ol'
and
tag
==
'li'
:
elif
self
.
tag
==
'ol'
and
tag
==
'li'
:
self
.
content
=
re
.
sub
(
pattern
,
'1.
\
g<1>'
,
self
.
content
)
self
.
content
=
re
.
sub
(
pattern
,
'1.
\
g<1>'
,
self
.
content
)
elif
self
.
tag
==
'thead'
and
tag
==
'tr'
:
self
.
content
=
re
.
sub
(
pattern
,
'
\
g<1>
\n
'
,
self
.
content
.
replace
(
'
\n
'
,
''
))
elif
self
.
tag
==
'tr'
and
tag
==
'th'
:
self
.
content
=
re
.
sub
(
pattern
,
'|
\
g<1>'
,
self
.
content
.
replace
(
'
\n
'
,
''
))
elif
self
.
tag
==
'tr'
and
tag
==
'td'
:
self
.
content
=
re
.
sub
(
pattern
,
'|
\
g<1>'
,
self
.
content
.
replace
(
'
\n
'
,
''
))
else
:
else
:
wrapper
=
MARKDOWN
.
get
(
tag
)
wrapper
=
MARKDOWN
.
get
(
tag
)
self
.
content
=
re
.
sub
(
pattern
,
'{}
\
g<1>{}'
.
format
(
wrapper
[
0
],
wrapper
[
1
]),
self
.
content
)
self
.
content
=
re
.
sub
(
pattern
,
'{}
\
g<1>{}'
.
format
(
wrapper
[
0
],
wrapper
[
1
]),
self
.
content
)
...
...
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