diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 7920721e..513ce6d1 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -63,7 +63,7 @@ jobs: else pip install "scikit-learn~=${{ matrix.sklearn_version }}"; fi if [ ${{ matrix.os }} == "ubuntu-latest" ]; - then wget -q https://github.com/jgm/pandoc/releases/download/2.19.2/pandoc-2.19.2-1-amd64.deb && sudo dpkg -i pandoc-2.19.2-1-amd64.deb; + then sudo apt install pandoc && pandoc --version; fi python --version pip --version diff --git a/skops/card/_markup.py b/skops/card/_markup.py index 7779a675..32f94b36 100644 --- a/skops/card/_markup.py +++ b/skops/card/_markup.py @@ -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) # 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: diff --git a/skops/card/_parser.py b/skops/card/_parser.py index 86d4f120..06fbc29f 100644 --- a/skops/card/_parser.py +++ b/skops/card/_parser.py @@ -22,7 +22,7 @@ from ._markup import Markdown, PandocItem -PANDOC_MIN_VERSION = "2.9.0" +PANDOC_MIN_VERSION = "2.0" class PandocParser: diff --git a/skops/card/tests/examples/toy-example.md b/skops/card/tests/examples/toy-example.md index 44669f11..a4762972 100644 --- a/skops/card/tests/examples/toy-example.md +++ b/skops/card/tests/examples/toy-example.md @@ -180,3 +180,8 @@ The "id" tag may change in order
Divs are possible
Divs are possible