Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Lesson Template
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
prace-lessons
Lesson Template
Commits
6e037a57
Commit
6e037a57
authored
9 years ago
by
Greg Wilson
Browse files
Options
Downloads
Patches
Plain Diff
CSS cataloguing tool
parent
d0853662
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/catalog.py
+47
-0
47 additions, 0 deletions
tools/catalog.py
with
47 additions
and
0 deletions
tools/catalog.py
0 → 100644
+
47
−
0
View file @
6e037a57
#!/usr/bin/env python
'''
Create YAML catalog of CSS styles using in a set of HTML documents.
Usage: catalog.py file [file...]
'''
import
sys
import
yaml
from
bs4
import
BeautifulSoup
def
main
(
argv
):
'''
Main driver.
'''
catalog
=
{}
for
filename
in
argv
[
1
:]:
with
open
(
filename
,
'
r
'
)
as
reader
:
doc
=
BeautifulSoup
(
reader
.
read
())
for
node
in
doc
.
descendants
:
update
(
catalog
,
node
)
display
(
catalog
)
def
update
(
catalog
,
node
):
'''
Record classes used in node.
'''
if
node
.
name
is
None
:
return
if
node
.
name
not
in
catalog
:
catalog
[
node
.
name
]
=
set
()
if
'
class
'
in
node
.
attrs
:
for
cls
in
node
.
attrs
[
'
class
'
]:
catalog
[
node
.
name
].
add
(
cls
)
def
display
(
catalog
):
'''
Show the catalog.
'''
for
name
in
sorted
(
catalog
.
keys
()):
catalog
[
name
]
=
sorted
(
catalog
[
name
])
yaml
.
dump
(
catalog
,
stream
=
sys
.
stdout
)
if
__name__
==
'
__main__
'
:
main
(
sys
.
argv
)
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment