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

clean up experimental plugin and add logging #85

Merged
merged 12 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"


#########################################################
Expand Down Expand Up @@ -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 && \
Expand Down
19 changes: 14 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -11,7 +11,7 @@ services:
ports:
- "5000:5000"
environment:
LOG_LEVEL: info
LOG_LEVEL: info
volumes:
- './:/usr/src/'
working_dir: '/usr/src/tests/examples/'
Expand All @@ -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'
- './:/usr/src/'
7 changes: 4 additions & 3 deletions documentation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
8 changes: 4 additions & 4 deletions documentation/docs/about/debug.md
Original file line number Diff line number Diff line change
@@ -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
- 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'
link_href: https://picsum.photos/
Expand Down
1 change: 1 addition & 0 deletions documentation/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ theme:
- 404.html

plugins:
- terminal/md-to-html
- git-revision-date
- search

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mkdocs-terminal",
"version": "3.2.1",
"version": "3.3.0",
"description": "Terminal.css theme for MkDocs",
"keywords": [
"mkdocs",
Expand All @@ -25,4 +25,4 @@
"engines": {
"node": ">= 16"
}
}
}
67 changes: 28 additions & 39 deletions terminal/plugins/md_to_html/plugin.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,39 @@
# 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 jinja2.utils import markupsafe
import markdown
import logging
DEFAULT_MARKUP_FILTER_NAME = "markup"


class MarkdownToHtmlFilterPlugin(BasePlugin):

config_scheme = (
)

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, **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)
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[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


# Set up logging
logger = logging.getLogger("mkdocs")
logger.addFilter(DuplicateFilter())
2 changes: 1 addition & 1 deletion terminal/theme_version.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<meta name="generator" content="mkdocs-{{ mkdocs_version }}, mkdocs-terminal-3.2.1">
<meta name="generator" content="mkdocs-{{ mkdocs_version }}, mkdocs-terminal-3.3.0">