Exemple #1
0
def test_dict_option(tmpdir):
    with tmpdir.as_cwd():
        Path("test.ini").write_text('''
[test]
foo=3
bar=5
test=test=7,item2=8
''')
        config = ConfigManager()
        sect = config.addSection("test")

        class TestOption(DictOption[str]):
            @classmethod
            def entryFromString(cls, entry: str) -> str:
                return entry

            def registerArgparse(self, group):
                pass

        sect["test"] = TestOption("", "", {"baz": "6"})
        config.read("test.ini")

        assert config["test"]["test"] == {
            "baz": "6",
            "foo": "3",
            "bar": "5",
            "test": "7",
            "item2": "8"
        }
Exemple #2
0
def addConfig(config: ConfigManager):
    section = config.addSection('custom', 'CustomRenderer Options')

    section['css-path'] = StringOption(
        """ Path to CSS """,
        options='--css-path',
        default='style.css',
    )

    section['katex-css-path'] = StringOption(
        """ Path to katex.min.css """,
        options='--katex-css-path',
        default='https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
    )

    section['font-css-path'] = StringOption(
        """ Path to font css file. This should import the Google fonts Lora and Marcellus SC """,
        options='--font-css-path',
        default='https://fonts.googleapis.com/css?family=Lora|Marcellus+SC',
    )

    section['display-toc'] = BooleanOption(
        """ Display table of contents on each page """,
        options='--display-toc !--no-display-toc',
        default=True,
    )
Exemple #3
0
def defaultConfig(loadConfigFiles: bool = False):
    config = ConfigManager()

    #
    # General
    #
    general = config.addSection('general')

    general['renderer'] = StringOption(
        """
        Renderer to use for conversion

        This is either one of the built in renderers, or a path to the
        directory of a renderer
        """,
        options='--renderer',
        default='HTML5',
    )

    general['theme'] = StringOption(
        """ Theme for the renderer to use """,
        options='--theme',
        default='default',
    )

    general['copy-theme-extras'] = BooleanOption(
        """  Copy files associated with the theme to the output directory """,
        options='--copy-theme-extras !--no-theme-extras',
        default=True,
    )

    general['kpsewhich'] = StringOption(
        """ Program which locates LaTeX files and packages """,
        options='--kpsewhich',
        default='kpsewhich',
    )

    general['xml'] = BooleanOption(
        """ Dump XML representation of the document (for debugging) """,
        options='--xml',
        default=False,
    )

    general['paux-dirs'] = MultiStringOption(
        """Directories where *.paux files should be loaded from.""",
        options='--paux-dirs',
        default=[],
    )

    general['plugins'] = MultiStringOption(
        """
        A list of plugins to use. Each element must be a valid python module name,
        accessible from the current python path.

        """,
        options='--plugins',
        default=[],
    )

    general['load-tex-packages'] = BooleanOption(
        """Try to load the TeX implementation of packages having no python
        implementation.""",
        options='--load-tex-packages',
        default=True,
    )

    general['tex-packages'] = MultiStringOption(
        """
        Packages that we will try to load from their TeX implementation if no
        python implementation is found, even if the load-tex-packages
        option is False.
        """,
        options='--tex-packages',
        default=[],
    )

    general['packages-dirs'] = MultiStringOption(
        """
        Directories where packages could be implemented in python.
        Use either absolute paths or paths relative to the current directory.
        """,
        options='--packages-dirs',
        default=[],
    )

    #
    # Links
    #

    links = config.addSection('links')

    class LinksOption(DictOption[str]):
        @classmethod
        def entryFromString(cls, entry: str) -> str:
            return entry

        def registerArgparse(self, group: ArgumentGroup):
            group.add_argument(*self.options,
                               dest=self.name,
                               help=self.description,
                               action='append',
                               nargs='+')

        def updateFromDict(self, data: Dict["str", Any]):
            try:
                data = data[self.name]
                if data is not None:
                    for entry in data:
                        if len(entry) == 2:
                            self.set("{}-title".format(entry[0]), entry[1])
                        elif len(entry) == 3:
                            self.set("{}-url".format(entry[0]), entry[1])
                            self.set("{}-title".format(entry[0]), entry[2])
                        else:
                            raise ArgumentTypeError(
                                "--link must be 2 or 3 arguments. {} were supplied"
                                .format(len(entry)))
            except KeyError:
                pass

    links['links'] = LinksOption(
        """ Set links for use in navigation """,
        options='--link',
        default={},
    )

    #
    # Counters
    #

    counters = config.addSection('counters')

    class CountersOption(DictOption[int]):
        @classmethod
        def entryFromString(cls, entry: str) -> int:
            return int(entry)

        def registerArgparse(self, group: ArgumentGroup):
            group.add_argument(*self.options,
                               dest=self.name,
                               help=self.description,
                               action='append',
                               nargs=2,
                               metavar=("COUNTER", "VALUE"))

    counters['counters'] = CountersOption(""" Set initial counter values """,
                                          options='--counter',
                                          default={})

    files = config.addSection('files', 'File Handling Options')

    files['input-encoding'] = StringOption(
        """ Input file encoding """,
        options='--input-encoding',
        default='utf-8',
    )

    files['output-encoding'] = StringOption(
        """ Output file encoding """,
        options='--output-encoding',
        default='utf-8',
    )

    files['escape-high-chars'] = BooleanOption(
        """ Escape characters that are higher than 7-bit """,
        options='--escape-high-chars',
        default=False,
    )

    files['split-level'] = IntegerOption(
        """ Highest section level that generates a new file """,
        options='--split-level',
        default=2,
    )

    files['log'] = BooleanOption(
        """ Log messages go to log file instead of console """,
        options='--log',
        default=False,
    )

    files['filename'] = StringOption(
        """ Template for output filenames """,
        options='--filename',
        default='index [$id, sect$num(4)]',
    )

    files['bad-chars'] = StringOption(
        """ Characters that should not be allowed in a filename """,
        options='--bad-filename-chars',
        default=
        ': #$%%^&*!~`"\'=?/{}[]()|<>;\\,.',  # Double % to escape since we interoplate values
    )

    files['bad-chars-sub'] = StringOption(
        """ Character that should be used instead of an illegal character """,
        options='--bad-filename-chars-sub',
        default='-',
    )

    files['directory'] = StringOption(
        """ Directory to put output files into """,
        options='--dir -d',
        default='$jobname',
    )

    #
    # Images
    #

    images = config.addSection('images')

    class ImageScaleOption(DictOption[float]):
        @classmethod
        def entryFromString(cls, entry: str) -> float:
            return float(entry)

        def registerArgparse(self, group: ArgumentGroup):
            group.add_argument(*self.options,
                               dest=self.name,
                               help=self.description,
                               action='append',
                               nargs=2,
                               metavar=("NODE", "VALUE"))

    images['scales'] = ImageScaleOption(
        """ Set image scale for given node name """,
        options='--scales',
        default={})

    images['base-url'] = StringOption(
        """ Base URL for all images """,
        options='--image-base-url',
        default='',
    )

    images['enabled'] = BooleanOption(
        """ Enable image generation """,
        options='--enable-images !--disable-images',
        default=True,
    )

    images['imager'] = StringOption(
        """ LaTeX to image program """,
        options='--imager',
        default='gspdfpng pdftoppm dvipng dvi2bitmap gsdvipng OSXCoreGraphics',
    )

    images['vector-imager'] = StringOption(
        """ LaTeX to vector image program """,
        options='--vector-imager',
        default='pdf2svg dvisvgm',
    )

    images['filenames'] = StringOption(
        """ Template for image filenames """,
        options='--image-filenames',
        default='images/img-$num(4)',
    )

    images['baseline-padding'] = IntegerOption(
        """ Amount to pad the image below the baseline """,
        options='--image-baseline-padding',
        default=0,
    )

    images['scale-factor'] = FloatOption(
        """ Factor to scale externally included images by """,
        options='--image-scale-factor',
        default=1.0,
    )

    images['vector-compiler'] = StringOption(
        """ LaTeX command to use when compiling image document with vector imager""",
        options='--vector-image-compiler',
        default='',
    )

    images['compiler'] = StringOption(
        """ LaTeX command to use when compiling image document """,
        options='--image-compiler',
        default='',
    )

    images['cache'] = BooleanOption(
        """  Enable image caching between runs """,
        options='--enable-image-cache !--disable-image-cache',
        default=False,
    )

    images['save-file'] = BooleanOption(
        """ Should the temporary images.tex file be saved for debugging? """,
        options='--save-image-file !--delete-image-file',
        default=False,
    )

    images['transparent'] = BooleanOption(
        """ Specifies whether the image backgrounds should be transparent or not """,
        options='--transparent-images !--opaque-images',
        default=False,
    )

    images['resolution'] = IntegerOption(
        """ Resolution of images document """,
        options='--image-resolution',
        default=0,
    )

    #
    # Document
    #

    doc = config.addSection('document', "Document Options")

    doc['base-url'] = StringOption(
        """ Base URL for inter-node links """,
        options='--base-url',
        default='',
    )

    doc['title'] = StringOption(
        """
        Title for the document

        This option specifies a title to use instead of the title
        specified in the LaTeX document.

        """,
        options='--title',
        default='',
    )

    doc['toc-depth'] = IntegerOption(
        """ Number of levels to display in the table of contents """,
        options='--toc-depth',
        default=3,
    )

    doc['toc-non-files'] = BooleanOption(
        """ Display sections that do not create files in the table of contents """,
        options='--toc-non-files',
        default=False,
    )

    doc['sec-num-depth'] = IntegerOption(
        """ Maximum section depth to display section numbers """,
        options='--sec-num-depth',
        default=2,
    )

    doc['index-columns'] = IntegerOption(
        """ Number of columns to split the index entries into """,
        options='--index-columns',
        default=2,
    )

    doc['lang-terms'] = MultiStringOption(
        """ A list of files that contain language terms """,
        options='--lang-terms',
        default=[],
    )

    doc['disable-charsub'] = MultiStringOption(
        """A list of characters to not perform character substitutions""",
        options="--disable-charsub",
        default=[])

    #
    # Logging
    #

    logging = config.addSection('logging', "Logging Options")

    class LogOption(DictOption[str]):
        @classmethod
        def entryFromString(cls, entry: str) -> str:
            return entry

        def registerArgparse(self, group: ArgumentGroup):
            group.add_argument(*self.options,
                               dest=self.name,
                               help=self.description,
                               action='append',
                               nargs=2,
                               metavar=("NAME", "LEVEL"))

    logging["logging"] = LogOption("Log levels",
                                   options="--logging",
                                   default={})

    if loadConfigFiles:
        config.read([
            '~/.plasTeXrc', '/usr/local/etc/plasTeXrc',
            os.path.join(os.path.dirname(__file__), 'plasTeXrc')
        ])

    return config
