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
1082c286
Unverified
Commit
1082c286
authored
7 years ago
by
Raniere Silva
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #184 from rgaiacs/styles-js-load-images
Replace extract_figures.py with Javacript
parents
337a6e8f
47bfe1bd
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+0
-4
0 additions, 4 deletions
Makefile
bin/extract_figures.py
+0
-98
0 additions, 98 deletions
bin/extract_figures.py
bin/lesson_initialize.py
+35
-6
35 additions, 6 deletions
bin/lesson_initialize.py
with
35 additions
and
108 deletions
Makefile
+
0
−
4
View file @
1082c286
...
...
@@ -95,10 +95,6 @@ lesson-check :
lesson-check-all
:
@
bin/lesson_check.py
-s
.
-p
${
PARSER
}
-l
-w
## lesson-figures : re-generate inclusion displaying all figures.
lesson-figures
:
@
bin/extract_figures.py
-p
${
PARSER
}
${
MARKDOWN_SRC
}
>
_includes/all_figures.html
## unittest : run unit tests on checking tools.
unittest
:
python bin/test_lesson_check.py
...
...
This diff is collapsed.
Click to expand it.
bin/extract_figures.py
deleted
100755 → 0
+
0
−
98
View file @
337a6e8f
#!/usr/bin/env python
from
__future__
import
print_function
import
sys
import
os
import
glob
from
optparse
import
OptionParser
from
util
import
Reporter
,
read_markdown
,
IMAGE_FILE_SUFFIX
def
main
():
"""
Main driver.
"""
args
=
parse_args
()
images
=
[]
for
filename
in
args
.
filenames
:
images
+=
get_images
(
args
.
parser
,
filename
)
save
(
sys
.
stdout
,
images
)
def
parse_args
():
"""
Parse command-line arguments.
"""
parser
=
OptionParser
()
parser
.
add_option
(
'
-p
'
,
'
--parser
'
,
default
=
None
,
dest
=
'
parser
'
,
help
=
'
path to Markdown parser
'
)
args
,
extras
=
parser
.
parse_args
()
require
(
args
.
parser
is
not
None
,
'
Path to Markdown parser not provided
'
)
require
(
extras
,
'
No filenames specified
'
)
args
.
filenames
=
extras
return
args
def
get_filenames
(
source_dir
):
"""
Get all filenames to be searched for images.
"""
return
glob
.
glob
(
os
.
path
.
join
(
source_dir
,
'
*.md
'
))
def
get_images
(
parser
,
filename
):
"""
Extract all images from file.
"""
content
=
read_markdown
(
parser
,
filename
)
result
=
[]
find_image_nodes
(
content
[
'
doc
'
],
result
)
find_image_links
(
content
[
'
doc
'
],
result
)
return
result
def
find_image_nodes
(
doc
,
result
):
"""
Find all nested nodes representing images.
"""
if
(
doc
[
'
type
'
]
==
'
img
'
)
or
\
((
doc
[
'
type
'
]
==
'
html_element
'
)
and
(
doc
[
'
value
'
]
==
'
img
'
)):
alt
=
doc
[
'
attr
'
].
get
(
'
alt
'
,
''
)
result
.
append
({
'
alt
'
:
alt
,
'
src
'
:
doc
[
'
attr
'
][
'
src
'
]})
else
:
for
child
in
doc
.
get
(
'
children
'
,
[]):
find_image_nodes
(
child
,
result
)
def
find_image_links
(
doc
,
result
):
"""
Find all links to files in the
'
fig
'
directory.
"""
if
((
doc
[
'
type
'
]
==
'
a
'
)
and
(
'
attr
'
in
doc
)
and
(
'
href
'
in
doc
[
'
attr
'
]))
\
or
\
((
doc
[
'
type
'
]
==
'
html_element
'
)
and
(
doc
[
'
value
'
]
==
'
a
'
)
and
(
'
href
'
in
doc
[
'
attr
'
])):
path
=
doc
[
'
attr
'
][
'
href
'
]
if
os
.
path
.
splitext
(
path
)[
1
].
lower
()
in
IMAGE_FILE_SUFFIX
:
result
.
append
({
'
alt
'
:
''
,
'
src
'
:
doc
[
'
attr
'
][
'
href
'
]})
else
:
for
child
in
doc
.
get
(
'
children
'
,
[]):
find_image_links
(
child
,
result
)
def
save
(
stream
,
images
):
"""
Save results as Markdown.
"""
text
=
'
\n
<hr/>
\n
'
.
join
([
'
<p><img alt=
"
{0}
"
src=
"
{1}
"
/></p>
'
.
format
(
img
[
'
alt
'
],
img
[
'
src
'
])
for
img
in
images
])
print
(
text
,
file
=
stream
)
def
require
(
condition
,
message
):
"""
Fail if condition not met.
"""
if
not
condition
:
print
(
message
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
bin/lesson_initialize.py
+
35
−
6
View file @
1082c286
...
...
@@ -351,7 +351,41 @@ EXTRAS_FIGURES_MD = '''\
layout: page
title: Figures
---
{% include all_figures.html %}
<script>
window.onload = function() {
var lesson_episodes = [
{% for episode in site.episodes %}
"
{{ episode.url}}
"
{% unless forloop.last %},{% endunless %}
{% endfor %}
];
var xmlHttp = []; /* Required since we are going to query every episode. */
for (i=0; i < lesson_episodes.length; i++) {
xmlHttp[i] = new XMLHttpRequest();
xmlHttp[i].episode = lesson_episodes[i]; /* To enable use this later. */
xmlHttp[i].onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var article_here = document.getElementById(this.episode);
var parser = new DOMParser();
var htmlDoc = parser.parseFromString(this.responseText,
"
text/html
"
);
var htmlDocArticle = htmlDoc.getElementsByTagName(
"
article
"
)[0];
article_here.appendChild(htmlDocArticle.getElementsByTagName(
"
h1
"
)[0]);
for (let image of htmlDocArticle.getElementsByTagName(
"
img
"
)) {
article_here.appendChild(image);
}
}
}
episode_url =
"
{{ page.root }}
"
+ lesson_episodes[i];
xmlHttp[i].open(
"
GET
"
, episode_url);
xmlHttp[i].send(null);
}
}
</script>
{% comment %}
Create anchor for each one of the episodes.
{% endcomment %}
{% for episode in site.episodes %}
<article id=
"
{{ episode.url }}
"
></article>
{% endfor %}
'''
EXTRAS_GUIDE_MD
=
'''
\
...
...
@@ -362,10 +396,6 @@ title: "Instructor Notes"
FIXME
'''
INCLUDES_ALL_FIGURES_HTML
=
'''
\
<!-- empty -->
'''
BOILERPLATE
=
(
(
'
AUTHORS
'
,
ROOT_AUTHORS
),
(
'
CITATION
'
,
ROOT_CITATION
),
...
...
@@ -380,7 +410,6 @@ BOILERPLATE = (
(
'
_extras/discuss.md
'
,
EXTRAS_DISCUSS_MD
),
(
'
_extras/figures.md
'
,
EXTRAS_FIGURES_MD
),
(
'
_extras/guide.md
'
,
EXTRAS_GUIDE_MD
),
(
'
_includes/all_figures.html
'
,
INCLUDES_ALL_FIGURES_HTML
)
)
...
...
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