How to use the mkdocs.config.config_options.Type function in mkdocs

To help you get started, we’ve selected a few mkdocs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mkdocs / mkdocs / mkdocs / config / config_options.py View on Github external
edit_uri = 'src/default/docs/'
            else:
                edit_uri = ''

        # ensure a well-formed edit_uri
        if edit_uri:
            if not edit_uri.startswith(('?', '#')) \
                    and not config['repo_url'].endswith('/'):
                config['repo_url'] += '/'
            if not edit_uri.endswith('/'):
                edit_uri += '/'

        config['edit_uri'] = edit_uri


class FilesystemObject(Type):
    """
    Base class for options that point to filesystem objects.
    """
    def __init__(self, exists=False, **kwargs):
        super().__init__(type_=str, **kwargs)
        self.exists = exists
        self.config_dir = None

    def pre_validation(self, config, key_name):
        self.config_dir = os.path.dirname(config.config_file_path) if config.config_file_path else None

    def run_validation(self, value):
        value = super().run_validation(value)
        if self.config_dir and not os.path.isabs(value):
            value = os.path.join(self.config_dir, value)
        if self.exists and not self.existence_test(value):
github mkdocs / mkdocs / mkdocs / config / defaults.py View on Github external
# NOTE: The order here is important. During validation some config options
# depend on others. So, if config option A depends on B, then A should be
# listed higher in the schema.

# Once we drop Python 2.6 support, this could be an OrderedDict, however, it
# isn't really needed either as we always sequentially process the schema other
# than at initialisation when we grab the full set of keys for convenience.

