Skip to content

Instantly share code, notes, and snippets.

@roktas
Last active August 19, 2023 22:23
Show Gist options
  • Save roktas/ccf5af60229a64af04ac99ceb93ede0c to your computer and use it in GitHub Desktop.
Save roktas/ccf5af60229a64af04ac99ceb93ede0c to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# TOO UGLY!
#
# Offline MDN SVG: https://frankfurt.kapeli.com/feeds/zzz/mdn/SVG.tgz
ELEMENTS = %w[
a
animate
animateMotion
animateTransform
circle
clipPath
defs
desc
ellipse
feBlend
feColorMatrix
feComponentTransfer
feComposite
feConvolveMatrix
feDiffuseLighting
feDisplacementMap
feDistantLight
feDropShadow
feFlood
feFuncA
feFuncB
feFuncG
feFuncR
feGaussianBlur
feImage
feMerge
feMergeNode
feMorphology
feOffset
fePointLight
feSpecularLighting
feSpotLight
feTile
feTurbulence
filter
foreignObject
g
hatch
hatchpath
image
line
linearGradient
marker
mask
metadata
mpath
path
pattern
polygon
polyline
radialGradient
rect
script
set
stop
style
svg
switch
symbol
text
textPath
title
tspan
use
view
]
ATTRIBUTES = %w[
accent-height
accumulate
additive
alignment-baseline
alphabetic
amplitude
arabic-form
ascent
attributeName
attributeType
azimuth
baseFrequency
baseline-shift
baseProfile
bbox
begin
bias
by
calcMode
cap-height
class
clip
clipPathUnits
clip-path
clip-rule
color
color-interpolation
color-interpolation-filters
color-profile
color-rendering
contentScriptType
contentStyleType
crossorigin
cursor
cx
cy
d
decelerate
descent
diffuseConstant
direction
display
divisor
dominant-baseline
dur
dx
dy
edgeMode
elevation
enable-background
end
exponent
fill
fill-opacity
fill-rule
filter
filterRes
filterUnits
flood-color
flood-opacity
font-family
font-size
font-size-adjust
font-stretch
font-style
font-variant
font-weight
format
from
fr
fx
fy
g1
g2
glyph-name
glyph-orientation-horizontal
glyph-orientation-vertical
glyphRef
gradientTransform
gradientUnits
hanging
height
href
hreflang
horiz-adv-x
horiz-origin-x
id
ideographic
image-rendering
in
in2
intercept
k
k1
k2
k3
k4
kernelMatrix
kernelUnitLength
kerning
keyPoints
keySplines
keyTimes
lang
lengthAdjust
letter-spacing
lighting-color
limitingConeAngle
local
marker-end
marker-mid
marker-start
markerHeight
markerUnits
markerWidth
mask
maskContentUnits
maskUnits
mathematical
max
media
method
min
mode
name
numOctaves
offset
opacity
operator
order
orient
orientation
origin
overflow
overline-position
overline-thickness
panose-1
paint-order
path
pathLength
patternContentUnits
patternTransform
patternUnits
ping
pointer-events
points
pointsAtX
pointsAtY
pointsAtZ
preserveAlpha
preserveAspectRatio
primitiveUnits
r
radius
referrerPolicy
refX
refY
rel
rendering-intent
repeatCount
repeatDur
requiredExtensions
requiredFeatures
restart
result
rotate
rx
ry
scale
seed
shape-rendering
slope
spacing
specularConstant
specularExponent
speed
spreadMethod
startOffset
stdDeviation
stemh
stemv
stitchTiles
stop-color
stop-opacity
strikethrough-position
strikethrough-thickness
string
stroke
stroke-dasharray
stroke-dashoffset
stroke-linecap
stroke-linejoin
stroke-miterlimit
stroke-opacity
stroke-width
style
surfaceScale
systemLanguage
tabindex
tableValues
target
targetX
targetY
text-anchor
text-decoration
text-rendering
textLength
to
transform
transform-origin
type
u1
u2
underline-position
underline-thickness
unicode
unicode-bidi
unicode-range
units-per-em
v-alphabetic
v-hanging
v-ideographic
v-mathematical
values
vector-effect
version
vert-adv-y
vert-origin-x
vert-origin-y
viewBox
viewTarget
visibility
width
widths
word-spacing
writing-mode
x
x-height
x1
x2
xChannelSelector
xlink:actuate
xlink:arcrole
xlink:href
xlink:role
xlink:show
xlink:title
xlink:type
xml:base
xml:lang
xml:space
y
y1
y2
yChannelSelector
z
zoomAndPan
]
def do_attributes
attributes_with_element_list = []
attributes_with_element_hash = {}
attributes_with_any_list = []
attributes_deprecated = []
ATTRIBUTES.each do |attribute|
file = "Attribute/#{attribute}.html"
file = "Attribute/#{attribute.capitalize}.html" unless File.exist?(file)
next unless File.exist?(file)
lines = File.readlines(file)
if (i = lines.find_index { |line| line =~ /following SVG element[s]?:/ })
attributes_with_element_list << attribute
start = i + 1
lines[start..(start + 100)].each do |line|
if (m = line.match(%r{"[.][.]/Element/(?<element>[^.]+).html"}))
(attributes_with_element_hash[attribute] ||= []) << m[:element]
end
end
end
if (lines.find { |line| line =~ /with any SVG element/ })
attributes_with_any_list << attribute
end
if (lines.find { |line| line =~ %r{<strong>Deprecated:?</strong>} })
attributes_deprecated << attribute
end
end
warn "All attributes: #{ATTRIBUTES.size}"
warn
warn "With element: #{attributes_with_element_list.size}"
warn
attributes_without_element_list = ATTRIBUTES - attributes_with_element_list
warn "Without element: #{attributes_without_element_list.size}"
warn
warn "With any element: #{attributes_with_any_list.size}"
warn
warn "Deprecated: #{attributes_deprecated.size}"
warn
# warn attributes_with_any_list
# warn attributes_deprecated
puts attributes_without_element_list
exit
puts "specifications("
attributes_with_element_hash.each do |attribute, elements|
puts %{ "#{attribute}": %i[}
elements.each do |element|
puts " #{element}"
end
puts " ],"
puts
end
puts ")"
end
def do_elements
elements_contentful = []
ELEMENTS.each do |element|
file = "Element/#{element}.html"
file = "Element/#{element.capitalize}.html" unless File.exist?(file)
next unless File.exist?(file)
lines = File.readlines(file)
# if (i = lines.find_index { |line| line =~ %r{[<]th.*Permitted content[<][/]th[>]} })
if (i = lines.find_index { |line| line =~ %r{Permitted content} })
start = i
lines[start..(start + 10)].each do |line|
if line =~ /[Cc]haracter data/
elements_contentful << element
end
end
end
end
puts elements_contentful
end
do_elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment