From 1cbb2a40c886603a2e2ccc883179cc2d196280e1 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 11 May 2025 21:38:22 -0600 Subject: make rules in html linkable --- html/Makefile | 13 ++++++++++++- html/link.svg | 1 + html/template.html | 25 ++++++++++++++++++++++++ scripts/prepare_html_rules.py | 44 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 html/link.svg create mode 100755 scripts/prepare_html_rules.py diff --git a/html/Makefile b/html/Makefile index e28c9dee..5c462103 100644 --- a/html/Makefile +++ b/html/Makefile @@ -26,6 +26,8 @@ GENERATE_CARD_LISTING := $(GAME_ROOT)/scripts/generate_card_listing.py GENERATE_HOVER_LINKS := $(GAME_ROOT)/scripts/generate_card_hover_links.py +PREPARE_RULES := $(GAME_ROOT)/scripts/prepare_html_rules.py + SETS := $(shell find $(CARDS_YML_DIR) -mindepth 1 -type d -printf "%f\n") SETS_SOURCEDIRS := $(foreach set, $(SETS), $(addprefix $(CARDS_YML_DIR)/, $(set))) @@ -123,6 +125,15 @@ $(1)/%.html: %.md $(MAKEFILE_LIST) $(HTML_TEMPLATE) $(GENERATE_HOVER_LINKS) else $(GENERATE_HOVER_LINKS) $$< | pandoc $(PANDOC_FLAGS) $(2) -o $$@; fi endef +define generateRulesHtml +$(1)/%.html: %.md $(MAKEFILE_LIST) $(HTML_TEMPLATE) $(GENERATE_HOVER_LINKS) + @echo "building $$@" + @if test \( ! \( -d $$(@D) \) \); then mkdir -p $$(@D);fi + $(VERBOSE) if [[ $$$$(cat $$< | wc -l) -gt 80 ]]; \ + then $(GENERATE_HOVER_LINKS) $$< | pandoc --toc $(PANDOC_FLAGS) $(2) | $(PREPARE_RULES) > $$@; \ + else $(GENERATE_HOVER_LINKS) $$< | pandoc $(PANDOC_FLAGS) $(2) | $(PREPARE_RULES) > $$@; fi +endef + $(eval $(call generateHtml, $(BUILDDIR),)) -$(eval $(call generateHtml, $(BUILDDIR)/rules, -N)) +$(eval $(call generateRulesHtml, $(BUILDDIR)/rules, -N)) $(eval $(call generateHtml, $(BUILDDIR)/blog,)) diff --git a/html/link.svg b/html/link.svg new file mode 100644 index 00000000..f0fdbf4f --- /dev/null +++ b/html/link.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/html/template.html b/html/template.html index bae64042..6d58af7d 100644 --- a/html/template.html +++ b/html/template.html @@ -250,6 +250,11 @@ $if(toc)$ padding-left: 10px; } $endif$ + +li.linkable-rule:active, li.linkable-rule:hover { + background-color: #d79921; + list-style-image: url(link.svg); +} $for(css)$ @@ -265,6 +270,26 @@ $endif$ $for(header-includes)$ $header-includes$ $endfor$ + $for(include-before)$ diff --git a/scripts/prepare_html_rules.py b/scripts/prepare_html_rules.py new file mode 100755 index 00000000..4d533bec --- /dev/null +++ b/scripts/prepare_html_rules.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# TODO: support nested lists + +import sys +import re + +def add_ids(ol): + """add ids to all li""" + id = "" + for s in ol.previous_siblings: + if not s.name: + continue + if s.name.startswith("h"): + id = s.attrs["data-number"] + break + + for i, li in enumerate(ol.find_all("li")): + li["id"] = f"{id}-{i+1}" + li["class"] = "rule" + +header_re = re.compile(r' str: + m = data_number_re.search(line) + if m: + return m.group(1) + else: + return "" + +headline = "" +i = 0 +for line in sys.stdin.readlines(): + if header_re.match(line): + headline = extract_headline_nr(line) + h_idx = line.find('