Skip to content

Commit

Permalink
Treat the metadata abstract as ReStructured text
Browse files Browse the repository at this point in the history
Abstracts in XML metadata retrieved from the Discovery Web Service are
treated as being in ReStructured Text (RST) format.  This is converted
to HTML in the full and KML renderings of a metadata entry.

Interpreting abstracts as RST should not affect existing metadata
other than improve formatting in many cases.  It will, however, allow
future metadata production to take advantage of the formatting
conventions provided by RST whilst still maintaining a human readable
output to the raw XML metadata.
  • Loading branch information
Homme Zwaagstra committed Sep 24, 2014
1 parent 382222b commit ee511a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 9 additions & 0 deletions python/medin/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# You can obtain a full copy of the RPL from
# http://opensource.org/licenses/rpl1.5.txt or [email protected]

from docutils import core

"""
Filters used in Mako templates.
Expand All @@ -37,3 +39,10 @@ def quote(text):
if ' ' in text:
return '"' + text + '"'
return text

def rst2html(rst):
"""Convert restructured text into a HTML fragment"""
# taken from <https://wiki.python.org/moin/ReStructuredText>

parts = core.publish_parts(source=rst, writer_name='html')
return parts['body_pre_docinfo']+parts['fragment']
4 changes: 2 additions & 2 deletions templates/full/metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<%namespace import="search_criteria" file="search-common.html"/>
<%inherit file="base-ok.html"/>\
<%!
from medin.filters import quote as q
from medin.filters import quote as q, rst2html
from medin.metadata import Year, YearMonth
%>

Expand Down Expand Up @@ -361,7 +361,7 @@ <h3>Geographic Extent</h3>

<h2>Overview</h2>

<p><strong>Abstract:</strong> ${metadata.abstract}</p>
<div><strong>Abstract:</strong> ${metadata.abstract | rst2html}</div>

<p><strong>Data holder:</strong> ${', '.join(custodians) or 'Unknown'}</p>

Expand Down
6 changes: 3 additions & 3 deletions templates/kml/catalogue/metadata-base.kml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
http://opensource.org/licenses/rpl1.5.txt or [email protected]
</%doc>\
<%!
from medin.filters import rst2html
template = ""
%><?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
Expand All @@ -50,9 +52,7 @@
<name>${title | x}</name>
<description>
<![CDATA[
<p>
${abstract | x}
</p>
${abstract | rst2html}
<p>Further metadata details are available <a href="${script_root}/${self.attr.template}/catalogue/${gid | x}" title="Full metadata details">here</a>.</p>
Expand Down

0 comments on commit ee511a8

Please sign in to comment.