Merge lp:~dholbach/help-app/1430735-pt1 into lp:~ubuntu-touch-coreapps-drivers/help-app/trunk

Proposed by Daniel Holbach
Status: Merged
Merged at revision: 98
Proposed branch: lp:~dholbach/help-app/1430735-pt1
Merge into: lp:~ubuntu-touch-coreapps-drivers/help-app/trunk
Diff against target: 133 lines (+94/-5)
3 files modified
edit-here/pelicanconf.py (+15/-1)
edit-here/q-and-a.py (+77/-0)
edit-here/translations.py (+2/-4)
To merge this branch: bzr merge lp:~dholbach/help-app/1430735-pt1
Reviewer Review Type Date Requested Status
Nicholas Skaggs (community) Approve
Review via email: mp+253164@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

With the idea of perhaps making this better later, let's land this and move forward. Thanks Daniel!

review: Approve
Revision history for this message
Daniel Holbach (dholbach) wrote :

I'll start landing this now. I filed bug 1433136 to track this. Let's look at this for 0.2.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'edit-here/pelicanconf.py'
2--- edit-here/pelicanconf.py 2015-03-10 10:56:31 +0000
3+++ edit-here/pelicanconf.py 2015-03-17 09:03:52 +0000
4@@ -44,4 +44,18 @@
5 TAG_SAVE_AS = ''
6 THEME = 'themes/phone'
7
8-MD_EXTENSIONS = ['toc']
9+MD_EXTENSIONS = ['q-and-a', 'attr_list', 'toc']
10+
11+META_TAGS = [
12+ '[TOC]',
13+]
14+
15+Q_AND_A_CLASSES = [
16+ '!!T',
17+ '!!I',
18+]
19+
20+HIDE_FROM_POT = Q_AND_A_CLASSES + [
21+ '{: .link-cta-ubuntu }',
22+ '{: .link-cta-ubuntu}',
23+]
24
25=== added file 'edit-here/q-and-a.py'
26--- edit-here/q-and-a.py 1970-01-01 00:00:00 +0000
27+++ edit-here/q-and-a.py 2015-03-17 09:03:52 +0000
28@@ -0,0 +1,77 @@
29+from __future__ import absolute_import
30+from __future__ import unicode_literals
31+from markdown import Extension
32+from markdown.blockprocessors import BlockProcessor
33+from markdown.util import etree
34+import re
35+
36+from pelicanconf import Q_AND_A_CLASSES
37+
38+
39+class QandAExtension(Extension):
40+ def extendMarkdown(self, md, md_globals):
41+ md.registerExtension(self)
42+ md.parser.blockprocessors.add('q-and-a',
43+ QandAProcessor(md.parser),
44+ '_begin')
45+
46+
47+class QandAProcessor(BlockProcessor):
48+ statements = r'|'.join(Q_AND_A_CLASSES)
49+ RE = re.compile(r'(.*)\s*?(%s)\s*?' % statements)
50+
51+ def test(self, parent, block):
52+ # [('How do I update my system?', '!!T')]
53+ matches = self.RE.search(block)
54+ if matches:
55+ return matches
56+ return False
57+
58+ def run(self, parent, blocks):
59+ block = blocks.pop(0)
60+ matches = self.RE.search(block)
61+ statement = matches.group(2)
62+ block = block.replace(statement, '')
63+ question = block.split('\n')[0]
64+ answer = '\n'.join(block.split('\n')[1:])
65+
66+ if statement == '!!T':
67+ # <div class="row">
68+ # <div class="eight-col last-col">
69+ # <!-- question & answer -->
70+ # </div>
71+ # </div>
72+ div = etree.SubElement(parent, 'div')
73+ div.set('class', 'row')
74+ div2 = etree.SubElement(div, 'div')
75+ div2.set('class', 'eight-col last-col')
76+ self.parser.parseChunk(div2, question)
77+ self.parser.parseChunk(div2, answer)
78+ elif statement == '!!I':
79+ # <div class="row">
80+ # <div class="eight-col">
81+ # <!-- question & answer -->
82+ # </div>
83+ # <div class="four-col last-col">
84+ # <!-- question & answer -->
85+ # </div>
86+ # </div>
87+ image_block = "..."
88+ # XXX: we need to figure out how to parse if an image is
89+ # there, etc.
90+ div = etree.SubElement(parent, 'div')
91+ div.set('class', 'row')
92+ text_div = etree.SubElement(div, 'div')
93+ text_div.set('class', 'eight-col')
94+ img_div = etree.SubElement(div, 'div')
95+ img_div.set('class', 'four-col last-col')
96+ self.parser.parseChunk(text_div, question)
97+ self.parser.parseChunk(text_div, answer)
98+ self.parser.parseChunk(img_div, image_block)
99+ else:
100+ sibling = self.lastChild(parent)
101+ self.parser.parseChunk(sibling, block)
102+
103+
104+def makeExtension(*args, **kwargs):
105+ return QandAExtension(*args, **kwargs)
106
107=== modified file 'edit-here/translations.py'
108--- edit-here/translations.py 2015-03-12 16:30:29 +0000
109+++ edit-here/translations.py 2015-03-17 09:03:52 +0000
110@@ -29,7 +29,7 @@
111 except:
112 require('python3-markdown')
113
114-from pelicanconf import PATH, MD_EXTENSIONS
115+from pelicanconf import PATH, MD_EXTENSIONS, META_TAGS
116
117 # This defines how complete we expect translations to be before we
118 # generate HTML from them. Needs to be string.
119@@ -40,13 +40,11 @@
120 ('zh_TW', 'zh-hant'),
121 )
122
123-META_TAGS = ['[TOC]']
124-
125 MD_MAGIC_FILE_TYPES = [
126 'ASCII text',
127 'UTF-8 Unicode text',
128 'UTF-8 Unicode text, with very long lines',
129- ]
130+]
131
132
133 def _temp_write_markdown(fn):

Subscribers

People subscribed via source and target branches