Skip to content

Commit

Permalink
update docs for base-parser and markdown parser (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjaymiller committed Feb 13, 2024
1 parent 5ccf5cc commit ffc6b55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors-)

<!-- ALL-CONTRIBUTORS-BADGE:END -->

>**WARNING**
>The 2023.9.1 update changes `site.static_path` to `site.static_paths` any custom output paths will need to be updated to reflect this change. `'output'` is still the default value for `site.static_paths` and will be used if no value is provided.
> **WARNING**
> The 2023.9.1 update changes `site.static_path` to `site.static_paths` any custom output paths will need to be updated to reflect this change. `'output'` is still the default value for `site.static_paths` and will be used if no value is provided.
# Render Engine

Expand Down
21 changes: 12 additions & 9 deletions docs/docs/parsers.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ Parsers control how content is parsed and rendered.
All [`Page`][src.render_engine.page.Page] and [`Collection`][src.render_engine.collection.Collection] objects have a `parser`
attribute that is used to parse the content of the object.

Parsers use [staticmethods](https://docs.python.org/3/library/functions.html#staticmethod) to parse content. This allows you to create custom parsers that can be used to parse content in any way you want. Render Engine comes with a [BasePageParser](#basepageparser) and a [MarkdownPageParser](#markdownpageparser) that can be used out of the box.
Parsers use [staticmethods](https://docs.python.org/3/library/functions.html#staticmethod) to parse content. This allows you to create custom parsers that can be used to parse content in any way you want. Render Engine comes with a [BasePageParser](https://github.com/render-engine/render-engine-parser) and a [MarkdownPageParser](https://github.com/render-engine/render-engine-markdown) that can be used out of the box.

## BasePageParser

:::src.render_engine.parsers.base_parsers.BasePageParser
The BasePageParser is the default parser for base-Page and collection object. This is a plain text parser that does not do any parsing of the content. It is useful for simple content that does not need to be parsed.

The `BasePageParser` will parse frontmatter and pass attributes of the page. The content will be returned as is.

```python
from render_engine.parsers.base_parsers import BasePageParser
from render_engine.page import Page

base_text = """
base_text = """
---
title: "Hello World"
---
Expand All @@ -41,13 +43,13 @@ my_page._render_content()

## MarkdownPageParser

In many cases, you will want to create rich content. Render Engine comes with a `MarkdownPageParser` that can be used to parse Markdown files. You can also pass in attributes to the page via frontmatter at the top of the markdown file.
In many cases, you will want to create rich content. The `MarkdownPageParser`. You can also pass in attributes to the page via frontmatter at the top of the markdown file.

```python
from render_engine.parsers.base_parsers import BasePageParser
from render_engine.page import Page

base_markdown = """
base_markdown = """
---
title: "Hello World"
---
Expand All @@ -73,11 +75,12 @@ my_page._render_content()

## Creating Custom Parsers

You can create custom parsers by subclassing [`BasePageParser`][src.render_engine.parsers.base_parsers.BasePageParser].
You can create custom parsers.

All the staticmethods for parsers should return a tuple where the first entry is a dictionary of attributes and the second entry is the rendered content.

All the static methods for parsers should return a tuple where the first entry is a dictionary of attributes and the second entry is the rendered content.
> !!! Warning
!!! Warning
Custom Parsers do not use frontmatter by default. You would need to ensure that your parser handles frontmatter if you want to use it.

For example, to create a parser that renders a dictionary, you could do the following:
Expand All @@ -92,7 +95,7 @@ class DictPageParser(BasePageParser):
return (base_content, content)

# `parse_content_path` would be similar in this case.
# `parse` would be inherited from `BasePageParser`
# `parse` would be inherited from `BasePageParser`

base_dict = {
"title": "Hello World"
Expand Down

0 comments on commit ffc6b55

Please sign in to comment.