Skip to content

Commit 9cf0963

Browse files
authored
Merge pull request #1 from IzaakWN/addDivider
Add optional divider (bottom-border)
2 parents 6e70452 + 6cfeae8 commit 9cf0963

8 files changed

Lines changed: 44 additions & 11 deletions

File tree

.github/workflows/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This directory contains automated workflows for continuous integration and deplo
1111
**Purpose:** Test the package across multiple Python versions and operating systems.
1212

1313
**Jobs:**
14-
- **test**: Runs on Python 3.8-3.12 across Ubuntu, macOS, and Windows
14+
- **test**: Runs on Python 3.9-3.12 across Ubuntu, macOS, and Windows
1515
- Installs the package
1616
- Tests imports
1717
- Validates plugin registration with MkDocs

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
os: [ubuntu-latest]
18-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
18+
python-version: ["3.9", "3.10", "3.11", "3.12"]
1919
include:
2020
- os: macos-latest
2121
python-version: "3.12"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Each link in the `links` list supports:
9191
- `text` (string, required): The text displayed for the link
9292
- `url` (string, optional): The URL the link points to (not needed if using `submenu`)
9393
- `target` (string, optional): The target attribute (e.g., `_blank` for new tab)
94+
- `bottom-border` (bool or int, optional): Add bottom divider of width 1px if true, or given value in px if number
9495
- `submenu` (list, optional): List of nested links for a submenu (see Nested Dropdowns below)
9596

9697
## Example: Using Shared Config File

SETUP_SUMMARY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This document summarizes the changes made to set up this repository for PyPI pub
1717
- Added maintainers field
1818
- Added `pyyaml` dependency
1919
- Enhanced project URLs (Issues, Documentation)
20-
- Updated Python version support (3.7-3.12)
20+
- Updated Python version support (3.9-3.12)
2121
- Fixed package data configuration
2222

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

2929
#### `.github/workflows/ci.yml` (new)
3030
Tests the package across multiple environments:
31-
- **Python versions**: 3.8, 3.9, 3.10, 3.11, 3.12
31+
- **Python versions**: 3.9, 3.10, 3.11, 3.12
3232
- **Operating systems**: Ubuntu, macOS, Windows
3333
- **Checks**:
3434
- Package installation

