Skip to content

Commit

Permalink
v0.4.0a2: demote_headers filter (w/ example template changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
mDuo13 committed Mar 29, 2017
1 parent a60d6a9 commit cfe4cb7
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 6 deletions.
25 changes: 25 additions & 0 deletions dactyl/filter_demote_headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
################################################################################
## Demote Headers filter ##
## Author: Rome Reginelli ##
## Copyright: Ripple Labs, Inc. 2017 ##
## ##
## Demote all headers one level. This can be useful to make PDF docs render ##
## a nice link hierarchy if your templates provide category headers at h1 but ##
## your docs individually start at the h1 level. ##
################################################################################

DEMOTE_FIELD = "demote_headers_pdf_only"

def filter_html(html, mode="html", target={}, **kwargs):
if (mode == "html" and
DEMOTE_FIELD in target and
target[DEMOTE_FIELD]):
# Don't bother then
return html

html = html.replace("<h5", "<h6")
html = html.replace("<h4", "<h5")
html = html.replace("<h3", "<h4")
html = html.replace("<h2", "<h3")
html = html.replace("<h1", "<h2")
return html
2 changes: 1 addition & 1 deletion dactyl/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.4.0a1'
__version__ = '0.4.0a2'
15 changes: 15 additions & 0 deletions examples/dactyl-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ filter_paths:
targets:
- name: everything
display_name: Target with ALL THE EXAMPLES™
filters:
- demote_headers
demote_headers_pdf_only: true

- name: filterdemos
display_name: Target with just the filter example pages
Expand All @@ -20,6 +23,12 @@ targets:
condition: tests-2

pages:
- html: tests-index.html
category: Tests
section_header: true
targets:
- everything

- md: includes.md
html: test-includes.html
category: Tests
Expand Down Expand Up @@ -48,6 +57,12 @@ pages:
targets:
- everything

- html: filters-index.html
category: Filters
section_header: true
targets:
- everything

- md: filter-examples/callouts.md
html: filter-callouts.html
category: Filters
Expand Down
22 changes: 20 additions & 2 deletions examples/template_assets/dactyl-print.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,30 @@
max-width: 650px;
}
.dactyl-pdf-cover h1,
.dactyl-pdf-cover h2,
.dactyl-pdf-cover h3 {
.dactyl-pdf-cover p {
padding: 0;
margin: 10px 0 0 0;
}

.dactyl-toc-cat a {
font-size: 18pt;
text-decoration: none;
color: black;
font-weight: bold;
margin-bottom: 10px;
}

.dactyl-section-cover {
page-break-before: always;
}

.dactyl-section-cover h1 {
font-size: 90pt;
margin-top: 40%;
padding-bottom: 10px;
border-bottom: 4px dashed black;
}

@page {
@bottom-left {
content: flow(footer);
Expand Down
5 changes: 5 additions & 0 deletions examples/templates/template-pdf.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
</head>
<body>
<footer>(Exported {{ current_time }})</footer>
{% if currentpage.section_header %}
<div class="dactyl-section-cover">
<h1>{{ currentpage.category }}</h1>
</div>
{% endif %}
<main class="dactyl-main">{{content}}</main>
</body>
</html>
8 changes: 5 additions & 3 deletions examples/templates/template-pdf_cover.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
<div class="dactyl-pdf-cover">
<section class="dactyl-pdf-title-area">
<h1>{{ target.display_name }}</h1>
<h2>{{ current_time }}</h2>
<p>{{ current_time }}</p>
</section>
</div>
<div class="dactyl-pdf-toc">
{% for cat in categories %}
<h3>{{ cat }}</h3>
<div class="dactyl-toc-cat">
<a href="{{ (pages|selectattr('category', 'equalto', cat)|first).html }}">{{ cat }}</a>
</div>
<ul>
{% for page in pages %}
{% if page.category == cat %}
{% if page.category == cat and not page.section_header %}
<li><a href="{{ page.html }}">{{ page.name }}</a></li>
{% endif %}
{% endfor %}
Expand Down

0 comments on commit cfe4cb7

Please sign in to comment.