diff options
author | rsiddharth <rsd@gnu.org> | 2016-02-13 18:54:22 -0500 |
---|---|---|
committer | rsiddharth <rsd@gnu.org> | 2016-02-13 18:54:22 -0500 |
commit | 70126d67549ad060ab8f01cab6fabf31516bcf01 (patch) | |
tree | 56f85956c1ad106c64d85bbf216e842ec1b09686 /lps_gen.py | |
parent | 0c4dad844c1bacc5d4fcd78ec46239654d576617 (diff) |
Autolinking of speakers in sessions page ready.
If "John Hacker" is the speaker that has to be autolinked in the
sessions MD file; the markup to autolink is [John Hacker]().
[John Hacker]() -> <a href="speakers.html#hacker">John Hacker</a>, if id
for "John Hacker" is available in the `speaker.ids` file[1].
[1]: The `speakers.ids` file is automatically written to the disk (in
the current working directory) when the speakers' bio page is generated.
List of speakers that are autolinked but don't have an id, are written
to the `speakers.noid` file when the sessions page is generated.
Addresses issue #7.
Diffstat (limited to 'lps_gen.py')
-rw-r--r-- | lps_gen.py | 57 |
1 files changed, 54 insertions, 3 deletions
@@ -117,6 +117,51 @@ class LPSRenderer(Renderer): # "room" and session "description". self.no_paragraph = None + # Contains a list of speakers' names which are marked up for + # auto-linking[1], but don't have an id to link to. + # + # [1]: Markup for auto-linking speakers is [John Hacker](). + self.speakers_noids = [] + + # If it is 'False', then the 'speaker.ids' file was not found; + # otherwise it is an OrderedDict containing the mapping of + # speakers and their corresponding id. + self.speakers_ids = json_read('speakers.ids') + + + def get_uid(self, speaker): + """Returns unique id for `speaker` if it exists; `False` otherwise. + """ + if not self.speakers_ids: + # There is no speakers_ids OrderedDict available. + return False + + speaker = unicode(speaker) + if speaker in self.speakers_ids.keys(): + return self.speakers_ids[speaker] + else: + # speaker not found in speakers_ids OrderedDict. + return False + + + def link(self, link, title, text): + # Here, we catch speaker names that have to be autolinked and + # autolink them if there is an id available for the speaker. + if not link: + # We found a speaker that has to be autolinked. + + # Here, `text` is the speaker' name. + id_ = self.get_uid(text) + if id_: + link = 'speakers.html#%s' % id_ + else: + # Oh no, there is no id for this speaker. + self.speakers_noids.append(text) + # Don't linkify this speaker; they don't have an id. + return text + + return super(LPSRenderer, self).link(link, title, text) + def header(self, text, level, raw=None): global lps_dict @@ -261,9 +306,11 @@ class LPSMarkdown(Markdown): """ Initialize with LPSRenderer as the renderer. """ - super(LPSMarkdown, self).__init__(renderer=LPSRenderer(), - inline=None, block=None, - **kwargs) + self.sessions_renderer = LPSRenderer() + super(LPSMarkdown, self).__init__( + renderer=self.sessions_renderer, + inline=None, block=None, + **kwargs) def parse(self, text): @@ -271,6 +318,10 @@ class LPSMarkdown(Markdown): lps_dict = OrderedDict() html = super(LPSMarkdown, self).parse(text) + + # Write list of speakers with no ids to `speakers.noids`. + json_write('speakers.noids', self.sessions_renderer.speakers_noids) + return lps_dict |