Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.

Commit 8b851db

Browse files
guymersdavidzchen
authored andcommitted
Markdown format updates (#8)
- Fix syntax error in markdown template - Only convert text to markdown if html format is being used - Add a few blank lines for markdown - Update the overview section so it uses markdown instead of html
1 parent 0713d0e commit 8b851db

File tree

9 files changed

+39
-41
lines changed

9 files changed

+39
-41
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bazel-*

skydoc/main.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import gflags
1919
import jinja2
20+
import mistune
2021
import os
2122
import re
2223
import shutil
@@ -54,6 +55,14 @@
5455
CSS_FILE = 'main.css'
5556
CSS_DIR = 'css'
5657

58+
def _create_jinja_environment():
59+
env = jinja2.Environment(
60+
loader=jinja2.FileSystemLoader(_runfile_path(TEMPLATE_PATH)),
61+
keep_trailing_newline=True,
62+
line_statement_prefix='%')
63+
env.filters['markdown'] = lambda text: jinja2.Markup(mistune.markdown(text))
64+
return env
65+
5766

5867
# TODO(dzc): Remove this workaround once we switch to a self-contained Python
5968
# binary format such as PEX.
@@ -135,9 +144,7 @@ def write(self, rulesets):
135144

136145
def _write_ruleset(self, output_dir, ruleset):
137146
# Load template and render Markdown.
138-
env = jinja2.Environment(
139-
loader=jinja2.FileSystemLoader(_runfile_path(TEMPLATE_PATH)),
140-
line_statement_prefix='%')
147+
env = _create_jinja_environment()
141148
template = env.get_template('markdown.jinja')
142149
out = template.render(ruleset=ruleset)
143150

@@ -154,9 +161,7 @@ def __init__(self, output_dir, output_file, output_zip):
154161
self.__output_dir = output_dir
155162
self.__output_file = output_file
156163
self.__output_zip = output_zip
157-
self.__env = jinja2.Environment(
158-
loader=jinja2.FileSystemLoader(_runfile_path(TEMPLATE_PATH)),
159-
line_statement_prefix='%')
164+
self.__env = _create_jinja_environment()
160165

161166
def write(self, rulesets):
162167
# Generate navigation used for all rules.

skydoc/rule.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"""Representations used for rendering documentation templates."""
1616

1717

18-
import mistune
1918
from skydoc import build_pb2
2019

2120

@@ -34,7 +33,7 @@ def __init__(self, proto):
3433
if proto.name == 'name' and not proto.documentation:
3534
self.documentation = 'A unique name for this rule.'
3635
else:
37-
self.documentation = mistune.markdown(proto.documentation)
36+
self.documentation = proto.documentation
3837

3938
def _get_type_str(self, proto):
4039
type_str = ''
@@ -90,17 +89,17 @@ class Output(object):
9089

9190
def __init__(self, proto):
9291
self.__proto = proto
93-
self.template = mistune.markdown(proto.template)
94-
self.documentation = mistune.markdown(proto.documentation)
92+
self.template = proto.template
93+
self.documentation = proto.documentation
9594

9695
class Rule(object):
9796
"""Representation of a rule used to render documentation templates."""
9897

9998
def __init__(self, proto):
10099
self.__proto = proto
101100
self.name = proto.name
102-
self.documentation = mistune.markdown(proto.documentation)
103-
self.example_documentation = mistune.markdown(proto.example_documentation)
101+
self.documentation = proto.documentation
102+
self.example_documentation = proto.example_documentation
104103
self.signature = self._get_signature(proto)
105104
self.attributes = []
106105
for attribute in proto.attribute:

skydoc/templates/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ filegroup(
88
"markdown.jinja",
99
"nav.jinja",
1010
"outputs.jinja",
11-
"overview.jinja",
1211
"toc.jinja",
1312
],
1413
)

skydoc/templates/attributes.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ limitations under the License.
2424
<td><code>{{ attribute.name }}</code></td>
2525
<td>
2626
<p><code>{{ attribute.type }}</code></p>
27-
{{ attribute.documentation }}
27+
{{ attribute.documentation|markdown|trim }}
2828
</td>
2929
</tr>
3030
% endfor

skydoc/templates/html.jinja

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,19 @@ Documentation generated by Skydoc
5252
<div class="page-content">
5353
<h1>{{ ruleset.title }}</h1>
5454
% include "toc.jinja"
55-
% include "overview.jinja"
55+
% if ruleset.description:
56+
<hr>
57+
<h2 id="overview">Overview<h2>
58+
{{ ruleset.description|markdown }}
59+
% endif
5660
% for rule in ruleset.rules
5761
<hr>
5862

5963
<h2 id="{{ rule.name }}">{{ rule.name }}</h2>
6064

6165
<pre>{{ rule.signature }}</pre>
6266

63-
{{ rule.documentation }}
67+
{{ rule.documentation|markdown }}
6468

6569
% if rule.outputs[0] is defined:
6670
<h3 id="{{ rule.name }}_outputs">
@@ -76,7 +80,7 @@ Documentation generated by Skydoc
7680

7781
% if rule.example_documentation
7882
<h3 id="{{ rule.name }}_examples">Examples</h3>
79-
{{ rule.example_documentation }}
83+
{{ rule.example_documentation|markdown }}
8084
% endif
8185

8286
% endfor

skydoc/templates/markdown.jinja

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ Documentation generated by Skydoc
1919
<h1>{{ ruleset.title }}</h1>
2020

2121
% include "toc.jinja"
22-
% include "overview.jinja"
22+
23+
% if ruleset.description:
24+
<hr>
25+
26+
<a name="overview"></a>
27+
## Overview
28+
29+
{{ ruleset.description }}
30+
{# I want a blank line here #}
31+
% endif
2332

2433
% for rule in ruleset.rules:
2534
<a name="{{ rule.name }}"></a>
@@ -32,20 +41,23 @@ Documentation generated by Skydoc
3241
{{ rule.documentation }}
3342

3443
% if rule.outputs[0] is defined:
44+
{# I want a blank line here #}
3545
<a name="{{ rule.name }}_outputs"></a>
3646
### Outputs
3747

3848
% include "outputs.jinja"
3949
% endif
4050

4151
% if rule.attributes[0] is defined:
52+
{# I want a blank line here #}
4253
<a name="{{ rule.name }}_args"></a>
4354
### Attributes
4455

4556
% include "attributes.jinja"
4657
% endif
4758

4859
% if rule.example_documentation
60+
{# I want a blank line here #}
4961
<a name="{{ rule.name }}_examples"></a>
5062
### Examples
5163

skydoc/templates/outputs.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ limitations under the License.
2323
<tr>
2424
<td><code>{{ output.template }}</code></td>
2525
<td>
26-
{{ output.documentation }}
26+
{{ output.documentation|markdown|trim }}
2727
</td>
2828
</tr>
2929
% endfor

skydoc/templates/overview.jinja

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)