USAGE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Each link in the `links` list supports:
108108
| `text` | string | Yes | The link text |
109109
| `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. |
110110
| `target` | string | No | HTML target attribute (e.g., `_blank` for new tab) |
111+
| `bottom-border` | bool or int | No | Add bottom divider of width 1px if true, or given value in px if number |
111112
| `submenu` | list | No | List of nested links (creates a submenu). See Nested Dropdowns below. |
112113

113114
## Advanced Examples

mkdocs_header_dropdown/plugin.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,34 @@ class HeaderDropdownPlugin(BasePlugin):
3535
('dropdowns', config_options.Type(list, default=[])),
3636
)
3737

38+
def _normalize_links(self, links):
39+
"""
40+
Normalize `border-bottom` value. Default width is 1px if specified
41+
"""
42+
normalized = []
43+
for link in (links or []):
44+
if not isinstance(link, dict):
45+
normalized.append(link)
46+
continue
47+
item = dict(link) # shallow copy avoid mutating link
48+
value = item.get('border-bottom', None)
49+
style = ""
50+
width = 0
51+
if value is None:
52+
width = 0
53+
elif isinstance(value,bool):
54+
width = 1 if value else 0
55+
elif isinstance(value,str):
56+
valstr = value.lower()
57+
width = 1 if any(v in valstr for v in ['yes','true','on']) else 0
58+
elif isinstance(value,(int,float)):
59+
width = value
60+
if width>0:
61+
style += f"border-bottom: {width}px solid var(--md-default-fg-color--lightest);"
62+
item['extra_style'] = style
63+
normalized.append(item)
64+
return normalized
65+
3866
def _generate_links_from_yaml(self, data, parent_key=None):
3967
"""
4068
Recursively generate dropdown links from YAML structure.
@@ -162,6 +190,11 @@ def on_config(self, config: MkDocsConfig, **kwargs) -> MkDocsConfig:
162190
# 2. Add dropdowns from mkdocs.yml
163191
dropdowns.extend(self.config.get('dropdowns', []))
164192

193+
# Normalize link-level attributes
194+
for dropdown in dropdowns:
195+
if isinstance(dropdown, dict) and isinstance(dropdown.get('links'), list):
196+
dropdown['links'] = self._normalize_links(dropdown['links'])
197+
165198
# Add the dropdowns to extra so templates can access them
166199
config.extra['header_dropdowns'] = dropdowns
167200

mkdocs_header_dropdown/templates/partials/header-dropdown.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
{# Top-level link with submenu - clickable link with arrow #}
2929
<a href="{{ link.url }}"
3030
{% if link.target %}target="{{ link.target }}"{% endif %}
31-
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;"
31+
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 }}"
3232
onmouseover="this.style.backgroundColor='var(--md-default-fg-color--lightest)'"
3333
onmouseout="this.style.backgroundColor='transparent'">
3434
<span>{{ link.text }}</span>
@@ -38,7 +38,7 @@
3838
</a>
3939
{% else %}
4040
{# Top-level item with submenu only - not clickable #}
41-
<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;"
41+
<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 }}"
4242
onmouseover="this.style.backgroundColor='var(--md-default-fg-color--lightest)'"
4343
onmouseout="this.style.backgroundColor='transparent'">
4444
<span>{{ link.text }}</span>
@@ -52,7 +52,7 @@
5252
{% for sublink in link.submenu %}
5353
<a href="{{ sublink.url }}"
5454
{% if sublink.target %}target="{{ sublink.target }}"{% endif %}
55-
style="display: block; padding: 0.5rem 1rem; color: var(--md-default-fg-color); text-decoration: none; font-size: 0.7rem"
55+
style="display: block; padding: 0.5rem 1rem; color: var(--md-default-fg-color); text-decoration: none; font-size: 0.7rem;{{ sublink.extra_style }}"
5656
onmouseover="this.style.backgroundColor='var(--md-default-fg-color--lightest)'"
5757
onmouseout="this.style.backgroundColor='transparent'">
5858
{{ sublink.text }}
@@ -63,7 +63,7 @@
6363
{% else %}
6464
<a href="{{ link.url }}"
6565
{% if link.target %}target="{{ link.target }}"{% endif %}
66-
style="display: block; padding: 0.5rem 1rem; color: var(--md-default-fg-color); text-decoration: none; font-size: 0.7rem"
66+
style="display: block; padding: 0.5rem 1rem; color: var(--md-default-fg-color); text-decoration: none; font-size: 0.7rem;{{ link.extra_style }}"
6767
onmouseover="this.style.backgroundColor='var(--md-default-fg-color--lightest)'"
6868
onmouseout="this.style.backgroundColor='transparent'">
6969
{{ link.text }}

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "mkdocs-header-dropdown"
77
dynamic = ["version"]
88
description = "A MkDocs plugin to add configurable dropdown menus to the Material theme header"
99
readme = "README.md"
10-
requires-python = ">=3.7"
10+
requires-python = ">=3.9"
1111
license = "MIT"
1212
keywords = ["mkdocs", "plugin", "dropdown", "navigation", "material-theme", "documentation"]
1313
authors = [
@@ -23,8 +23,6 @@ classifiers = [
2323
"Topic :: Text Processing :: Markup :: Markdown",
2424
"Framework :: MkDocs",
2525
"Programming Language :: Python :: 3",
26-
"Programming Language :: Python :: 3.7",
27-
"Programming Language :: Python :: 3.8",
2826
"Programming Language :: Python :: 3.9",
2927
"Programming Language :: Python :: 3.10",
3028
"Programming Language :: Python :: 3.11",

0 commit comments

Comments
 (0)