Exemple #4
0
from plasTeX.ConfigManager import *
from plasTeX.DOM import Node

config = ConfigManager()

section = config.add_section('html5')

config.add_category('html5', 'Html5 renderer Options')

section['extra-css'] = MultiOption(
    """ Extra css files to use """,
    options='--extra-css',
    category='html5',
    default='',
)

section['extra-js'] = MultiOption(
    """ Extra javascript files to use """,
    options='--extra-js',
    category='html5',
    default='',
)

section['theme-css'] = StringOption(
    """ Theme css file""",
    options='--theme-css',
    category='html5',
    default='green',
)

section['use-theme-css'] = BooleanOption(
Exemple #5
0
#!/usr/bin/env python

import os
from plasTeX.ConfigManager import *

c = config = ConfigManager()

#
# General
#
general = c.add_section('general')

general['renderer'] = StringOption(
    """
    Renderer to use for conversion

    This is either one of the built in renderers, or a path to the
    directory of a renderer
    """,
    options='--renderer',
    default='XHTML',
)

general['theme'] = StringOption(
    """ Theme for the renderer to use """,
    options='--theme',
    default='default',
)

general['copy-theme-extras'] = BooleanOption(
    """  Copy files associated with the theme to the output directory """,
Exemple #6
0
def addConfig(config: ConfigManager):
    section = config.addSection('html5', 'Html5 renderer Options')

    section['extra-css'] = MultiStringOption(
        """ Extra css files to use """,
        options='--extra-css',
        default=[],
    )

    section['extra-js'] = MultiStringOption(
        """ Extra javascript files to use """,
        options='--extra-js',
        default=[],
    )

    section['theme-css'] = StringOption(
        """ Theme css file""",
        options='--theme-css',
        default='white',
    )

    section['use-theme-css'] = BooleanOption(
        """ Use theme css """,
        options='--use-theme-css !--no-theme-css',
        default=True,
    )

    section['use-theme-js'] = BooleanOption(
        """ Use theme javascript """,
        options='--use-theme-js !--no-theme-js',
        default=True,
    )

    section['display-toc'] = BooleanOption(
        """ Display table of contents on each page """,
        options='--display-toc !--no-display-toc',
        default=True,
    )

    section['localtoc-level'] = IntegerOption(
        """ Create local toc above this level """,
        options='--localtoc-level',
        default=Node.DOCUMENT_LEVEL - 1,
    )

    section['breadcrumbs-level'] = IntegerOption(
        """ Create breadcrumbs from this level """,
        options='--breadcrumbs-level',
        default=10,
    )

    section['use-mathjax'] = BooleanOption(
        """ Use mathjax """,
        options='--use-mathjax !--no-mathjax',
        default=True,
    )

    section['mathjax-url'] = StringOption(
        """ Url of the MathJax lib """,
        options='--mathjax-url',
        default='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js',
    )

    section['mathjax-dollars'] = BooleanOption(
        """ Use single dollars as math delimiter for mathjax """,
        options='--dollars !--no-dollars',
        default=False,
    )

    section['filters'] = MultiStringOption(
        """Comma separated list of commands to invoke on each output page.""",
        options='--filters',
        default=[],
    )
Exemple #7
0
import os
from plasTeX.ConfigManager import *

config = ConfigManager()

section = config.add_section("gerby")

config.add_category("gerby", "Gerby renderer options")

section["tags"] = StringOption(
  """Location of the tags file""",
  options = "--tags",
  category = "gerby",
  default = "tags",
)
Exemple #8
0
import os
from plasTeX.ConfigManager import *
from plasTeX.DOM import Node

config = ConfigManager()

section = config.add_section('html5')

config.add_category('html5', 'Html5 renderer Options')

section['extra-css'] = MultiOption(
    """ Extra css files to use """,
    options='--extra-css',
    category='html5',
    default='',
)

section['extra-js'] = MultiOption(
    """ Extra javascript files to use """,
    options='--extra-js',
    category='html5',
    default='',
)

section['theme-css'] = StringOption(
    """ Theme css file""",
    options='--theme-css',
    category='html5',
    default='green',
)