diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4ebf60c1..c7a804ea 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -75,6 +75,25 @@ jobs: with: cargo-command: clippy --all-features --all-targets + ensure-counter-styles-up-to-date: + name: Ensure counter styles up to date + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: | + python ./web_atoms/update_predefined_counter_styles.py + git update-index --really-refresh + if git diff-index --quiet HEAD + then + echo "Predefined counter styles are up to date" + exit 0 + else + echo "Predefined counter styles are out of date" + echo "Run python ./web_atoms/update_predefined_counter_styles.py to update them" + exit 1 + fi + + build_result: name: Result runs-on: ubuntu-latest diff --git a/web_atoms/build.rs b/web_atoms/build.rs index a1463107..bf88947c 100644 --- a/web_atoms/build.rs +++ b/web_atoms/build.rs @@ -29,21 +29,29 @@ static NAMESPACES: &[(&str, &str)] = &[ ("mathml", "http://www.w3.org/1998/Math/MathML"), ]; +fn iter_file_lines(filename: &str) -> impl Iterator { + let filepath = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join(filename); + let reader = BufReader::new(File::open(filepath).unwrap()); + reader.lines().map(Result::unwrap) +} + fn main() { let generated = Path::new(&env::var("OUT_DIR").unwrap()).join("generated.rs"); let mut generated = BufWriter::new(File::create(generated).unwrap()); named_entities_to_phf(&Path::new(&env::var("OUT_DIR").unwrap()).join("named_entities.rs")); + // Create a string cache for style atoms + string_cache_codegen::AtomType::new("StyleAtom", "style_atom!") + .atoms(iter_file_lines("style_atoms.txt")) + .atoms(iter_file_lines("predefined_counter_styles.txt")) + .write_to(&mut generated) + .unwrap(); + // Create a string cache for local names - let local_names = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("local_names.txt"); - let mut local_names_atom = string_cache_codegen::AtomType::new("LocalName", "local_name!"); - for line in BufReader::new(File::open(local_names).unwrap()).lines() { - let local_name = line.unwrap(); - local_names_atom.atom(&local_name); - local_names_atom.atom(&local_name.to_ascii_lowercase()); - } - local_names_atom + string_cache_codegen::AtomType::new("LocalName", "local_name!") + .atoms(iter_file_lines("local_names.txt")) + .atoms(iter_file_lines("local_names.txt").map(|s| s.to_ascii_lowercase())) .with_macro_doc("Takes a local name as a string and returns its key in the string cache.") .write_to(&mut generated) .unwrap(); diff --git a/web_atoms/predefined_counter_styles.txt b/web_atoms/predefined_counter_styles.txt new file mode 100644 index 00000000..997212b6 --- /dev/null +++ b/web_atoms/predefined_counter_styles.txt @@ -0,0 +1,55 @@ +decimal +decimal-leading-zero +arabic-indic +armenian +upper-armenian +lower-armenian +bengali +cambodian +khmer +cjk-decimal +devanagari +georgian +gujarati +gurmukhi +hebrew +kannada +lao +malayalam +mongolian +myanmar +oriya +persian +lower-roman +upper-roman +tamil +telugu +thai +tibetan +lower-alpha +lower-latin +upper-alpha +upper-latin +lower-greek +hiragana +hiragana-iroha +katakana +katakana-iroha +disc +circle +square +disclosure-open +disclosure-closed +cjk-earthly-branch +cjk-heavenly-stem +japanese-informal +japanese-formal +korean-hangul-formal +korean-hanja-informal +korean-hanja-formal +simp-chinese-informal +simp-chinese-formal +trad-chinese-informal +trad-chinese-formal +cjk-ideographic +ethiopic-numeric diff --git a/web_atoms/style_atoms.txt b/web_atoms/style_atoms.txt new file mode 100644 index 00000000..eb242215 --- /dev/null +++ b/web_atoms/style_atoms.txt @@ -0,0 +1,185 @@ +-moz-content-preferred-color-scheme +-moz-device-pixel-ratio +-moz-fixed-pos-containing-block +-moz-gtk-csd-close-button-position +-moz-gtk-csd-maximize-button-position +-moz-gtk-csd-menu-radius +-moz-gtk-csd-minimize-button-position +-moz-gtk-csd-titlebar-button-spacing +-moz-gtk-csd-titlebar-radius +-moz-gtk-csd-tooltip-radius +-moz-gtk-menu-radius +-moz-mac-titlebar-height +-moz-overlay-scrollbar-fade-duration +DOMContentLoaded +abort +activate +addtrack +animationcancel +animationend +animationiteration +animationstart +aspect-ratio +beforetoggle +beforeunload +block-size +button +canplay +canplaythrough +center +change +characteristicvaluechanged +checkbox +cancel +click +close +closing +color +complete +compositionend +compositionstart +compositionupdate +controllerchange +cursive +dark +datachannel +date +datetime-local +dir +device-pixel-ratio +durationchange +email +emptied +end +ended +error +fantasy +fetch +file +fill +fill-opacity +formdata +fullscreenchange +fullscreenerror +gattserverdisconnected +hairline +hashchange +height +hidden +icecandidate +iceconnectionstatechange +icegatheringstatechange +image +inline-size +input +inputsourceschange +invalid +keydown +keypress +kind +left +light +ltr +load +loadeddata +loadedmetadata +loadend +loadstart +message +message +messageerror +monospace +month +mousedown +mousemove +mouseover +mouseup +negotiationneeded +none +normal +number +onchange +open +orientation +pagehide +pageshow +password +pause +play +playing +popstate +postershown +prefers-color-scheme +print +progress +radio +range +ratechange +readystatechange +referrer +reftest-wait +rejectionhandled +removetrack +reset +resize +resolution +resourcetimingbufferfull +right +rtl +sans-serif +safe-area-inset-top +safe-area-inset-bottom +safe-area-inset-left +safe-area-inset-right +scan +screen +scroll-position +scrollbar-inline-size +search +seeked +seeking +select +selectend +selectionchange +selectstart +serif +sessionavailable +show +signalingstatechange +slotchange +squeeze +squeezeend +squeezestart +srclang +statechange +stroke +stroke-opacity +storage +submit +suspend +system-ui +tel +text +time +timeupdate +toggle +track +transitioncancel +transitionend +transitionrun +transitionstart +uncapturederror +unhandledrejection +unload +url +visibilitychange +volumechange +waiting +webglcontextcreationerror +webkitAnimationEnd +webkitAnimationIteration +webkitAnimationStart +webkitTransitionEnd +webkitTransitionRun +week +width \ No newline at end of file diff --git a/web_atoms/update_predefined_counter_styles.py b/web_atoms/update_predefined_counter_styles.py new file mode 100644 index 00000000..e4640260 --- /dev/null +++ b/web_atoms/update_predefined_counter_styles.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +from os.path import join, dirname +import re +from urllib.request import urlopen + +print("Fetching https://drafts.csswg.org/css-counter-styles...") +counter_styles_spec = urlopen("https://drafts.csswg.org/css-counter-styles") + +print("Finding counter styles") +names = []; +for line in counter_styles_spec: + if b'data-dfn-for=""' in line or b'data-dfn-for=""' in line: + counter_style = re.search('>([^>]+)(|