diff --git a/test2.py b/test2.py
new file mode 100644
index 0000000..8e9c6e0
--- /dev/null
+++ b/test2.py
@@ -0,0 +1,34 @@
+from tomd import Tomd
+
+table='''
+
+
+
+ head1 |
+ head2 |
+ head3 |
+
+
+
+
+ content1 |
+ content2 |
+ content3 |
+
+
+
+'''
+
+
+md = Tomd(table).markdown
+print("~~~~~~~~~~~~~")
+print(md)
+print("~~~~~~~~~~~~~")
+
+'''
+output
+|head1|head2|head3
+|------
+|content1|content2|content3|
+'''
+
diff --git a/tomd.py b/tomd.py
index 9f168b0..2b0e9ad 100644
--- a/tomd.py
+++ b/tomd.py
@@ -134,8 +134,6 @@ def parse_inline(self):
self.content = self.content.replace('
', '\n---\n')
self.content = self.content.replace('
', '')
- if self.tag == "table": # for removing tbody
- self.content = re.sub(INLINE_ELEMENTS['tbody'], '\g<1>', self.content)
INLINE_ELEMENTS_LIST_KEYS = list(INLINE_ELEMENTS.keys())
INLINE_ELEMENTS_LIST_KEYS.sort()
@@ -161,11 +159,6 @@ def parse_inline(self):
elif self.tag == 'tr' and tag == 'td':
self.content = re.sub(pattern, '|\g<1>|', self.content.replace('\n', ''))
self.content = self.content.replace("||", "|") # end of column also needs a pipe
- elif self.tag == 'table' and tag == 'td':
- self.content = re.sub(pattern, '|\g<1>|', self.content)
- self.content = self.content.replace("||", "|") # end of column also needs a pipe
- self.content = self.content.replace('|\n\n', '|\n') # replace double new line
- self.construct_table()
else:
wrapper = MARKDOWN.get(tag)
if tag == "strong":
@@ -177,22 +170,6 @@ def parse_inline(self):
# focusing on div, add new line if not there (and if content is long enough)
self.content += '\n'
- def construct_table(self):
- # this function, after self.content has gained | for table entries,
- # adds the |---| in markdown to create a proper table
-
- temp = self.content.split('\n', 3)
- for elt in temp:
- if elt != "":
- count = elt.count("|") # count number of pipes
- break
- pipe = "\n|" # beginning \n for safety
- for i in range(count - 1):
- pipe += "---|"
- pipe += "\n"
- self.content = pipe + pipe + self.content + "\n" # TODO: column titles?
- self.content = self.content.replace('|\n\n', '|\n') # replace double new line
- self.content = self.content.replace("
\n", "
") # end of column also needs a pipe
class Tomd:
@@ -207,6 +184,7 @@ def convert(self, html="", options=None):
if html == "":
html = self.html
# main function here
+ html = re.sub("\s+",'', html) #del \n\t
elements = []
for tag, pattern in BlOCK_ELEMENTS.items():
for m in re.finditer(pattern, html, re.I | re.S | re.M):