chore: Update to mkdocs-simple v2.1.2

Note the upstream refactor from mkdocs-simple v1 -> v2 was fairly large, so
  this is a rather larger update than most. And in fact one feature of
  mkdocs-semiliterate (universal markdown extraction) was incorporated into
  mkdocs-simple, so the initialization of this plugin is noticeably simplified
  as a result.

  Also updates mkdocs to 1.4.
This commit is contained in:
Glen Whitney 2022-11-09 14:09:44 -05:00
parent 3b97489374
commit 861ba98942
11 changed files with 208 additions and 139 deletions

View File

@ -8,6 +8,7 @@ plugins:
- semiliterate:
merge_docs_dir: false
ignore_folders: [build, dist, tests, semiliterate]
ignore_hidden: false
include_extensions: [LICENSE, '.png']
extract_standard_markdown:
extract:

View File

@ -13,7 +13,9 @@ of the `simple` plugin.)
from mkdocs import utils
from mkdocs.config import config_options
from mkdocs_simple_plugin.semiliterate import (
Semiliterate, LazyFile, ExtractionPattern, StreamExtract, get_line)
Semiliterate, LazyFile, ExtractionPattern, StreamExtract,
get_line, get_match)
from mkdocs_simple_plugin.simple import Simple
from mkdocs_simple_plugin.plugin import SimplePlugin
import os
@ -32,6 +34,15 @@ to replace_line method.
# except as marked:
def replace_line(self, line, ensure_line=True):
"""Apply the specified replacements to the line and return it."""
# Process trimming
if self._trim:
line = line[self._trim:]
# Process inline content regex
if self._content:
match_object = get_match(self._content, line)
if match_object.lastindex:
return match_object[match_object.lastindex]
# Perform replace operations:
if not self.replace:
return line
for item in self.replace:
@ -270,19 +281,17 @@ anticipated by the `{%- block ... %}` directives placed by the theme writer.
self.wrote_something = True
self.transcribe(remainder[body_match.end():])
# ## The following has to be identical to StreamExtract.check_pattern
# ## The following has to be identical to StreamExtract.try_extract_match
# ## except for the marked bit handling ensure_lines
def check_pattern(self, pattern, line, emit_last=True):
"""Check if pattern is contained in line.
def try_extract_match(
self,
match_object: re.Match,
emit_last: bool = True) -> bool:
"""Extract match into output.
If _pattern_ is not false-y and is contained in _line_,
returns true (and if the _emit_last_ flag is true,
emits the last group of the match if any). Otherwise,
check_pattern does nothing but return false.
If _match_object_ is not false-y, returns true.
If extract flag is true, emits the last group of the match if any.
"""
if not pattern:
return False
match_object = pattern.search(line)
if not match_object:
return False
if match_object.lastindex and emit_last:
@ -297,24 +306,6 @@ anticipated by the `{%- block ... %}` directives placed by the theme writer.
class SemiliteratePlugin(SimplePlugin):
r""" md An extension of the mkdocs-simple-plugin
### Universal block-comment markdown
By default, `semiliterate` scans for block-comment markdown `/** md` ... `**/`
in all files with _any_ extension, as it's valid in so many disparate languages.
(As opposed to `simple`, which defaults to searching for such markdown in a
specific list of file types.)
"""
super_sdict = dict(SimplePlugin.config_scheme)
super_semi_dflt = super_sdict['semiliterate'].default
semi_dflt = [b if 'js' not in b['pattern'] else dict(b, pattern=r'\.')
for b in super_semi_dflt]
altered_config_scheme = dict(
super_sdict,
semiliterate=config_options.Type(list, default=semi_dflt)).items()
add_param_doc = r""" md
### Additional plugin parameters
`semiliterate` adds a couple of new plugin parameters to further tailor its
@ -322,7 +313,7 @@ behavior as compared to `simple`. They are described in this section, with
default values in parentheses at the beginning of each entry.
{! plugin.py extract:
start: '[*]altered_config_scheme'
start: '[*]super_config_scheme'
replace:
- ["\\('(.*)',\\s*$", '\1\n']
- ['config_options.Type.*?default=([^\)]*)', ': (\1)']
@ -334,9 +325,10 @@ terminate: '^\s*\)'
stop: '["]{3}'
!}
"""
super_config_scheme = SimplePlugin.config_scheme
config_scheme = (
# Note documentation of each new parameter **follows** the parameter.
*altered_config_scheme,
*super_config_scheme,
('exclude_extensions',
config_options.Type(list, default=['.o'])),
# Files whose name contains a string in this list will not be
@ -372,25 +364,6 @@ terminate: '^\s*\)'
)
def on_config(self, config, **kwargs):
# Since we have extensions in Demiliterate, suppress the semiliterate
# configuration until we handle it ourselves:
semi = self.config['semiliterate']
self.config['semiliterate'] = []
new_config = super().on_config(config, **kwargs)
self.config['semiliterate'] = semi
self.semiliterate = [Demiliterate(**item) for item in semi]
self.exclude_extensions = self.config['exclude_extensions']
dflt_enable = False
if not self.config['copy_standard_markdown']:
self.include_extensions = self.config['include_extensions']
dflt_enable = True
if self.config['extract_standard_markdown'].get('enable', dflt_enable):
ext_pat = '|'.join(re.escape(s) for s in utils.markdown_extensions)
self.semiliterate.append(
Demiliterate(
pattern=re.compile(f"^(.*(?:{ext_pat}))$"),
destination=r'\1',
**self.config['extract_standard_markdown']))
r""" md
### Adjusting the mkdocs theme
@ -401,13 +374,17 @@ in the generated docs dir to the theme search path. (Note this means that
files in the corresponding subdirectory of your project will be copied into
the resulting doc site unless their names start with a '.')
"""
# Save the include extensions before SimplePlugin modifies them:
self.config['saved_includes'] = self.config['include_extensions']
new_config = super().on_config(config, **kwargs)
cfpath = os.path.dirname(config.config_file_path)
self.custom_dir = None
for themedir in config['theme'].dirs:
common = os.path.commonpath([cfpath, themedir])
if common == cfpath:
self.custom_dir = os.path.relpath(themedir, cfpath)
newthemedir = os.path.join(self.build_docs_dir, self.custom_dir)
newthemedir = os.path.join(
self.config['build_docs_dir'], self.custom_dir)
utils.log.debug(
'mkdocs-semiliterate: found theme.custom_dir = '
+ self.custom_dir
@ -427,17 +404,74 @@ the resulting doc site unless their names start with a '.')
+ f"from theme directory {self.custom_dir}")
files.remove(sources[path])
def in_extensions(self, file):
def on_pre_build(self, *, config):
"""Build documentation directory with files according to settings."""
semisimple = Semisimple(**self.config)
# Merge docs
if self.config["merge_docs_dir"]:
semisimple.merge_docs(self.orig_docs_dir)
# Copy all of the valid doc files into build_docs_dir
self.paths = semisimple.build_docs()
class Semisimple(Simple):
"""Mkdocs Semisimple Plugin"""
def __init__(self, semiliterate, exclude_extensions, saved_includes,
copy_standard_markdown, extract_standard_markdown,
extract_on_copy, **kwargs):
# Since we have extensions in Demiliterate, suppress the semiliterate
# configuration until we handle it ourselves:
super().__init__(semiliterate=[], **kwargs)
self.semiliterate = [Demiliterate(**item) for item in semiliterate]
self.exclude_extensions = exclude_extensions
self.extract_on_copy = extract_on_copy
dflt_enable = False
if not copy_standard_markdown:
self.copy_glob = set(saved_includes)
dflt_enable = True
if extract_standard_markdown.get('enable', dflt_enable):
ext_pat = '|'.join(re.escape(s) for s in utils.markdown_extensions)
self.semiliterate.append(
Demiliterate(
pattern=re.compile(f"^(.*(?:{ext_pat}))$"),
destination=r'\1',
**extract_standard_markdown))
def should_copy_file(self, file):
if any(ext in file for ext in self.exclude_extensions):
return False
return super().in_extensions(file)
return super().should_copy_file(file)
def extract_from(self, from_directory, name, to_directory):
def try_extract(self, from_directory, name, to_directory):
if any(ext in name for ext in self.exclude_extensions):
return False
if not self.config['extract_on_copy'] and self.in_extensions(name):
if not self.extract_on_copy and self.should_copy_file(name):
return False
return super().extract_from(from_directory, name, to_directory)
return super().try_extract(from_directory, name, to_directory)
# Had to override this because the simple version hardcoded that if a file
# was copied, it could not be extracted. So check carefully for changes in
# simple. Only the lines between # # START and # # END differ.
def build_docs(self) -> list:
"""Build the docs directory from workspace files."""
paths = []
files = self.get_files()
for file in files:
if not os.path.isfile(file):
continue
from_dir = os.path.dirname(file)
name = os.path.basename(file)
build_prefix = os.path.normpath(
os.path.join(self.build_dir, from_dir))
# # START
copied = self.try_copy_file(from_dir, name, build_prefix)
extracted = self.try_extract(from_dir, name, build_prefix)
if (copied or extracted):
paths.append(file)
# # END
return paths
class Demiliterate(Semiliterate):
@ -483,7 +517,7 @@ semiliterate.ensurelines
Returns True if extraction was successful.
"""
to_file = self.filenname_match(from_file)
to_file = self.filename_match(from_file)
if not to_file:
return False
from_file_path = os.path.join(from_directory, from_file)
@ -491,7 +525,9 @@ semiliterate.ensurelines
(destination_directory, to_file) = os.path.split(to_file_path) # ADDED
try:
with open(from_file_path) as original_file:
utils.log.debug(f"mkdocs-semiliterate: Scanning {from_file}...")
utils.log.debug(
f"mkdocs-semiliterate: In {from_directory}, "
+ f"scanning {from_file}...")
# extraction = StreamExtract(
extraction = StreamInclusion(
input_stream=original_file,
@ -502,6 +538,9 @@ semiliterate.ensurelines
patterns=self.patterns,
**kwargs)
return extraction.extract()
except (UnicodeDecodeError) as error:
utils.log.info("mkdocs-semiliterate: skipping %s\n %s",
from_file_path, str(error))
except BaseException as error:
utils.log.error(
f"mkdocs-semiliterate: could not build {from_file_path}:\n "

View File

@ -1,6 +1,6 @@
[metadata]
name = mkdocs-semiliterate
version = 0.6.0
version = 0.7.0
description = Extension of mkdocs-simple-plugin adding easy content inclusion
long_description = file: README.md
long_description_content_type = text/markdown
@ -24,8 +24,8 @@ license = Apache-2.0
[options]
packages = mkdocs_semiliterate
install_requires =
mkdocs~=1.3.1
mkdocs-simple-plugin~=1.0
mkdocs~=1.4
mkdocs-simple-plugin==2.1.2
[options.entry_points]
mkdocs.plugins =

View File

@ -215,7 +215,7 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
.admonition {
.admonition, details {
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
@ -223,29 +223,33 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
text-align: left;
}
.admonition.note { /* csslint allow: adjoining-classes */
color: #3a87ad;
background-color: #d9edf7;
.admonition.note, details.note { /* csslint allow: adjoining-classes */
color: #2e6b89;
background-color: #e2f0f7;
border-color: #bce8f1;
}
.admonition.warning { /* csslint allow: adjoining-classes */
color: #c09853;
background-color: #fcf8e3;
.admonition.warning, details.warning { /* csslint allow: adjoining-classes */
color: #7a6032;
background-color: #fffae5;
border-color: #fbeed5;
}
.admonition.danger { /* csslint allow: adjoining-classes */
color: #b94a48;
background-color: #f2dede;
.admonition.danger, details.danger { /* csslint allow: adjoining-classes */
color: #7f3130;
background-color: #fde3e3;
border-color: #eed3d7;
}
.admonition-title {
.admonition-title, summary {
font-weight: bold;
text-align: left;
}
.admonition>p:last-child, details>p:last-child {
margin-bottom: 0;
}
@media (max-width: 991.98px) {
.navbar-collapse.show { /* csslint allow: adjoining-classes */
overflow-y: auto;

View File

@ -215,7 +215,7 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
.admonition {
.admonition, details {
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
@ -223,29 +223,33 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
text-align: left;
}
.admonition.note { /* csslint allow: adjoining-classes */
color: #3a87ad;
background-color: #d9edf7;
.admonition.note, details.note { /* csslint allow: adjoining-classes */
color: #2e6b89;
background-color: #e2f0f7;
border-color: #bce8f1;
}
.admonition.warning { /* csslint allow: adjoining-classes */
color: #c09853;
background-color: #fcf8e3;
.admonition.warning, details.warning { /* csslint allow: adjoining-classes */
color: #7a6032;
background-color: #fffae5;
border-color: #fbeed5;
}
.admonition.danger { /* csslint allow: adjoining-classes */
color: #b94a48;
background-color: #f2dede;
.admonition.danger, details.danger { /* csslint allow: adjoining-classes */
color: #7f3130;
background-color: #fde3e3;
border-color: #eed3d7;
}
.admonition-title {
.admonition-title, summary {
font-weight: bold;
text-align: left;
}
.admonition>p:last-child, details>p:last-child {
margin-bottom: 0;
}
@media (max-width: 991.98px) {
.navbar-collapse.show { /* csslint allow: adjoining-classes */
overflow-y: auto;

View File

@ -215,7 +215,7 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
.admonition {
.admonition, details {
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
@ -223,29 +223,33 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
text-align: left;
}
.admonition.note { /* csslint allow: adjoining-classes */
color: #3a87ad;
background-color: #d9edf7;
.admonition.note, details.note { /* csslint allow: adjoining-classes */
color: #2e6b89;
background-color: #e2f0f7;
border-color: #bce8f1;
}
.admonition.warning { /* csslint allow: adjoining-classes */
color: #c09853;
background-color: #fcf8e3;
.admonition.warning, details.warning { /* csslint allow: adjoining-classes */
color: #7a6032;
background-color: #fffae5;
border-color: #fbeed5;
}
.admonition.danger { /* csslint allow: adjoining-classes */
color: #b94a48;
background-color: #f2dede;
.admonition.danger, details.danger { /* csslint allow: adjoining-classes */
color: #7f3130;
background-color: #fde3e3;
border-color: #eed3d7;
}
.admonition-title {
.admonition-title, summary {
font-weight: bold;
text-align: left;
}
.admonition>p:last-child, details>p:last-child {
margin-bottom: 0;
}
@media (max-width: 991.98px) {
.navbar-collapse.show { /* csslint allow: adjoining-classes */
overflow-y: auto;

View File

@ -215,7 +215,7 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
.admonition {
.admonition, details {
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
@ -223,29 +223,33 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
text-align: left;
}
.admonition.note { /* csslint allow: adjoining-classes */
color: #3a87ad;
background-color: #d9edf7;
.admonition.note, details.note { /* csslint allow: adjoining-classes */
color: #2e6b89;
background-color: #e2f0f7;
border-color: #bce8f1;
}
.admonition.warning { /* csslint allow: adjoining-classes */
color: #c09853;
background-color: #fcf8e3;
.admonition.warning, details.warning { /* csslint allow: adjoining-classes */
color: #7a6032;
background-color: #fffae5;
border-color: #fbeed5;
}
.admonition.danger { /* csslint allow: adjoining-classes */
color: #b94a48;
background-color: #f2dede;
.admonition.danger, details.danger { /* csslint allow: adjoining-classes */
color: #7f3130;
background-color: #fde3e3;
border-color: #eed3d7;
}
.admonition-title {
.admonition-title, summary {
font-weight: bold;
text-align: left;
}
.admonition>p:last-child, details>p:last-child {
margin-bottom: 0;
}
@media (max-width: 991.98px) {
.navbar-collapse.show { /* csslint allow: adjoining-classes */
overflow-y: auto;

View File

@ -215,7 +215,7 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
.admonition {
.admonition, details {
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
@ -223,29 +223,33 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
text-align: left;
}
.admonition.note { /* csslint allow: adjoining-classes */
color: #3a87ad;
background-color: #d9edf7;
.admonition.note, details.note { /* csslint allow: adjoining-classes */
color: #2e6b89;
background-color: #e2f0f7;
border-color: #bce8f1;
}
.admonition.warning { /* csslint allow: adjoining-classes */
color: #c09853;
background-color: #fcf8e3;
.admonition.warning, details.warning { /* csslint allow: adjoining-classes */
color: #7a6032;
background-color: #fffae5;
border-color: #fbeed5;
}
.admonition.danger { /* csslint allow: adjoining-classes */
color: #b94a48;
background-color: #f2dede;
.admonition.danger, details.danger { /* csslint allow: adjoining-classes */
color: #7f3130;
background-color: #fde3e3;
border-color: #eed3d7;
}
.admonition-title {
.admonition-title, summary {
font-weight: bold;
text-align: left;
}
.admonition>p:last-child, details>p:last-child {
margin-bottom: 0;
}
@media (max-width: 991.98px) {
.navbar-collapse.show { /* csslint allow: adjoining-classes */
overflow-y: auto;

View File

@ -215,7 +215,7 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
.admonition {
.admonition, details {
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
@ -223,29 +223,33 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
text-align: left;
}
.admonition.note { /* csslint allow: adjoining-classes */
color: #3a87ad;
background-color: #d9edf7;
.admonition.note, details.note { /* csslint allow: adjoining-classes */
color: #2e6b89;
background-color: #e2f0f7;
border-color: #bce8f1;
}
.admonition.warning { /* csslint allow: adjoining-classes */
color: #c09853;
background-color: #fcf8e3;
.admonition.warning, details.warning { /* csslint allow: adjoining-classes */
color: #7a6032;
background-color: #fffae5;
border-color: #fbeed5;
}
.admonition.danger { /* csslint allow: adjoining-classes */
color: #b94a48;
background-color: #f2dede;
.admonition.danger, details.danger { /* csslint allow: adjoining-classes */
color: #7f3130;
background-color: #fde3e3;
border-color: #eed3d7;
}
.admonition-title {
.admonition-title, summary {
font-weight: bold;
text-align: left;
}
.admonition>p:last-child, details>p:last-child {
margin-bottom: 0;
}
@media (max-width: 991.98px) {
.navbar-collapse.show { /* csslint allow: adjoining-classes */
overflow-y: auto;

View File

@ -215,7 +215,7 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
.admonition {
.admonition, details {
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
@ -223,29 +223,33 @@ h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, h4:hover .head
text-align: left;
}
.admonition.note { /* csslint allow: adjoining-classes */
color: #3a87ad;
background-color: #d9edf7;
.admonition.note, details.note { /* csslint allow: adjoining-classes */
color: #2e6b89;
background-color: #e2f0f7;
border-color: #bce8f1;
}
.admonition.warning { /* csslint allow: adjoining-classes */
color: #c09853;
background-color: #fcf8e3;
.admonition.warning, details.warning { /* csslint allow: adjoining-classes */
color: #7a6032;
background-color: #fffae5;
border-color: #fbeed5;
}
.admonition.danger { /* csslint allow: adjoining-classes */
color: #b94a48;
background-color: #f2dede;
.admonition.danger, details.danger { /* csslint allow: adjoining-classes */
color: #7f3130;
background-color: #fde3e3;
border-color: #eed3d7;
}
.admonition-title {
.admonition-title, summary {
font-weight: bold;
text-align: left;
}
.admonition>p:last-child, details>p:last-child {
margin-bottom: 0;
}
@media (max-width: 991.98px) {
.navbar-collapse.show { /* csslint allow: adjoining-classes */
overflow-y: auto;

View File

@ -5,7 +5,8 @@ theme:
custom_dir: doc_theme/
plugins:
- semiliterate:
ignore_folders: [refsite, snippet]
ignore_folders: [refsite]
ignore_hidden: false
merge_docs_dir: false
include_extensions: []
semiliterate: