Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neoteroi.spantable does not support code with pipes #62

Open
yves-chevallier opened this issue Jul 15, 2024 · 0 comments
Open

neoteroi.spantable does not support code with pipes #62

yves-chevallier opened this issue Jul 15, 2024 · 0 comments

Comments

@yves-chevallier
Copy link

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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant