Skip to content

Commit cfe4cb7

Browse files
committed
v0.4.0a2: demote_headers filter (w/ example template changes)
1 parent a60d6a9 commit cfe4cb7

File tree

6 files changed

+71
-6
lines changed

6 files changed

+71
-6
lines changed

dactyl/filter_demote_headers.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
################################################################################
2+
## Demote Headers filter ##
3+
## Author: Rome Reginelli ##
4+
## Copyright: Ripple Labs, Inc. 2017 ##
5+
## ##
6+
## Demote all headers one level. This can be useful to make PDF docs render ##
7+
## a nice link hierarchy if your templates provide category headers at h1 but ##
8+
## your docs individually start at the h1 level. ##
9+
################################################################################
10+
11+
DEMOTE_FIELD = "demote_headers_pdf_only"
12+
13+
def filter_html(html, mode="html", target={}, **kwargs):
14+
if (mode == "html" and
15+
DEMOTE_FIELD in target and
16+
target[DEMOTE_FIELD]):
17+
# Don't bother then
18+
return html
19+
20+
html = html.replace("<h5", "<h6")
21+
html = html.replace("<h4", "<h5")
22+
html = html.replace("<h3", "<h4")
23+
html = html.replace("<h2", "<h3")
24+
html = html.replace("<h1", "<h2")
25+
return html

dactyl/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.4.0a1'
1+
__version__ = '0.4.0a2'

examples/dactyl-config.yml

+15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ filter_paths:
1111
targets:
1212
- name: everything
1313
display_name: Target with ALL THE EXAMPLES™
14+
filters:
15+
- demote_headers
16+
demote_headers_pdf_only: true
1417

1518
- name: filterdemos
1619
display_name: Target with just the filter example pages
@@ -20,6 +23,12 @@ targets:
2023
condition: tests-2
2124

2225
pages:
26+
- html: tests-index.html
27+
category: Tests
28+
section_header: true
29+
targets:
30+
- everything
31+
2332
- md: includes.md
2433
html: test-includes.html
2534
category: Tests
@@ -48,6 +57,12 @@ pages:
4857
targets:
4958
- everything
5059

60+
- html: filters-index.html
61+
category: Filters
62+
section_header: true
63+
targets:
64+
- everything
65+
5166
- md: filter-examples/callouts.md
5267
html: filter-callouts.html
5368
category: Filters

examples/template_assets/dactyl-print.css

+20-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,30 @@
1313
max-width: 650px;
1414
}
1515
.dactyl-pdf-cover h1,
16-
.dactyl-pdf-cover h2,
17-
.dactyl-pdf-cover h3 {
16+
.dactyl-pdf-cover p {
1817
padding: 0;
1918
margin: 10px 0 0 0;
2019
}
2120

21+
.dactyl-toc-cat a {
22+
font-size: 18pt;
23+
text-decoration: none;
24+
color: black;
25+
font-weight: bold;
26+
margin-bottom: 10px;
27+
}
28+
29+
.dactyl-section-cover {
30+
page-break-before: always;
31+
}
32+
33+
.dactyl-section-cover h1 {
34+
font-size: 90pt;
35+
margin-top: 40%;
36+
padding-bottom: 10px;
37+
border-bottom: 4px dashed black;
38+
}
39+
2240
@page {
2341
@bottom-left {
2442
content: flow(footer);

examples/templates/template-pdf.html

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
</head>
1010
<body>
1111
<footer>(Exported {{ current_time }})</footer>
12+
{% if currentpage.section_header %}
13+
<div class="dactyl-section-cover">
14+
<h1>{{ currentpage.category }}</h1>
15+
</div>
16+
{% endif %}
1217
<main class="dactyl-main">{{content}}</main>
1318
</body>
1419
</html>

examples/templates/template-pdf_cover.html

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
<div class="dactyl-pdf-cover">
1212
<section class="dactyl-pdf-title-area">
1313
<h1>{{ target.display_name }}</h1>
14-
<h2>{{ current_time }}</h2>
14+
<p>{{ current_time }}</p>
1515
</section>
1616
</div>
1717
<div class="dactyl-pdf-toc">
1818
{% for cat in categories %}
19-
<h3>{{ cat }}</h3>
19+
<div class="dactyl-toc-cat">
20+
<a href="{{ (pages|selectattr('category', 'equalto', cat)|first).html }}">{{ cat }}</a>
21+
</div>
2022
<ul>
2123
{% for page in pages %}
22-
{% if page.category == cat %}
24+
{% if page.category == cat and not page.section_header %}
2325
<li><a href="{{ page.html }}">{{ page.name }}</a></li>
2426
{% endif %}
2527
{% endfor %}

0 commit comments

Comments
 (0)