diff options
| author | 2013-03-13 20:58:39 -0300 | |
|---|---|---|
| committer | 2013-03-13 20:58:39 -0300 | |
| commit | 8b14a1e5b2ca574fdd4fd2377567ec98a110d4b6 (patch) | |
| tree | 0895935489e4920d18824f7fb3a0d799649a27c3 /nikola/plugins/compile_rest | |
| parent | 878ba1152ebc64a4a2609d23c9e400a6111db642 (diff) | |
Imported Upstream version 5.4.2upstream/5.4.2
Diffstat (limited to 'nikola/plugins/compile_rest')
| -rw-r--r-- | nikola/plugins/compile_rest/__init__.py | 10 | ||||
| -rw-r--r-- | nikola/plugins/compile_rest/gist_directive.py | 12 | ||||
| -rw-r--r-- | nikola/plugins/compile_rest/pygments_code_block_directive.py | 39 | ||||
| -rw-r--r-- | nikola/plugins/compile_rest/slides.py | 7 | ||||
| -rw-r--r-- | nikola/plugins/compile_rest/soundcloud.py | 32 | ||||
| -rw-r--r-- | nikola/plugins/compile_rest/vimeo.py | 10 | ||||
| -rw-r--r-- | nikola/plugins/compile_rest/youtube.py | 8 |
7 files changed, 78 insertions, 40 deletions
diff --git a/nikola/plugins/compile_rest/__init__.py b/nikola/plugins/compile_rest/__init__.py index 4191add..b0a0c00 100644 --- a/nikola/plugins/compile_rest/__init__.py +++ b/nikola/plugins/compile_rest/__init__.py @@ -44,6 +44,8 @@ from .slides import slides directives.register_directive('slides', slides) from .gist_directive import GitHubGist directives.register_directive('gist', GitHubGist) +from .soundcloud import soundcloud +directives.register_directive('soundcloud', soundcloud) from nikola.plugin_categories import PageCompiler @@ -75,10 +77,10 @@ class CompileRest(PageCompiler): tags=""): with codecs.open(path, "wb+", "utf8") as fd: if onefile: - fd.write('.. title: %s\n' % title) - fd.write('.. slug: %s\n' % slug) - fd.write('.. date: %s\n' % date) - fd.write('.. tags: %s\n' % tags) + fd.write('.. title: {0}\n'.format(title)) + fd.write('.. slug: {0}\n'.format(slug)) + fd.write('.. date: {0}\n'.format(date)) + fd.write('.. tags: {0}\n'.format(tags)) fd.write('.. link: \n') fd.write('.. description: \n\n') fd.write("\nWrite your post here.") diff --git a/nikola/plugins/compile_rest/gist_directive.py b/nikola/plugins/compile_rest/gist_directive.py index 3bfe818..0ea8f23 100644 --- a/nikola/plugins/compile_rest/gist_directive.py +++ b/nikola/plugins/compile_rest/gist_directive.py @@ -24,11 +24,11 @@ class GitHubGist(Directive): has_content = False def get_raw_gist_with_filename(self, gistID, filename): - url = "https://raw.github.com/gist/%s/%s" % (gistID, filename) + url = '/'.join(("https://raw.github.com/gist", gistID, filename)) return requests.get(url).text def get_raw_gist(self, gistID): - url = "https://raw.github.com/gist/%s/" % (gistID) + url = "https://raw.github.com/gist/{0}/".format(gistID) return requests.get(url).text def run(self): @@ -43,12 +43,12 @@ class GitHubGist(Directive): if 'file' in self.options: filename = self.options['file'] rawGist = (self.get_raw_gist_with_filename(gistID, filename)) - embedHTML = ('<script src="https://gist.github.com/%s.js?file=%s">' - '</script>') % (gistID, filename) + embedHTML = ('<script src="https://gist.github.com/{0}.js' + '?file={1}"></script>').format(gistID, filename) else: rawGist = (self.get_raw_gist(gistID)) - embedHTML = ('<script src="https://gist.github.com/%s.js">' - '</script>') % gistID + embedHTML = ('<script src="https://gist.github.com/{0}.js">' + '</script>').format(gistID) return [nodes.raw('', embedHTML, format='html'), nodes.raw('', '<noscript>', format='html'), diff --git a/nikola/plugins/compile_rest/pygments_code_block_directive.py b/nikola/plugins/compile_rest/pygments_code_block_directive.py index f858427..79bada2 100644 --- a/nikola/plugins/compile_rest/pygments_code_block_directive.py +++ b/nikola/plugins/compile_rest/pygments_code_block_directive.py @@ -165,9 +165,9 @@ def code_block_directive(name, arguments, options, content, lineno, after_index = content.find(after_text)
if after_index < 0:
raise state_machine.reporter.severe(
- 'Problem with "start-at" option of "%s" '
- 'code-block directive:\nText not found.'
- % options['start-at'])
+ 'Problem with "start-at" option of "{0}" '
+ 'code-block directive:\nText not found.'.format(
+ options['start-at']))
# patch mmueller start
# Move the after_index to the beginning of the line with the
# match.
@@ -192,9 +192,9 @@ def code_block_directive(name, arguments, options, content, lineno, after_index = content.find(after_text)
if after_index < 0:
raise state_machine.reporter.severe(
- 'Problem with "start-after" option of "%s" '
- 'code-block directive:\nText not found.' %
- options['start-after'])
+ 'Problem with "start-after" option of "{0}" '
+ 'code-block directive:\nText not found.'.format(
+ options['start-after']))
line_offset = len(content[:after_index +
len(after_text)].splitlines())
content = content[after_index + len(after_text):]
@@ -207,9 +207,9 @@ def code_block_directive(name, arguments, options, content, lineno, before_index = content.find(before_text)
if before_index < 0:
raise state_machine.reporter.severe(
- 'Problem with "end-at" option of "%s" '
- 'code-block directive:\nText not found.' %
- options['end-at'])
+ 'Problem with "end-at" option of "{0}" '
+ 'code-block directive:\nText not found.'.format(
+ options['end-at']))
content = content[:before_index + len(before_text)]
before_text = options.get('end-before', None)
@@ -219,9 +219,9 @@ def code_block_directive(name, arguments, options, content, lineno, before_index = content.find(before_text)
if before_index < 0:
raise state_machine.reporter.severe(
- 'Problem with "end-before" option of "%s" '
- 'code-block directive:\nText not found.' %
- options['end-before'])
+ 'Problem with "end-before" option of "{0}" '
+ 'code-block directive:\nText not found.'.format(
+ options['end-before']))
content = content[:before_index]
else:
@@ -246,8 +246,9 @@ def code_block_directive(name, arguments, options, content, lineno, lineno = 1 + line_offset
total_lines = content.count('\n') + 1 + line_offset
lnwidth = len(str(total_lines))
- fstr = "\n%%%dd " % lnwidth
- code_block += nodes.inline(fstr[1:] % lineno, fstr[1:] % lineno,
+ fstr = "\n%{0}d ".format(lnwidth)
+ code_block += nodes.inline(fstr[1:].format(lineno),
+ fstr[1:].format(lineno),
classes=['linenumber'])
# parse content with pygments and add to code_block element
@@ -272,7 +273,8 @@ def code_block_directive(name, arguments, options, content, lineno, linenos = list(range(lineno, lineno + len(values)))
for chunk, ln in zip(values, linenos)[1:]:
if ln <= total_lines:
- code_block += nodes.inline(fstr % ln, fstr % ln,
+ code_block += nodes.inline(fstr.format(ln),
+ fstr.format(ln),
classes=['linenumber'])
code_block += nodes.Text(chunk, chunk)
lineno += len(values) - 1
@@ -319,8 +321,8 @@ def string_bool(argument): elif argument.lower() == 'false':
return False
else:
- raise ValueError('"%s" unknown; choose from "True" or "False"' %
- argument)
+ raise ValueError('"{0}" unknown; choose from "True" or "False"'.format(
+ argument))
def csharp_unicodelevel(argument):
@@ -340,7 +342,8 @@ def listings_directive(name, arguments, options, content, lineno, fname = arguments[0]
options['include'] = os.path.join('listings', fname)
target = urlunsplit(("link", 'listing', fname, '', ''))
- generated_nodes = [core.publish_doctree('`%s <%s>`_' % (fname, target))[0]]
+ generated_nodes = [core.publish_doctree('`{0} <{1}>`_'.format(fname,
+ target))[0]]
generated_nodes += code_block_directive(name, [arguments[1]], options,
content, lineno, content_offset,
block_text, state, state_machine)
diff --git a/nikola/plugins/compile_rest/slides.py b/nikola/plugins/compile_rest/slides.py index c9d55f3..f9901f5 100644 --- a/nikola/plugins/compile_rest/slides.py +++ b/nikola/plugins/compile_rest/slides.py @@ -77,12 +77,13 @@ class slides(Directive): options.update(self.options) options = json.dumps(options) output = [] - output.append('<script> $(function(){ $("#slides").slides(%s); });' - '</script>' % options) + output.append('<script> $(function(){ $("#slides").slides(' + options + + '); });' + '</script>') output.append('<div id="slides" class="slides"><div ' 'class="slides_container">') for image in self.content: - output.append("""<div><img src="%s"></div>""" % image) + output.append("""<div><img src="{0}"></div>""".format(image)) output.append("""</div></div>""") return [nodes.raw('', '\n'.join(output), format='html')] diff --git a/nikola/plugins/compile_rest/soundcloud.py b/nikola/plugins/compile_rest/soundcloud.py new file mode 100644 index 0000000..d47bebf --- /dev/null +++ b/nikola/plugins/compile_rest/soundcloud.py @@ -0,0 +1,32 @@ +from docutils import nodes +from docutils.parsers.rst import directives + +CODE = ("""<iframe width="{width}" height="{height}" +scrolling="no" frameborder="no" +src="https://w.soundcloud.com/player/?url=http://api.soundcloud.com/tracks/""" + """{sid}"> +</iframe>""") + + +def soundcloud(name, args, options, content, lineno, + contentOffset, blockText, state, stateMachine): + """ Restructured text extension for inserting SoundCloud embedded music """ + string_vars = { + 'sid': content[0], + 'width': 600, + 'height': 160, + 'extra': '' + } + extra_args = content[1:] # Because content[0] is ID + extra_args = [ea.strip().split("=") for ea in extra_args] # key=value + extra_args = [ea for ea in extra_args if len(ea) == 2] # drop bad lines + extra_args = dict(extra_args) + if 'width' in extra_args: + string_vars['width'] = extra_args.pop('width') + if 'height' in extra_args: + string_vars['height'] = extra_args.pop('height') + + return [nodes.raw('', CODE.format(**string_vars), format='html')] + +soundcloud.content = True +directives.register_directive('soundcloud', soundcloud) diff --git a/nikola/plugins/compile_rest/vimeo.py b/nikola/plugins/compile_rest/vimeo.py index 3eefcc4..34f2a50 100644 --- a/nikola/plugins/compile_rest/vimeo.py +++ b/nikola/plugins/compile_rest/vimeo.py @@ -37,8 +37,8 @@ except ImportError: except ImportError: json = None -CODE = """<iframe src="http://player.vimeo.com/video/%(vimeo_id)s" -width="%(width)s" height="%(height)s" +CODE = """<iframe src="http://player.vimeo.com/video/{vimeo_id}" +width="{width}" height="{height}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen> </iframe> """ @@ -76,8 +76,8 @@ def vimeo(name, args, options, content, lineno, contentOffset, blockText, if json: # we can attempt to retrieve video attributes from vimeo try: - url = ('http://vimeo.com/api/v2/video/%(vimeo_id)s.json' % - string_vars) + url = ('http://vimeo.com/api/v2/video/{vimeo_id}' + '.json'.format(**string_vars)) data = requests.get(url).text video_attributes = json.loads(data) string_vars['height'] = video_attributes['height'] @@ -86,7 +86,7 @@ def vimeo(name, args, options, content, lineno, contentOffset, blockText, # fall back to the defaults pass - return [nodes.raw('', CODE % string_vars, format='html')] + return [nodes.raw('', CODE.format(**string_vars), format='html')] vimeo.content = True directives.register_directive('vimeo', vimeo) diff --git a/nikola/plugins/compile_rest/youtube.py b/nikola/plugins/compile_rest/youtube.py index fe3b28b..30ac000 100644 --- a/nikola/plugins/compile_rest/youtube.py +++ b/nikola/plugins/compile_rest/youtube.py @@ -26,9 +26,9 @@ from docutils import nodes from docutils.parsers.rst import directives CODE = """\ -<iframe width="%(width)s" -height="%(height)s" -src="http://www.youtube.com/embed/%(yid)s?rel=0&hd=1&wmode=transparent" +<iframe width="{width}" +height="{height}" +src="http://www.youtube.com/embed/{yid}?rel=0&hd=1&wmode=transparent" ></iframe>""" @@ -51,6 +51,6 @@ def youtube(name, args, options, content, lineno, string_vars['width'] = extra_args.pop('width') if 'height' in extra_args: string_vars['height'] = extra_args.pop('height') - return [nodes.raw('', CODE % (string_vars), format='html')] + return [nodes.raw('', CODE.format(**string_vars), format='html')] youtube.content = True directives.register_directive('youtube', youtube) |
