Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions markata/plugins/auto_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,24 @@ def get_description(article: "Post") -> str:
content = article.content

# Remove admonitions (e.g., !!!, !!!+, ???, ???+)
content = re.sub(r'^[!?]{3}\+? .*?$', '', content, flags=re.MULTILINE)
content = re.sub(r"^[!?]{3}\+? .*?$", "", content, flags=re.MULTILINE)

# Remove CSS class attributes {.class-name}
content = re.sub(r'\{\.[\w\-]+\}', '', content)
content = re.sub(r"\{\.[\w\-]+\}", "", content)

# Remove Jinja template tags {% %} and {{ }}
content = re.sub(r'\{%.*?%\}', '', content, flags=re.DOTALL)
content = re.sub(r'\{\{.*?\}\}', '', content, flags=re.DOTALL)
content = re.sub(r"\{%.*?%\}", "", content, flags=re.DOTALL)
content = re.sub(r"\{\{.*?\}\}", "", content, flags=re.DOTALL)

# Remove wikilinks [[link]] or [[link|text]]
content = re.sub(r'\[\[([^\]|]+)(?:\|([^\]]+))?\]\]', lambda m: m.group(2) if m.group(2) else m.group(1), content)
content = re.sub(
r"\[\[([^\]|]+)(?:\|([^\]]+))?\]\]",
lambda m: m.group(2) if m.group(2) else m.group(1),
content,
)

# Remove HTML comments
content = re.sub(r'<!--.*?-->', '', content, flags=re.DOTALL)
content = re.sub(r"<!--.*?-->", "", content, flags=re.DOTALL)

# Remove HTML tags before markdown parsing
soup = BeautifulSoup(content, "html.parser")
Expand All @@ -155,7 +159,7 @@ def extract_text(tokens):
description = extract_text(tokens)

# Clean up excessive whitespace
description = re.sub(r'\s+', ' ', description).strip()
description = re.sub(r"\s+", " ", description).strip()

return description

Expand Down
14 changes: 8 additions & 6 deletions markata/plugins/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ def save(markata: Markata) -> None:
if should_write:
xsl_file.write_text(xsl)


def create_page(
markata: Markata,
feed: Feed,
Expand All @@ -503,7 +504,9 @@ def create_page(
if cache_key_posts not in markata._feed_hash_cache:
# Use post slugs and published dates instead of full to_dict()
# This provides a stable, lightweight cache key
posts_data = feed.map("(post.slug, str(getattr(post, 'date', '')), getattr(post, 'title', ''))")
posts_data = feed.map(
"(post.slug, str(getattr(post, 'date', '')), getattr(post, 'title', ''))"
)
markata._feed_hash_cache[cache_key_posts] = str(sorted(posts_data))

posts_hash_data = markata._feed_hash_cache[cache_key_posts]
Expand Down Expand Up @@ -542,9 +545,7 @@ def create_page(
sitemap_output_file = (
Path(markata.config.output_dir) / feed.config.slug / "sitemap.xml"
)
atom_output_file = (
Path(markata.config.output_dir) / feed.config.slug / "atom.xml"
)
atom_output_file = Path(markata.config.output_dir) / feed.config.slug / "atom.xml"

# Create all directories in one batch
partial_output_file.parent.mkdir(exist_ok=True, parents=True)
Expand Down Expand Up @@ -597,7 +598,9 @@ def create_page(
if feed.config.sitemap:
if feed_sitemap_from_cache is None:
from_cache = False
sitemap_template = get_template(markata.jinja_env, feed.config.sitemap_template)
sitemap_template = get_template(
markata.jinja_env, feed.config.sitemap_template
)
feed_sitemap = sitemap_template.render(markata=markata, feed=feed)
cache.set(feed_sitemap_key, feed_sitemap)
else:
Expand Down Expand Up @@ -662,7 +665,6 @@ def create_page(
atom_output_file.write_text(feed_atom)



@background.task
def create_card(
markata: "Markata",
Expand Down
2 changes: 1 addition & 1 deletion markata/plugins/jinja_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def get_templates_mtime(env: Environment) -> float:
for template_dir in get_template_paths(env):
template_path = Path(template_dir)
if template_path.exists():
for path in template_path.rglob('*'):
for path in template_path.rglob("*"):
if path.is_file():
try:
max_mtime = max(max_mtime, path.stat().st_mtime)
Expand Down
73 changes: 73 additions & 0 deletions markata/plugins/mermaid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Markata Plugin: Mermaid Diagram Renderer

This plugin converts Mermaid code blocks in Markdown files into rendered Mermaid diagrams.

# Installation

Ensure Mermaid.js is available in your site. If serving locally, add the script to your template:

```html
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
```

# Configuration

Enable the plugin in `markata.toml`:

```toml
[markata]
hooks = ["markata.plugins.mermaid"]
```

# Usage

Use Mermaid code blocks in your Markdown content:

```markdown
```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```
```

# Notes

- Requires the Markata markdown-it-py backend with the `html` option enabled.
"""

import re
from typing import TYPE_CHECKING

from markata.hookspec import hook_impl

if TYPE_CHECKING:
from markata import Markata

MERMAID_BLOCK_RE = re.compile(r"```[\s]*mermaid\n(.*?)\n```", re.DOTALL)


@hook_impl
def pre_render(markata: "Markata") -> None:
for article in markata.iter_articles("processing mermaid blocks"):
markata.make_hash("mermaid", article.content)
if "mermaid" in article.content:
article.content = MERMAID_BLOCK_RE.sub(
replace_mermaid_block, article.content
)


def replace_mermaid_block(match: re.Match) -> str:
mermaid_code = match.group(1).strip()
mermaid_block = f'<pre class="mermaid">{mermaid_code}</pre>'
return mermaid_block


MERMAID_SCRIPT = """
"""
Loading