DEFAULT_SCHEMA = (

    # Reserved for internal use, stores the mkdocs.yml config file.
    ('config_file_path', config_options.Type(str)),

    # The title to use for the documentation
    ('site_name', config_options.Type(str, required=True)),

    # Defines the structure of the navigation.
    ('nav', config_options.Nav()),
    # TODO: remove this when the `pages` config setting is fully deprecated.
    ('pages', config_options.Nav()),

    # The full URL to where the documentation will be hosted
    ('site_url', config_options.URL()),

    # A description for the documentation project that will be added to the
    # HTML meta tags.
    ('site_description', config_options.Type(str)),
    # The name of the author to add to the HTML meta tags
    ('site_author', config_options.Type(str)),

    # The MkDocs theme for the documentation.
github mkdocs / mkdocs / mkdocs / config / defaults.py View on Github external
# A copyright notice to add to the footer of documentation.
    ('copyright', config_options.Type(str)),

    # set of values for Google analytics containing the account IO and domain,
    # this should look like, ['UA-27795084-5', 'mkdocs.org']
    ('google_analytics', config_options.Type(list, length=2)),

    # The address on which to serve the live reloading docs server.
    ('dev_addr', config_options.IpAddress(default='127.0.0.1:8000')),

    # If `True`, use `/index.hmtl` style files with hyperlinks to
    # the directory.If `False`, use `.html style file with
    # hyperlinks to the file.
    # True generates nicer URLs, but False is useful if browsing the output on
    # a filesystem.
    ('use_directory_urls', config_options.Type(bool, default=True)),

    # Specify a link to the project source repo to be included
    # in the documentation pages.
    ('repo_url', config_options.RepoURL()),

    # A name to use for the link to the project source repo.
    # Default, If repo_url is unset then None, otherwise
    # "GitHub", "Bitbucket" or "GitLab" for known url or Hostname
    # for unknown urls.
    ('repo_name', config_options.Type(str)),

    # Specify a URI to the docs dir in the project source repo, relative to the
    # repo_url. When set, a link directly to the page in the source repo will
    # be added to the generated HTML. If repo_url is not set also, this option
    # is ignored.
    ('edit_uri', config_options.Type(str)),
github zhaoterryy / mkdocs-pdf-export-plugin / mkdocs_pdf_export_plugin / plugin.py View on Github external
import os
import sys
from timeit import default_timer as timer

from mkdocs.config import config_options
from mkdocs.plugins import BasePlugin

class PdfExportPlugin(BasePlugin):

    DEFAULT_MEDIA_TYPE = 'print'

    config_scheme = (
        ('media_type', config_options.Type(str, default=DEFAULT_MEDIA_TYPE)),
        ('verbose', config_options.Type(bool, default=False)),
        ('enabled_if_env', config_options.Type(str)),
        ('combined', config_options.Type(bool, default=False)),
        ('combined_output_path', config_options.Type(str, default="pdf/combined.pdf")),
        ('theme_handler_path', config_options.Type(str))
    )

    def __init__(self):
        self.renderer = None
        self.enabled = True
        self.combined = False
        self.num_files = 0
        self.num_errors = 0
        self.total_time = 0

    def on_config(self, config):
        if 'enabled_if_env' in self.config:
github greenape / mknotebooks / mknotebooks / plugin.py View on Github external
self.abs_dest_path = os.path.normpath(os.path.join(site_dir, self.dest_path))
        self.url = self._get_url(use_directory_urls)

    def __getattr__(self, item):
        return self.file.__getattribute__(item)

    def is_documentation_page(self):
        return True


class Plugin(mkdocs.plugins.BasePlugin):
    config_scheme = (
        ("execute", mkdocs.config.config_options.Type(bool, default=False)),
        ("allow_errors", mkdocs.config.config_options.Type(bool, default=False)),
        ("preamble", mkdocs.config.config_options.FilesystemObject()),
        ("timeout", mkdocs.config.config_options.Type(int)),
        ("write_markdown", mkdocs.config.config_options.Type(bool, default=False)),
        (
            "enable_default_jupyter_cell_styling",
            mkdocs.config.config_options.Type(bool, default=True),
        ),
        (
            "enable_default_pandas_dataframe_styling",
            mkdocs.config.config_options.Type(bool, default=True),
        ),
    )

    def on_config(self, config: MkDocsConfig):
        exporter_config = Config()
        if self.config["execute"]:
            default_preprocessors = MarkdownExporter.default_preprocessors.default_args[
                0
github fralau / mkdocs_macros_plugin / macros / plugin.py View on Github external
# ------------------------------------------
# Plugin
# ------------------------------------------
class MacrosPlugin(BasePlugin):
    """
    Inject config 'extra' variables into the markdown
    plus macros / variables defined in external module.

    The python code is located in 'main.py' or in a 'main' package
    in the root directory of the website
    (unless you want to redefine that name in the 'python_module' value
    in the mkdocs.yml file)
    """

    # what is under the 'macros' namespace (will go into the config property):
    J2_STRING = PluginType(str, default='')
    config_scheme = (
        # main python module:
        ('module_name',  PluginType(str, 
                                    default=DEFAULT_MODULE_NAME)),
        # include directory for templates ({% include ....%}):
        ('include_dir',  J2_STRING),
        # list of additional yaml files:
        ('include_yaml', PluginType(list, default=[])),
        # for altering the j2 markers, in case of need:
        ('j2_block_start_string',    J2_STRING),
        ('j2_block_end_string',      J2_STRING),
        ('j2_variable_start_string', J2_STRING),
        ('j2_variable_end_string',   J2_STRING)
    )
github byrnereese / mkdocs-minify-plugin / mkdocs_minify_plugin / plugin.py View on Github external
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 mkdocs.structure.files

from jsmin import jsmin
from htmlmin import minify

class MinifyPlugin(BasePlugin):

    config_scheme = (
        ('minify_html', mkdocs.config.config_options.Type(bool, default=False)),
        ('htmlmin_opts', mkdocs.config.config_options.Type((str, dict), default=None)),
        ('minify_js', mkdocs.config.config_options.Type(bool, default=False)),
        ('js_files', mkdocs.config.config_options.Type((str, list), default=None))
    )

    def __init__(self):
        self.enabled = True
        self.total_time = 0

    def on_post_page(self, output_content, page, config):
        if self.config['minify_html']:
            opts = self.config['htmlmin_opts'] or {}
            for key in opts:
                if key not in ['remove_comments','remove_empty_space','remove_all_empty_space','reduce_boolean_attributes','remove_optional_attribute_quotes','conver_charrefs','keep_pre','pre_tags','pre_attr']:
                    print("htmlmin option " + key + " not recognized")
            return minify(output_content, opts.get("remove_comments", False), opts.get("remove_empty_space", False), opts.get("remove_all_empty_space", False), opts.get("reduce_empty_attributes", True), opts.get("reduce_boolean_attributes", False), opts.get("remove_optional_attribute_quotes", True), opts.get("convert_charrefs", True), opts.get("keep_pre", False), opts.get("pre_tags", ('pre', 'textarea')), opts.get("pre_tags", 'pre'))
        else: