How to use the nikola.plugin_categories.PageCompiler function in Nikola

To help you get started, we’ve selected a few Nikola 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 undertherain / pycontextfree / site / plugins / pdoc / pdoc.py View on Github external
import io
import os
import shlex
import subprocess
import sys
import tempfile


from nikola import shortcodes as sc
from nikola.plugin_categories import PageCompiler
from nikola.utils import makedirs, write_metadata
from nikola.utils import LOGGER


class CompilePdoc(PageCompiler):
    """Compile docstrings into HTML."""

    name = "pdoc"
    friendly_name = "PDoc"
    supports_metadata = False

    def __init__(self):
        plugin_path = os.path.dirname(os.path.realpath(__file__))
        base_path = plugin_path.split("plugins")[0]
        LOGGER.info(f"!!!!!!!!!!!!!!!!base path = {base_path}")
        sys.path.insert(0, os.path.join(base_path, "../"))

    def compile_string(self, data, source_path=None, is_two_file=True, post=None, lang=None):
        """Compile docstrings into HTML strings, with shortcode support."""
        if not is_two_file:
            _, data = self.split_metadata(data, None, lang)
github openframeworks / ofSite / plugins / asciidoc / asciidoc.py View on Github external
# for non-ascii encoding
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

from nikola.plugin_categories import PageCompiler
from nikola.utils import makedirs, req_missing, write_metadata

try:
    from collections import OrderedDict
except ImportError:
    OrderedDict = dict  # NOQA


class CompileAsciiDoc(PageCompiler):
    """Compile asciidoc into HTML."""

    name = "asciidoc"
    demote_headers = True

    def compile_html(self, source, dest, is_two_file=True):
        makedirs(os.path.dirname(dest))
        binary = self.site.config.get('ASCIIDOC_BINARY', 'asciidoc')
        try:
            subprocess.check_call((binary, '-b', 'html5', '-s', '-o', dest, source))
        except OSError as e:
            if e.strreror == 'No such file or directory':
                req_missing(['asciidoc'], 'build this site (compile with asciidoc)', python=False)

    def create_post(self, path, **kw):
        content = kw.pop('content', 'Write your post here.')