Skip to content

neoteroi.spantable does not support code with pipes #62

@yves-chevallier

Description

@yves-chevallier

The following will fail:

::spantable::

| Foo | Bar |
| --- | --- |
| Baz | `|` |

::end-spantable::

One hack is to store temporary replace codes with a placeholder:

--- a/neoteroi/mkdocs/markdown/tables/__init__.py
+++ b/neoteroi/mkdocs/markdown/tables/__init__.py
@@ -115,6 +115,15 @@ def read_table(markdown: str, cls: Type[T] = Table) -> Optional[T]:
     records: List[List[str]] = []
 
     for line in markdown.splitlines():
+
+        # Code blocks could contain pipes, so we need to store them and replace them later
+        code = []
+        def store(match):
+            code.append(match.group(0))
+            return f"@@{len(code) - 1}@@"
+
+        line = re.sub(r"`[^`]+`", store, line)
+
         if _TABLE_SEPARATOR_LINE_PATTERN.match(line):
             continue
 
@@ -122,6 +131,11 @@ def read_table(markdown: str, cls: Type[T] = Table) -> Optional[T]:
 
         if matches:
             row = [match.group(1).strip() for match in matches]
+
+            for i, cell in enumerate(row):
+                row[i] = re.sub(
+                    r"@@(\d+)@@", lambda m: code[int(m.group(1))], cell)
+
             if not headers:
                 headers = row
             else:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions