Beispiel #1
0
def read_source(self, config):
    self.eva = None
    try:
        with open(self.file.abs_src_path,
                  "r",
                  encoding="utf-8-sig",
                  errors="strict") as f:
            source = f.read()
    except OSError:
        log.error(f"File not found: {self.file.src_path}")
        raise
    except ValueError:
        log.error(f"Encoding error reading file: {self.file.src_path}")
        raise

    m = YAML_RE.match(source)
    if m:
        try:
            data = yaml.load(m.group(1), SafeLoader)
            if not isinstance(data, dict):
                data = {}
        except Exception as exc:
            raise BuildError(f"Page's YAML metadata is malformed: {exc}")

        try:
            self.eva = config["meta_model_class"](**data)
        except ValidationError as exc:
            raise PluginError(
                f"Deserializing {self} page's meta failed with the following errors: {exc}"
            )

    self.markdown = source
    self.title = self.eva.title
Beispiel #2
0
 def on_page_markdown(self, markdown, **kwargs):
     if self.error_on == 'page_markdown':
         raise BuildError('page markdown error')
     return markdown
Beispiel #3
0
 def on_pre_page(self, page, **kwargs):
     if self.error_on == 'pre_page':
         raise BuildError('pre page error')
     return page