Skip to content
Open
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
19 changes: 19 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 16 additions & 8 deletions web_atoms/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,29 @@ static NAMESPACES: &[(&str, &str)] = &[
("mathml", "http://www.w3.org/1998/Math/MathML"),
];

fn iter_file_lines(filename: &str) -> impl Iterator<Item = String> {
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();
Expand Down
55 changes: 55 additions & 0 deletions web_atoms/predefined_counter_styles.txt
Original file line number Diff line number Diff line change
@@ -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
185 changes: 185 additions & 0 deletions web_atoms/style_atoms.txt
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions web_atoms/update_predefined_counter_styles.py
Original file line number Diff line number Diff line change
@@ -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="<counter-style-name>"' in line or b'data-dfn-for="<counter-style>"' in line:
counter_style = re.search('>([^>]+)(</dfn>|<a class="self-link")', line.decode()).group(1)
names.append(counter_style)

filename = join(dirname(__file__), "predefined_counter_styles.txt")
with open(filename, "w") as f:
for name in names:
f.write(f"{name}\n")

print("Done.")