markdown-analysis 0.1.0__tar.gz → 0.1.2__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: markdown_analysis
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: UNKNOWN
5
5
  Home-page: https://github.com/yannbanas/mrkdwn_analysis
6
6
  Author: yannbanas
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: markdown-analysis
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: UNKNOWN
5
5
  Home-page: https://github.com/yannbanas/mrkdwn_analysis
6
6
  Author: yannbanas
@@ -233,6 +233,7 @@ class MarkdownParser:
233
233
  separator_line = self.lines[self.pos+1].strip()
234
234
  self.pos += 2
235
235
  rows = []
236
+
236
237
  while self.pos < self.length:
237
238
  line = self.lines[self.pos].strip()
238
239
  if not line or self.starts_new_block(line):
@@ -240,12 +241,21 @@ class MarkdownParser:
240
241
  rows.append(line)
241
242
  self.pos += 1
242
243
 
243
- header_cells = [h.strip() for h in header_line.strip('|').split('|') if h.strip()]
244
- data_rows = []
245
- for r in rows:
246
- data_rows.append([c.strip() for c in r.strip('|').split('|') if c.strip()])
244
+ def parse_row(row):
245
+ parts = row.strip().split('|')
246
+ if parts and not parts[0]:
247
+ parts.pop(0)
248
+ if parts and not parts[-1]:
249
+ parts.pop()
250
+ return [p.strip() for p in parts]
247
251
 
248
- self.tokens.append(BlockToken('table', meta={"header": header_cells, "rows": data_rows}, line=start+1))
252
+ header_cells = parse_row(header_line)
253
+ data_rows = [parse_row(row) for row in rows]
254
+
255
+ self.tokens.append(BlockToken('table', meta={
256
+ "header": header_cells,
257
+ "rows": data_rows
258
+ }, line=start+1))
249
259
 
250
260
  def starts_new_block(self, line):
251
261
  return (self.ATX_HEADER_RE.match(line) or
@@ -274,19 +284,24 @@ class MarkdownParser:
274
284
  self.pos = self.length
275
285
 
276
286
  def parse_fenced_code_block(self, lang):
287
+ initial_line = self.pos
288
+ initial_indent = len(self.lines[self.pos]) - len(self.lines[self.pos].lstrip())
289
+ fence_marker = self.lines[self.pos].strip()[:3] # Get ``` or ~~~
277
290
  self.pos += 1
278
291
  start = self.pos
292
+
279
293
  while self.pos < self.length:
280
294
  line = self.lines[self.pos]
281
- if line.strip().startswith('```'):
295
+ if line.strip() == fence_marker:
282
296
  content = "\n".join(self.lines[start:self.pos])
283
297
  self.tokens.append(BlockToken('code', content=content, meta={"language": lang}, line=start+1))
284
298
  self.pos += 1
285
299
  return
286
300
  self.pos += 1
287
- content = "\n".join(self.lines[start:])
288
- self.tokens.append(BlockToken('code', content=content, meta={"language": lang}, line=start+1))
289
- self.pos = self.length
301
+
302
+ # If we reach here, we didn't find the closing fence
303
+ self.pos = initial_line # Reset position if fence not found
304
+ raise ValueError(f"Unclosed code fence starting at line {initial_line + 1}")
290
305
 
291
306
  def parse_blockquote(self):
292
307
  start = self.pos
@@ -6,7 +6,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
6
6
 
7
7
  setup(
8
8
  name='markdown_analysis',
9
- version='0.1.0',
9
+ version='0.1.2',
10
10
  long_description=long_description,
11
11
  long_description_content_type="text/markdown",
12
12
  author='yannbanas',