From bc0bd84d087e994baf00ba985f91f0c88db9fce9 Mon Sep 17 00:00:00 2001 From: Steve Phelps Date: Mon, 18 Nov 2019 18:02:01 +0000 Subject: [PATCH 1/8] specify initial section numbering via notebook metadata toc.base_numbering as set by the toc2 notebook plugin. --- ipypublish/preprocessors/slides_from_markdown.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ipypublish/preprocessors/slides_from_markdown.py b/ipypublish/preprocessors/slides_from_markdown.py index c20c436..b0ddd18 100644 --- a/ipypublish/preprocessors/slides_from_markdown.py +++ b/ipypublish/preprocessors/slides_from_markdown.py @@ -151,6 +151,8 @@ class MarkdownSlides(Preprocessor): """ + #header_levels = [4] + column_level = traits.Integer( 1, min=0, help="maximum header level for new columns (0 indicates no maximum)" ).tag(config=True) @@ -174,8 +176,14 @@ def preprocess(self, nb, resources): latexdoc_tags = ["code", "error", "table", "equation", "figure", "text"] # break up titles cells_in_slide = 0 - header_levels = [] final_cells = FinalCells(self.header_slide) + + base_numbering = nb.metadata.toc.base_numbering + if base_numbering is not None: + header_levels = list(map(lambda x: int(x) - 1, base_numbering.split("."))) + else: + header_levels = [] + for i, cell in enumerate(nb.cells): # Make sure every cell has an ipub meta tag From a94569c90adbb2ae7c04906f495a68817fbe78c1 Mon Sep 17 00:00:00 2001 From: Steve Phelps Date: Mon, 18 Nov 2019 18:04:21 +0000 Subject: [PATCH 2/8] removed commented out code --- ipypublish/preprocessors/slides_from_markdown.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ipypublish/preprocessors/slides_from_markdown.py b/ipypublish/preprocessors/slides_from_markdown.py index b0ddd18..b59493c 100644 --- a/ipypublish/preprocessors/slides_from_markdown.py +++ b/ipypublish/preprocessors/slides_from_markdown.py @@ -151,8 +151,6 @@ class MarkdownSlides(Preprocessor): """ - #header_levels = [4] - column_level = traits.Integer( 1, min=0, help="maximum header level for new columns (0 indicates no maximum)" ).tag(config=True) From a188cee5ac23b1723f913cbdd294e8239802f467 Mon Sep 17 00:00:00 2001 From: Steve Phelps Date: Tue, 19 Nov 2019 09:47:42 +0000 Subject: [PATCH 3/8] added error checking and logging when validating toc.base_numbering --- ipypublish/preprocessors/slides_from_markdown.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ipypublish/preprocessors/slides_from_markdown.py b/ipypublish/preprocessors/slides_from_markdown.py index b59493c..7240945 100644 --- a/ipypublish/preprocessors/slides_from_markdown.py +++ b/ipypublish/preprocessors/slides_from_markdown.py @@ -176,11 +176,17 @@ def preprocess(self, nb, resources): cells_in_slide = 0 final_cells = FinalCells(self.header_slide) - base_numbering = nb.metadata.toc.base_numbering - if base_numbering is not None: - header_levels = list(map(lambda x: int(x) - 1, base_numbering.split("."))) - else: - header_levels = [] + header_levels = [] + if nb.metadata.toc is not None: + base_numbering = nb.metadata.toc.base_numbering + if base_numbering is not None: + try: + header_levels = list(map(lambda x: int(x), base_numbering.split("."))) + header_levels[0] -= 1 + logging.debug("base_numbering = " + base_numbering) + logging.debug("header_levels = " + str(header_levels)) + except ValueError: + logger.warn("Invalid toc.base_numbering in notebook metadata") for i, cell in enumerate(nb.cells): From 89e3053c1843ed8f4eba964ddb910d868c16a418 Mon Sep 17 00:00:00 2001 From: phelps-sg Date: Tue, 19 Nov 2019 11:18:43 +0000 Subject: [PATCH 4/8] Fixed logging and metadata error handling, as per the changes requested for review of {chrissewell}{ipypublish}#113 --- .../preprocessors/slides_from_markdown.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ipypublish/preprocessors/slides_from_markdown.py b/ipypublish/preprocessors/slides_from_markdown.py index 7240945..0d58ea0 100644 --- a/ipypublish/preprocessors/slides_from_markdown.py +++ b/ipypublish/preprocessors/slides_from_markdown.py @@ -177,16 +177,16 @@ def preprocess(self, nb, resources): final_cells = FinalCells(self.header_slide) header_levels = [] - if nb.metadata.toc is not None: + try: base_numbering = nb.metadata.toc.base_numbering - if base_numbering is not None: - try: - header_levels = list(map(lambda x: int(x), base_numbering.split("."))) - header_levels[0] -= 1 - logging.debug("base_numbering = " + base_numbering) - logging.debug("header_levels = " + str(header_levels)) - except ValueError: - logger.warn("Invalid toc.base_numbering in notebook metadata") + header_levels = list(map(lambda x: int(x), base_numbering.split("."))) + header_levels[0] -= 1 + logging.debug("base_numbering = " + base_numbering) + logging.debug("header_levels = " + str(header_levels)) + except ValueError: + logging.warning("Invalid toc.base_numbering in notebook metadata") + except AttributeError: + logging.debug("No toc.base_numbering in notebook metadata; starting at 1") for i, cell in enumerate(nb.cells): From 7cef5c28b109aab9e9e544b341e46c30c8d960d3 Mon Sep 17 00:00:00 2001 From: phelps-sg Date: Tue, 19 Nov 2019 11:54:24 +0000 Subject: [PATCH 5/8] Documented toc.base_numbering, following review of {chrissewell}{ipypublish}#113 --- docs/source/metadata_tags.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/source/metadata_tags.rst b/docs/source/metadata_tags.rst index bf75004..f7c9815 100644 --- a/docs/source/metadata_tags.rst +++ b/docs/source/metadata_tags.rst @@ -499,6 +499,25 @@ For **slide output**: - the value of slide can be true, “new” (to indicate the start of a new slide) or “notes” +Specifying the start section number in slide-shows +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +For **slide output**: + +.. code:: json + + { + "toc": { + "base_numbering": "3", + } + } + +- the above will set the first section number to 3 rather than 1 + +- note that the top-level key is "toc", and *not* "ipub"; this allows + the starting section number to be configured using the + `toc2 notebook extension `__ + Captions in a Markdown cell ~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 98fad88800add4fa4e0454d77cfc0d58d67e1388 Mon Sep 17 00:00:00 2001 From: phelps-sg Date: Wed, 20 Nov 2019 10:52:28 +0000 Subject: [PATCH 6/8] removed check for absolute filepath --- ipypublish/postprocessors/base.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ipypublish/postprocessors/base.py b/ipypublish/postprocessors/base.py index ef1db85..f719d0c 100644 --- a/ipypublish/postprocessors/base.py +++ b/ipypublish/postprocessors/base.py @@ -116,11 +116,6 @@ def postprocess(self, stream, mimetype, filepath, resources=None): if self.requires_path: - if not filepath.is_absolute(): - self.handle_error( - "the post-processor requires an absolute folder path", IOError - ) - if filepath.parent.exists() and not filepath.parent.is_dir(): self.handle_error( "the filepath's parent is not a folder: {}".format(filepath), From afdd826ed7a463b96d27f2cd097c005b1da91ab0 Mon Sep 17 00:00:00 2001 From: Steve Phelps Date: Sat, 23 Nov 2019 16:07:19 +0000 Subject: [PATCH 7/8] Allow custom stylesheet to be added to slideshow via ipub.customcss notebook metadata --- ipypublish/schema/doc_metadata.schema.json | 3 +++ ipypublish/templates/segments/std-slides.html-tplx.json | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/ipypublish/schema/doc_metadata.schema.json b/ipypublish/schema/doc_metadata.schema.json index 8316370..178e9d2 100644 --- a/ipypublish/schema/doc_metadata.schema.json +++ b/ipypublish/schema/doc_metadata.schema.json @@ -12,6 +12,9 @@ "type": "string", "default": "english" }, + "customcss": { + "description": "additional custom stylesheet to link" + }, "titlepage": { "description": "options for creating the title page", "type": [ diff --git a/ipypublish/templates/segments/std-slides.html-tplx.json b/ipypublish/templates/segments/std-slides.html-tplx.json index 1c5a9ca..7126ca2 100644 --- a/ipypublish/templates/segments/std-slides.html-tplx.json +++ b/ipypublish/templates/segments/std-slides.html-tplx.json @@ -39,6 +39,12 @@ "", "", "", + "{%- if nb.metadata.ipub -%}", + "{%- if nb.metadata.ipub.customcss -%}", + "", + "", + "{% endif %}", + "{% endif %}", "", "", "", From 45e1611693927ba0c2d5c3b4b86a6bf096ff716d Mon Sep 17 00:00:00 2001 From: Steve Phelps Date: Thu, 28 Nov 2019 14:07:40 +0000 Subject: [PATCH 8/8] preprocessor added to filter all cells with metadata ipub.ignore==true --- ipypublish/preprocessors/skip_ignored.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 ipypublish/preprocessors/skip_ignored.py diff --git a/ipypublish/preprocessors/skip_ignored.py b/ipypublish/preprocessors/skip_ignored.py new file mode 100644 index 0000000..ad53380 --- /dev/null +++ b/ipypublish/preprocessors/skip_ignored.py @@ -0,0 +1,14 @@ +from nbconvert.preprocessors import Preprocessor +from nbformat import NotebookNode + + +class SkipIgnored(Preprocessor): + + def preprocess(self, nb, resources): + + def included(cell): + cell.metadata.ipub = cell.metadata.get("ipub", NotebookNode()) + return not cell.metadata.ipub.get("ignore", False) + + nb.cells = list(filter(included, nb.cells)) + return nb, resources \ No newline at end of file