-
Notifications
You must be signed in to change notification settings - Fork 54
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
ENH pandoc parser minor improvements and support older pandoc #284
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ def __init__(self): | |
"RawInline": self._raw_inline, | ||
"RawBlock": self._raw_block, | ||
"SoftBreak": self._soft_break, | ||
"LineBreak": self._line_break, | ||
"Para": self._para, | ||
"Header": self._header, | ||
"Image": self._image, | ||
|
@@ -124,6 +125,9 @@ def _soft_break(self, value) -> str: | |
incr = 0 if not self._indent_trace else self._indent_trace[-1] | ||
return "\n" + self._get_indent(incr=incr) | ||
|
||
def _line_break(self, value) -> str: | ||
return "\n" | ||
|
||
def _make_content(self, content): | ||
parts = [] | ||
for item in content: | ||
|
@@ -185,7 +189,14 @@ def _code(item: tuple[Any, str]) -> str: | |
_, txt = item | ||
return f"`{txt}`" | ||
|
||
def _table_cols(self, items) -> list[str]: | ||
def _table_cols_old(self, items) -> list[str]: | ||
columns = [] | ||
for (content,) in items: | ||
column = self.__call__(content) | ||
columns.append(column) | ||
return columns | ||
|
||
def _table_cols_new(self, items) -> list[str]: # pragma: no cover | ||
columns = [] | ||
fn = self.__call__ | ||
for item in items: | ||
|
@@ -194,7 +205,20 @@ def _table_cols(self, items) -> list[str]: | |
columns.append(column) | ||
return columns | ||
|
||
def _table_body(self, items) -> list[list[str]]: | ||
def _table_body_old(self, items) -> list[list[str]]: | ||
body = [] | ||
for row_items in items: | ||
row = [] | ||
for col_row_item in row_items: | ||
if not col_row_item: | ||
content = "" | ||
else: | ||
content = col_row_item[0] | ||
row.append(self.__call__(content)) | ||
body.append(row) | ||
return body | ||
|
||
def _table_body_new(self, items) -> list[list[str]]: # pragma: no cover | ||
body = [] | ||
fn = self.__call__ | ||
for _, row_items in items: | ||
|
@@ -205,20 +229,34 @@ def _table_body(self, items) -> list[list[str]]: | |
body.append(row) | ||
return body | ||
|
||
def _table(self, item) -> str: | ||
def _table_old(self, item) -> tuple[list[str], list[list[str]]]: | ||
# pandoc < 2.10 | ||
_, _, _, thead, tbody = item | ||
columns = self._table_cols_old(thead) | ||
body = self._table_body_old(tbody) | ||
return columns, body | ||
|
||
def _table_new(self, item) -> tuple[list[str], list[list[str]]]: # pragma: no cover | ||
# pandoc >= 2.10 | ||
# attr capt specs thead tbody tfoot | ||
_, _, _, thead, tbody, _ = item | ||
|
||
# header | ||
(_, thead_bodies) = thead | ||
(attr, thead_body) = thead_bodies[0] # multiple headers? | ||
|
||
columns = self._table_cols(thead_body) | ||
|
||
columns = self._table_cols_new(thead_body) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have expected these lines to be covered. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the table change actually happens after 2.9, not 2.5 as I first suspected. Therefore, given that we now install pandoc via apt on CI, which uses 2.9, the old table implementation is covered, not the new one. I thus moved around the pragmas to the new implementation. |
||
# rows | ||
# attr rhc hd bd | ||
_, _, _, trows = tbody[0] # multiple groups of rows? | ||
body = self._table_body(trows) | ||
body = self._table_body_new(trows) | ||
return columns, body | ||
|
||
def _table(self, item) -> str: | ||
if len(item) == 6: # pragma: no cover | ||
# pandoc >= 2.5 | ||
columns, body = self._table_new(item) | ||
else: | ||
# pandoc < 2.5 | ||
columns, body = self._table_old(item) | ||
|
||
table: Mapping[str, Sequence[Any]] | ||
if not body: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woohoo :D