diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-02-27 23:02:17 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-02-27 23:02:17 +0100 |
| commit | 421adbea75c5a4282630a7399f8b1018c4f0dd90 (patch) | |
| tree | b93aa014016bc21381a0a3b05bc56909ce0bee1d /megapixels/app/site | |
| parent | 9bac173e85865e4f0d1dba5071b40eb7ebe3dd1a (diff) | |
parser
Diffstat (limited to 'megapixels/app/site')
| -rw-r--r-- | megapixels/app/site/parser.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/megapixels/app/site/parser.py b/megapixels/app/site/parser.py index dc53177b..98d9f284 100644 --- a/megapixels/app/site/parser.py +++ b/megapixels/app/site/parser.py @@ -16,7 +16,9 @@ def parse_markdown(metadata, sections, s3_path, skip_h1=False): """ groups = [] current_group = [] + footnotes = [] in_stats = False + ignoring = False if 'desc' in metadata and 'subdesc' in metadata: groups.append(intro_section(metadata, s3_path)) @@ -27,7 +29,16 @@ def parse_markdown(metadata, sections, s3_path, skip_h1=False): elif section.strip().startswith('---'): continue elif section.lower().strip().startswith('ignore text'): - break + ignoring = True + continue + elif section.strip().startswith('### Footnotes'): + groups.append(format_section(current_group, s3_path)) + footnotes = [] + in_footnotes = True + elif in_footnotes: + footnotes.append(section) + elif ignoring: + continue elif '### Statistics' in section: if len(current_group): groups.append(format_section(current_group, s3_path)) @@ -70,9 +81,14 @@ def parse_markdown(metadata, sections, s3_path, skip_h1=False): else: current_group.append(section) groups.append(format_section(current_group, s3_path)) + + if len(footnotes): + groups.append(format_footnotes(footnotes, s3_path)) + content = "".join(groups) return content + def intro_section(metadata, s3_path): """ Build the intro section for datasets @@ -100,6 +116,7 @@ def intro_section(metadata, s3_path): return section + def fix_images(lines, s3_path): """ do our own tranformation of the markdown around images to handle wide images etc @@ -122,6 +139,7 @@ def fix_images(lines, s3_path): real_lines.append(line) return "\n".join(real_lines) + def format_section(lines, s3_path, type='', tag='section'): """ format a normal markdown section @@ -135,6 +153,7 @@ def format_section(lines, s3_path, type='', tag='section'): return "<{}>{}</{}>".format(tag, markdown(lines), tag) return "" + def fix_meta(lines): new_lines = [] for line in lines: @@ -143,6 +162,7 @@ def fix_meta(lines): new_lines.append(line) return new_lines + def format_metadata(section): """ format a metadata section (+ key: value pairs) @@ -153,6 +173,13 @@ def format_metadata(section): meta.append("<div><div class='gray'>{}</div><div>{}</div></div>".format(key, value)) return "<div class='meta'>{}</div>".format(''.join(meta)) +def format_footnotes(footnotes): + footnotes = '\n'.join(footnotes).split('\n') + for footnote in footnotes: + if not len(footnote) or '[^' not in footnote: + continue + key, footnote = footnotes.split(': ') + def format_applet(section, s3_path): """ Format the applets, which load javascript modules like the map and CSVs |
