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
9d68bdd4
Commit
9d68bdd4
authored
9 years ago
by
Greg Wilson
Browse files
Options
Downloads
Plain Diff
Merging from core
parents
07ee1096
d123f135
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
_includes/header.html
+1
-0
1 addition, 0 deletions
_includes/header.html
tools/filters/blockquote2div.py
+32
-18
32 additions, 18 deletions
tools/filters/blockquote2div.py
with
33 additions
and
18 deletions
_includes/header.html
+
1
−
0
View file @
9d68bdd4
<link
rel=
"shortcut icon"
type=
"image/x-icon"
href=
"/favicon.ico"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"css/bootstrap/bootstrap.css"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"css/bootstrap/bootstrap-theme.css"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"css/swc.css"
/>
<link
rel=
"alternate"
type=
"application/rss+xml"
title=
"Software Carpentry Blog"
href=
"http://software-carpentry.org/feed.xml"
/>
<meta
charset=
"UTF-8"
/>
...
...
This diff is collapsed.
Click to expand it.
tools/filters/blockquote2div.py
+
32
−
18
View file @
9d68bdd4
...
...
@@ -21,7 +21,7 @@ For example, this is a valid blockquote:
and it will be converted into this markdown:
<div class=
'
callout
'
>
<div class=
'
callout
panel panel-info
'
>
## Callout time!
Let
'
s do something.
</div>
...
...
@@ -33,7 +33,7 @@ This is also a valid blockquote:
and it will be converted into this markdown:
<div class=
'
prereq
'
>
<div class=
'
prereq
panel panel-warning
'
>
## Prerequisites
Breakfast!
</div>
...
...
@@ -46,10 +46,14 @@ like this:
"""
import
pandocfilters
as
pf
# These are classes that, if set on the title of a blockquote, will
# trigger the blockquote to be converted to a div.
SPECIAL_CLASSES
=
[
'
callout
'
,
'
challenge
'
,
'
prereq
'
,
'
objectives
'
]
SPECIAL_CLASSES
=
{
"
callout
"
:
(
"
panel-info
"
,
"
glyphicon-pushpin
"
),
"
challenge
"
:
(
"
panel-success
"
,
"
glyphicon-pencil
"
),
"
prereq
"
:
(
"
panel-warning
"
,
"
glyphicon-education
"
),
"
objectives
"
:
(
"
panel-warning
"
,
"
glyphicon-certificate
"
),
}
def
find_header
(
blockquote
):
...
...
@@ -64,18 +68,6 @@ def find_header(blockquote):
return
level
,
attr
,
inline
def
remove_attributes
(
blockquote
):
"""
Remove attributes from a blockquote if they are defined on a
header that is the first thing in the blockquote.
Modifies the blockquote inplace.
"""
if
blockquote
[
0
][
'
t
'
]
==
'
Header
'
:
level
,
attr
,
inlines
=
blockquote
[
0
][
'
c
'
]
attr
=
pf
.
attributes
({})
blockquote
[
0
]
=
pf
.
Header
(
level
,
attr
,
inlines
)
def
blockquote2div
(
key
,
value
,
format
,
meta
):
"""
Convert a blockquote into a div if it begins with a header
that has attributes containing a single class that is in the
...
...
@@ -96,10 +88,32 @@ def blockquote2div(key, value, format, meta):
id
,
classes
,
kvs
=
attr
if
len
(
classes
)
==
1
and
classes
[
0
]
in
SPECIAL_CLASSES
:
remove_attributes
(
blockquote
)
panel_kind
,
glyphicon_kind
=
SPECIAL_CLASSES
[
classes
[
0
]]
h_level
,
h_attr
,
h_inlines
=
blockquote
[
0
][
'
c
'
]
# insert an icon as the first sub-item of the header
span
=
pf
.
Span
([
""
,
[
"
glyphicon
"
,
glyphicon_kind
],
[]],
[])
h_inlines
.
insert
(
0
,
span
)
# only the header goes into panel-heading
# WARNING: pandoc doesn't preserve header attributes when the
# header is nested under blockquote. This makes it
# impossible to alter header's "class" attribute, for
# example.
header
=
pf
.
Header
(
h_level
,
h_attr
,
h_inlines
)
panel_header
=
pf
.
Div
((
""
,
[
"
panel-heading
"
],
[]),
[
header
])
# the rest of the blockquote goes into panel-body
panel_body
=
pf
.
Div
((
""
,
[
"
panel-body
"
],
[]),
blockquote
[
1
:])
# apply Bootstrap panel classes to the div
classes
.
append
(
"
panel
"
)
classes
.
append
(
panel_kind
)
# a blockquote is just a list of blocks, so it can be
# passed directly to Div, which expects Div(attr, blocks)
return
pf
.
Div
(
attr
,
blockquote
)
return
pf
.
Div
(
(
id
,
classes
,
kvs
),
[
panel_header
,
panel_body
]
)
if
__name__
==
'
__main__
'
:
...
...
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