Skip to content

feat: language aware config step + hana changes #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
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
360 changes: 257 additions & 103 deletions pipeline/core/builder.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pipeline/preprocessors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Markdown preprocessors for documentation pipeline."""

from .markdown_preprocessor import preprocess_markdown
from .markdown_preprocessor import has_conditional_blocks, preprocess_markdown

__all__ = ["preprocess_markdown"]
__all__ = ["has_conditional_blocks", "preprocess_markdown"]
19 changes: 12 additions & 7 deletions pipeline/preprocessors/markdown_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

logger = logging.getLogger(__name__)

CONDITIONAL_BLOCK_PATTERN = re.compile(
r"(?P<indent>[ \t]*):::(?P<language>\w+)\s*\n"
r"(?P<content>((?:.*\n)*?))" # Capture the content inside the block
r"(?P=indent)[ \t]*:::" # Match closing with same indentation
)


def _apply_conditional_rendering(md_text: str, target_language: str) -> str:
"""Apply conditional rendering to markdown content.
Expand All @@ -37,12 +43,6 @@ def _apply_conditional_rendering(md_text: str, target_language: str) -> str:
msg = "target_language must be 'python' or 'js'"
raise ValueError(msg)

pattern = re.compile(
r"(?P<indent>[ \t]*):::(?P<language>\w+)\s*\n"
r"(?P<content>((?:.*\n)*?))" # Capture the content inside the block
r"(?P=indent)[ \t]*:::" # Match closing with same indentation
)

def replace_conditional_blocks(match: re.Match) -> str:
"""Keep active conditionals."""
language = match.group("language")
Expand All @@ -58,7 +58,12 @@ def replace_conditional_blocks(match: re.Match) -> str:
# If the language does not match, return an empty string
return ""

return pattern.sub(replace_conditional_blocks, md_text)
return CONDITIONAL_BLOCK_PATTERN.sub(replace_conditional_blocks, md_text)


def has_conditional_blocks(md_text: str) -> bool:
"""Check if the markdown content has conditional blocks."""
return CONDITIONAL_BLOCK_PATTERN.search(md_text) is not None


def preprocess_markdown(
Expand Down
47 changes: 47 additions & 0 deletions pipeline/tools/mintlify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""TypedDict definitions for Mintlify docs.json configuration structure."""

from __future__ import annotations

from typing import TypedDict


class MintlifyConfig(TypedDict):
"""Mintlify config."""

navigation: Navigation


class Navigation(TypedDict, total=False):
"""Navigation configuration."""

versions: list[NavigationVersion] | None


class NavigationVersion(TypedDict, total=False):
"""Version within a navigation."""

version: str
dropdowns: list[NavigationDropdown] | None
tabs: list[NavigationTab] | None


class NavigationDropdown(TypedDict, total=False):
"""Dropdown within a version."""

dropdown: str
icon: str
tabs: list[NavigationTab] | None


class NavigationTab(TypedDict, total=False):
"""Tab within a version."""

tab: str
groups: list[NavigationGroup] | None


class NavigationGroup(TypedDict):
"""Group within a tab."""

group: str
pages: list[str | NavigationGroup]
Loading