From 4b08d3190ee569e01512bf3596d7b446d17b5f98 Mon Sep 17 00:00:00 2001 From: ntno Date: Wed, 18 Jan 2023 23:22:56 -0500 Subject: [PATCH 01/12] clean up and flake8 --- terminal/plugins/md_to_html/plugin.py | 66 ++++++++++++--------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/terminal/plugins/md_to_html/plugin.py b/terminal/plugins/md_to_html/plugin.py index a42ea2a8..fbf8aabf 100644 --- a/terminal/plugins/md_to_html/plugin.py +++ b/terminal/plugins/md_to_html/plugin.py @@ -1,50 +1,44 @@ -# Copyright (c) 2018 Byrne Reese -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -# import os -# import sys -# import re -# from timeit import default_timer as timer -# from datetime import datetime, timedelta -# from mkdocs import utils as mkdocs_utils -# from mkdocs.config import config_options, Config from mkdocs.plugins import BasePlugin -import jinja2 -# from jinja2.ext import Extension +from mkdocs.commands.build import DuplicateFilter +from mkdocs.config import config_options +from jinja2.utils import markupsafe import markdown +import logging +DEFAULT_MARKUP_FILTER_NAME = "markup" class MarkdownToHtmlFilterPlugin(BasePlugin): config_scheme = ( + ('filter-name', config_options.Type(str, default=DEFAULT_MARKUP_FILTER_NAME)), ) def __init__(self): - self.enabled = True - self.dirs = [] + self.md = None - def md_filter(self, text, **kwargs): - md = markdown.Markdown( - extensions=self.config['markdown_extensions'], - extension_configs=self.config['mdx_configs'] or {} + def setup_markdown(self, config): + self.md = markdown.Markdown( + extensions=config.markdown_extensions or [], + extension_configs=config.mdx_configs or {} ) - return jinja2.Markup(md.convert(text)) - def on_env(self, env, config, files): - self.config = config - env.filters['markdown'] = self.md_filter + def on_pre_build(self, config): + logger.info("MarkdownToHtmlFilterPlugin::on_pre_build::markdown_extensions: %s", config.markdown_extensions) + logger.info("MarkdownToHtmlFilterPlugin::on_pre_build::mdx_configs': %s", config.mdx_configs) + self.setup_markdown(config) + logger.info("MarkdownToHtmlFilterPlugin::on_pre_build::md: %s", self.md) + return + + def markupsafe_jinja2_filter(self, text, **kwargs): + return markupsafe.Markup(self.md.convert(text)) + + def on_env(self, env, config, files, **kwargs): + env.filters[config["filter-name"]] = self.markupsafe_jinja2_filter + logger.warning("TileGridPlugin::on_env::%s: %s", config["filter-name"], self.markupsafe_jinja2_filter) + self.env = env return env + + +# Set up logging +logger = logging.getLogger("mkdocs") +logger.addFilter(DuplicateFilter()) From ee8425ba4c66a2e77729061e951e9af80f80f744 Mon Sep 17 00:00:00 2001 From: ntno Date: Wed, 18 Jan 2023 23:27:20 -0500 Subject: [PATCH 02/12] wip testing --- terminal/macros/tile-grid/tile.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminal/macros/tile-grid/tile.j2 b/terminal/macros/tile-grid/tile.j2 index c5a49ae1..4aadd9c9 100644 --- a/terminal/macros/tile-grid/tile.j2 +++ b/terminal/macros/tile-grid/tile.j2 @@ -27,7 +27,7 @@ {% else %}{{ tile.link_text|default(tile.link_href, true) }}{%- endif -%} {%- endif -%} {%- if ns.has_caption %} -
{{ tile.caption|string|trim }}
+
{{ tile.caption|string|trim|markup }}
{%- endif %} From 89af55af50c5a03b6e3c2f2338bc2aa48f1c7573 Mon Sep 17 00:00:00 2001 From: ntno Date: Wed, 18 Jan 2023 23:33:54 -0500 Subject: [PATCH 03/12] bump --- package-lock.json | 4 ++-- package.json | 4 ++-- terminal/theme_version.html | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9dbc10d1..c48c7e44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "mkdocs-terminal", - "version": "3.2.1", + "version": "3.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -68,4 +68,4 @@ } } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index ebca1f04..0b0b3f07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mkdocs-terminal", - "version": "3.2.1", + "version": "3.3.0", "description": "Terminal.css theme for MkDocs", "keywords": [ "mkdocs", @@ -25,4 +25,4 @@ "engines": { "node": ">= 16" } -} +} \ No newline at end of file diff --git a/terminal/theme_version.html b/terminal/theme_version.html index 08dada68..5ad627b9 100644 --- a/terminal/theme_version.html +++ b/terminal/theme_version.html @@ -1 +1 @@ - + \ No newline at end of file From 7d749e48e2f32bfdafccbf00e0103b3162f1de88 Mon Sep 17 00:00:00 2001 From: ntno Date: Wed, 18 Jan 2023 23:34:09 -0500 Subject: [PATCH 04/12] simplify --- terminal/plugins/md_to_html/plugin.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/terminal/plugins/md_to_html/plugin.py b/terminal/plugins/md_to_html/plugin.py index fbf8aabf..9979dc64 100644 --- a/terminal/plugins/md_to_html/plugin.py +++ b/terminal/plugins/md_to_html/plugin.py @@ -9,10 +9,6 @@ class MarkdownToHtmlFilterPlugin(BasePlugin): - config_scheme = ( - ('filter-name', config_options.Type(str, default=DEFAULT_MARKUP_FILTER_NAME)), - ) - def __init__(self): self.md = None @@ -33,8 +29,8 @@ def markupsafe_jinja2_filter(self, text, **kwargs): return markupsafe.Markup(self.md.convert(text)) def on_env(self, env, config, files, **kwargs): - env.filters[config["filter-name"]] = self.markupsafe_jinja2_filter - logger.warning("TileGridPlugin::on_env::%s: %s", config["filter-name"], self.markupsafe_jinja2_filter) + env.filters[DEFAULT_MARKUP_FILTER_NAME] = self.markupsafe_jinja2_filter + logger.warning("TileGridPlugin::on_env::%s: %s", DEFAULT_MARKUP_FILTER_NAME, self.markupsafe_jinja2_filter) self.env = env return env From c62716ac2362e45a8a0a7bc6312bc966b2c9f09e Mon Sep 17 00:00:00 2001 From: ntno Date: Wed, 18 Jan 2023 23:34:26 -0500 Subject: [PATCH 05/12] build local theme and install before running server --- Makefile | 6 +++++- docker-compose.yml | 19 ++++++++++++++----- documentation/Makefile | 7 ++++--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 315c6f50..020e958b 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ serve-docs: docker compose run --entrypoint "/bin/bash" --service-ports local_documentation_server -c "make serve-mkdocs" serve-local-theme: - docker compose run --entrypoint "/bin/bash" --service-ports local_documentation_server -c "make serve-local" + docker compose run --entrypoint "/bin/bash" --service-ports local_theme_server -c "make build-local-theme-and-serve" ######################################################### @@ -75,6 +75,10 @@ install-from-dist: build-theme pip uninstall mkdocs-terminal pip install dist/*.tar.gz +build-local-theme-and-serve: install-from-dist + cd documentation && \ + $(MAKE) serve-local + #for developer use, assumes you have already installed prereqs quick-tests: flake8 --ignore E501 && \ diff --git a/docker-compose.yml b/docker-compose.yml index 18896da0..201f624b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: ubuntu: image: ntno/ubuntu-build-base:1.0.0 - restart: "no" + restart: "no" volumes: - $PWD:/usr/src local_examples_server: @@ -11,7 +11,7 @@ services: ports: - "5000:5000" environment: - LOG_LEVEL: info + LOG_LEVEL: info volumes: - './:/usr/src/' working_dir: '/usr/src/tests/examples/' @@ -21,7 +21,16 @@ services: ports: - "8080:8080" environment: - LOG_LEVEL: debug + LOG_LEVEL: debug + volumes: + - './:/usr/src/' + working_dir: '/usr/src/documentation' + local_theme_server: + image: ntno/ubuntu-build-base:1.0.0 + restart: "no" + ports: + - "8080:8080" + environment: + LOG_LEVEL: debug volumes: - - './:/usr/src/' - working_dir: '/usr/src/documentation' \ No newline at end of file + - './:/usr/src/' \ No newline at end of file diff --git a/documentation/Makefile b/documentation/Makefile index c3477730..cca2eba6 100644 --- a/documentation/Makefile +++ b/documentation/Makefile @@ -11,12 +11,13 @@ install-mkdocs-requirements: upgrade-pip build-mkdocs: clean install-mkdocs-requirements mkdocs build -v -serve-local: build-mkdocs - mkdocs serve -v --dev-addr=0.0.0.0:8080 -f local.yml - serve-mkdocs: build-mkdocs mkdocs serve -v --dev-addr=0.0.0.0:8080 +serve-local: clean install-mkdocs-requirements + mkdocs build -v -f local.yml + mkdocs serve -v --dev-addr=0.0.0.0:8080 -f local.yml + clean: rm -rf site/ From 0aa22d9bec5b8a4ff100045f50bbb0827bd0cd3e Mon Sep 17 00:00:00 2001 From: ntno Date: Wed, 18 Jan 2023 23:35:51 -0500 Subject: [PATCH 06/12] run local server with plugin installed --- documentation/local.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/documentation/local.yml b/documentation/local.yml index b853617c..a25c2a9a 100644 --- a/documentation/local.yml +++ b/documentation/local.yml @@ -16,6 +16,7 @@ theme: - 404.html plugins: + - terminal/md-to-html - git-revision-date - search From 7fc488fbaf35d48e82c46470b7fc41c2d3297da0 Mon Sep 17 00:00:00 2001 From: ntno Date: Wed, 18 Jan 2023 23:38:14 -0500 Subject: [PATCH 07/12] fix images links --- documentation/docs/about/debug.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/documentation/docs/about/debug.md b/documentation/docs/about/debug.md index e51833e6..5c5f369d 100644 --- a/documentation/docs/about/debug.md +++ b/documentation/docs/about/debug.md @@ -1,17 +1,17 @@ --- tiles: - caption: '*@petradr*' - img_src: ../../../img/picsum/167_200x200.jpeg + img_src: ../../img/picsum/167_200x200.jpeg img_title: 'to Picsum homepage' img_alt: 'close up image of fallen leaves' link_href: https://picsum.photos/ - caption: 'Marcin **C**zerwinski' - img_src: ../../../img/picsum/127_200x200.jpeg + img_src: ../../img/picsum/127_200x200.jpeg img_title: 'to Picsum homepage' img_alt: 'close up image of green moss on a log' link_href: https://picsum.photos/ - caption: 'Steve Richey' - img_src: ../../../img/picsum/143_200x200.jpeg + img_src: ../../img/picsum/143_200x200.jpeg img_title: 'to Picsum homepage' img_alt: 'overhead image of fallen leaves' link_href: https://picsum.photos/ From 3ae1d17c4b8cd3a88ac707303c37b36e7803a139 Mon Sep 17 00:00:00 2001 From: ntno Date: Wed, 18 Jan 2023 23:40:13 -0500 Subject: [PATCH 08/12] pass link to markup --- documentation/docs/about/debug.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/docs/about/debug.md b/documentation/docs/about/debug.md index 5c5f369d..feb2d483 100644 --- a/documentation/docs/about/debug.md +++ b/documentation/docs/about/debug.md @@ -10,7 +10,7 @@ tiles: img_title: 'to Picsum homepage' img_alt: 'close up image of green moss on a log' link_href: https://picsum.photos/ - - caption: 'Steve Richey' + - caption: "[Steve Richey](https://picsum.photos/)" img_src: ../../img/picsum/143_200x200.jpeg img_title: 'to Picsum homepage' img_alt: 'overhead image of fallen leaves' From 1c5ae038a0cd9bc315fc7453ffdb69bb94d3bb8b Mon Sep 17 00:00:00 2001 From: ntno Date: Wed, 18 Jan 2023 23:41:16 -0500 Subject: [PATCH 09/12] flake8 fix --- terminal/plugins/md_to_html/plugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/terminal/plugins/md_to_html/plugin.py b/terminal/plugins/md_to_html/plugin.py index 9979dc64..614bf172 100644 --- a/terminal/plugins/md_to_html/plugin.py +++ b/terminal/plugins/md_to_html/plugin.py @@ -1,6 +1,5 @@ from mkdocs.plugins import BasePlugin from mkdocs.commands.build import DuplicateFilter -from mkdocs.config import config_options from jinja2.utils import markupsafe import markdown import logging From 131bf56f31927b6275183333fc92fe01a945ba07 Mon Sep 17 00:00:00 2001 From: ntno Date: Wed, 18 Jan 2023 23:42:45 -0500 Subject: [PATCH 10/12] remove markup test for now --- terminal/macros/tile-grid/tile.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminal/macros/tile-grid/tile.j2 b/terminal/macros/tile-grid/tile.j2 index 4aadd9c9..c5a49ae1 100644 --- a/terminal/macros/tile-grid/tile.j2 +++ b/terminal/macros/tile-grid/tile.j2 @@ -27,7 +27,7 @@ {% else %}{{ tile.link_text|default(tile.link_href, true) }}{%- endif -%} {%- endif -%} {%- if ns.has_caption %} -
{{ tile.caption|string|trim|markup }}
+
{{ tile.caption|string|trim }}
{%- endif %} From 0843aad68708ed50e343ab656597485d63dee088 Mon Sep 17 00:00:00 2001 From: ntno Date: Wed, 18 Jan 2023 23:46:40 -0500 Subject: [PATCH 11/12] allow future arguments --- terminal/plugins/md_to_html/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminal/plugins/md_to_html/plugin.py b/terminal/plugins/md_to_html/plugin.py index 614bf172..7d1029f9 100644 --- a/terminal/plugins/md_to_html/plugin.py +++ b/terminal/plugins/md_to_html/plugin.py @@ -17,7 +17,7 @@ def setup_markdown(self, config): extension_configs=config.mdx_configs or {} ) - def on_pre_build(self, config): + def on_pre_build(self, config, **kwargs): logger.info("MarkdownToHtmlFilterPlugin::on_pre_build::markdown_extensions: %s", config.markdown_extensions) logger.info("MarkdownToHtmlFilterPlugin::on_pre_build::mdx_configs': %s", config.mdx_configs) self.setup_markdown(config) From 3a873d993ccc4a6e2d3a7f42fb38a9a0b79ecda0 Mon Sep 17 00:00:00 2001 From: ntno Date: Wed, 18 Jan 2023 23:50:53 -0500 Subject: [PATCH 12/12] update logging --- terminal/plugins/md_to_html/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminal/plugins/md_to_html/plugin.py b/terminal/plugins/md_to_html/plugin.py index 7d1029f9..68f37458 100644 --- a/terminal/plugins/md_to_html/plugin.py +++ b/terminal/plugins/md_to_html/plugin.py @@ -29,7 +29,7 @@ def markupsafe_jinja2_filter(self, text, **kwargs): def on_env(self, env, config, files, **kwargs): env.filters[DEFAULT_MARKUP_FILTER_NAME] = self.markupsafe_jinja2_filter - logger.warning("TileGridPlugin::on_env::%s: %s", DEFAULT_MARKUP_FILTER_NAME, self.markupsafe_jinja2_filter) + logger.info("MarkdownToHtmlFilterPlugin::on_env::%s: %s", DEFAULT_MARKUP_FILTER_NAME, self.markupsafe_jinja2_filter) self.env = env return env