Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This directory contains automated workflows for continuous integration and deplo
**Purpose:** Test the package across multiple Python versions and operating systems.

**Jobs:**
- **test**: Runs on Python 3.8-3.12 across Ubuntu, macOS, and Windows
- **test**: Runs on Python 3.9-3.12 across Ubuntu, macOS, and Windows
- Installs the package
- Tests imports
- Validates plugin registration with MkDocs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
include:
- os: macos-latest
python-version: "3.12"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Each link in the `links` list supports:
- `text` (string, required): The text displayed for the link
- `url` (string, optional): The URL the link points to (not needed if using `submenu`)
- `target` (string, optional): The target attribute (e.g., `_blank` for new tab)
- `bottom-border` (bool or int, optional): Add bottom divider of width 1px if true, or given value in px if number
- `submenu` (list, optional): List of nested links for a submenu (see Nested Dropdowns below)

## Example: Using Shared Config File
Expand Down
4 changes: 2 additions & 2 deletions SETUP_SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This document summarizes the changes made to set up this repository for PyPI pub
- Added maintainers field
- Added `pyyaml` dependency
- Enhanced project URLs (Issues, Documentation)
- Updated Python version support (3.7-3.12)
- Updated Python version support (3.9-3.12)
- Fixed package data configuration

#### `MANIFEST.in` (new)
Expand All @@ -28,7 +28,7 @@ This document summarizes the changes made to set up this repository for PyPI pub

#### `.github/workflows/ci.yml` (new)
Tests the package across multiple environments:
- **Python versions**: 3.8, 3.9, 3.10, 3.11, 3.12
- **Python versions**: 3.9, 3.10, 3.11, 3.12
- **Operating systems**: Ubuntu, macOS, Windows
- **Checks**:
- Package installation
Expand Down
1 change: 1 addition & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Each link in the `links` list supports:
| `text` | string | Yes | The link text |
| `url` | string | Conditional | The target URL (can be relative or absolute). Required unless `submenu` is provided. Optional when using `submenu` to make the parent clickable. |
| `target` | string | No | HTML target attribute (e.g., `_blank` for new tab) |
| `bottom-border` | bool or int | No | Add bottom divider of width 1px if true, or given value in px if number |
| `submenu` | list | No | List of nested links (creates a submenu). See Nested Dropdowns below. |

## Advanced Examples
Expand Down
33 changes: 33 additions & 0 deletions mkdocs_header_dropdown/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@ class HeaderDropdownPlugin(BasePlugin):
('dropdowns', config_options.Type(list, default=[])),
)

def _normalize_links(self, links):
"""
Normalize `border-bottom` value. Default width is 1px if specified
"""
normalized = []
for link in (links or []):
if not isinstance(link, dict):
normalized.append(link)
continue
item = dict(link) # shallow copy avoid mutating link
value = item.get('border-bottom', None)
style = ""
width = 0
if value is None:
width = 0
elif isinstance(value,bool):
width = 1 if value else 0
elif isinstance(value,str):
valstr = value.lower()
width = 1 if any(v in valstr for v in ['yes','true','on']) else 0
elif isinstance(value,(int,float)):
width = value
if width>0:
style += f"border-bottom: {width}px solid var(--md-default-fg-color--lightest);"
item['extra_style'] = style
normalized.append(item)
return normalized

def _generate_links_from_yaml(self, data, parent_key=None):
"""
Recursively generate dropdown links from YAML structure.
Expand Down Expand Up @@ -162,6 +190,11 @@ def on_config(self, config: MkDocsConfig, **kwargs) -> MkDocsConfig:
# 2. Add dropdowns from mkdocs.yml
dropdowns.extend(self.config.get('dropdowns', []))

# Normalize link-level attributes
for dropdown in dropdowns:
if isinstance(dropdown, dict) and isinstance(dropdown.get('links'), list):
dropdown['links'] = self._normalize_links(dropdown['links'])

# Add the dropdowns to extra so templates can access them
config.extra['header_dropdowns'] = dropdowns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{# Top-level link with submenu - clickable link with arrow #}
<a href="{{ link.url }}"
{% if link.target %}target="{{ link.target }}"{% endif %}
style="display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 1rem; color: var(--md-default-fg-color); text-decoration: none; font-size: 0.7rem;"
style="display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 1rem; color: var(--md-default-fg-color); text-decoration: none; font-size: 0.7rem;{{ link.extra_style }}"
onmouseover="this.style.backgroundColor='var(--md-default-fg-color--lightest)'"
onmouseout="this.style.backgroundColor='transparent'">
<span>{{ link.text }}</span>
Expand All @@ -38,7 +38,7 @@
</a>
{% else %}
{# Top-level item with submenu only - not clickable #}
<div style="display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 1rem; color: var(--md-default-fg-color); font-size: 0.7rem; cursor: pointer;"
<div style="display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 1rem; color: var(--md-default-fg-color); font-size: 0.7rem; cursor: pointer;{{ link.extra_style }}"
onmouseover="this.style.backgroundColor='var(--md-default-fg-color--lightest)'"
onmouseout="this.style.backgroundColor='transparent'">
<span>{{ link.text }}</span>
Expand All @@ -52,7 +52,7 @@
{% for sublink in link.submenu %}
<a href="{{ sublink.url }}"
{% if sublink.target %}target="{{ sublink.target }}"{% endif %}
style="display: block; padding: 0.5rem 1rem; color: var(--md-default-fg-color); text-decoration: none; font-size: 0.7rem"
style="display: block; padding: 0.5rem 1rem; color: var(--md-default-fg-color); text-decoration: none; font-size: 0.7rem;{{ sublink.extra_style }}"
onmouseover="this.style.backgroundColor='var(--md-default-fg-color--lightest)'"
onmouseout="this.style.backgroundColor='transparent'">
{{ sublink.text }}
Expand All @@ -63,7 +63,7 @@
{% else %}
<a href="{{ link.url }}"
{% if link.target %}target="{{ link.target }}"{% endif %}
style="display: block; padding: 0.5rem 1rem; color: var(--md-default-fg-color); text-decoration: none; font-size: 0.7rem"
style="display: block; padding: 0.5rem 1rem; color: var(--md-default-fg-color); text-decoration: none; font-size: 0.7rem;{{ link.extra_style }}"
onmouseover="this.style.backgroundColor='var(--md-default-fg-color--lightest)'"
onmouseout="this.style.backgroundColor='transparent'">
{{ link.text }}
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "mkdocs-header-dropdown"
dynamic = ["version"]
description = "A MkDocs plugin to add configurable dropdown menus to the Material theme header"
readme = "README.md"
requires-python = ">=3.7"
requires-python = ">=3.9"
license = "MIT"
keywords = ["mkdocs", "plugin", "dropdown", "navigation", "material-theme", "documentation"]
authors = [
Expand All @@ -23,8 +23,6 @@ classifiers = [
"Topic :: Text Processing :: Markup :: Markdown",
"Framework :: MkDocs",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
Loading