diff options
Diffstat (limited to 'nikola/plugins/compile/rest')
| -rw-r--r-- | nikola/plugins/compile/rest/__init__.py | 34 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/chart.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/doc.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/listing.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/media.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/post_list.py | 5 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/slides.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/soundcloud.py | 9 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/template.txt | 8 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/vimeo.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/youtube.py | 2 |
11 files changed, 57 insertions, 13 deletions
diff --git a/nikola/plugins/compile/rest/__init__.py b/nikola/plugins/compile/rest/__init__.py index c71a5f8..50b37cf 100644 --- a/nikola/plugins/compile/rest/__init__.py +++ b/nikola/plugins/compile/rest/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -35,10 +35,16 @@ try: import docutils.utils import docutils.io import docutils.readers.standalone + import docutils.writers.html4css1 has_docutils = True except ImportError: has_docutils = False +try: + from collections import OrderedDict +except ImportError: + OrderedDict = None # NOQA + from nikola.plugin_categories import PageCompiler from nikola.utils import get_logger, makedirs, req_missing @@ -47,6 +53,7 @@ class CompileRest(PageCompiler): """Compile reSt into HTML.""" name = "rest" + demote_headers = True logger = None def compile_html(self, source, dest, is_two_file=True): @@ -71,14 +78,16 @@ class CompileRest(PageCompiler): # author). add_ln = len(spl[0].splitlines()) + 1 + default_template_path = os.path.join(os.path.dirname(__file__), 'template.txt') output, error_level, deps = rst2html( data, settings_overrides={ - 'initial_header_level': 2, + 'initial_header_level': 1, 'record_dependencies': True, 'stylesheet_path': None, 'link_stylesheet': True, 'syntax_highlight': 'short', 'math_output': 'mathjax', + 'template': default_template_path, }, logger=self.logger, l_source=source, l_add_ln=add_ln) out_file.write(output) deps_path = dest + '.dep' @@ -94,7 +103,10 @@ class CompileRest(PageCompiler): return False def create_post(self, path, onefile=False, **kw): - metadata = {} + if OrderedDict is not None: + metadata = OrderedDict() + else: + metadata = {} metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) @@ -117,6 +129,9 @@ class CompileRest(PageCompiler): plugin_info.plugin_object.short_help = plugin_info.description self.logger = get_logger('compile_rest', site.loghandlers) + if not site.debug: + self.logger.level = 4 + return super(CompileRest, self).set_site(site) @@ -139,7 +154,10 @@ def get_observer(settings): """ errormap = {0: 1, 1: 2, 2: 4, 3: 5, 4: 6} text = docutils.nodes.Element.astext(msg) - out = '[{source}:{line}] {text}'.format(source=settings['source'], line=msg['line'] + settings['add_ln'], text=text) + line = msg['line'] + settings['add_ln'] if 'line' in msg else 0 + out = '[{source}{colon}{line}] {text}'.format( + source=settings['source'], colon=(':' if line else ''), + line=line, text=text) settings['logger'].log(errormap[msg['level']], out) return observer @@ -155,6 +173,14 @@ class NikolaReader(docutils.readers.standalone.Reader): return document +def add_node(node, visit_function=None, depart_function=None): + docutils.nodes._add_node_class_names([node.__name__]) + if visit_function: + setattr(docutils.writers.html4css1.HTMLTranslator, 'visit_' + node.__name__, visit_function) + if depart_function: + setattr(docutils.writers.html4css1.HTMLTranslator, 'depart_' + node.__name__, depart_function) + + def rst2html(source, source_path=None, source_class=docutils.io.StringInput, destination_path=None, reader=None, parser=None, parser_name='restructuredtext', writer=None, diff --git a/nikola/plugins/compile/rest/chart.py b/nikola/plugins/compile/rest/chart.py index ee917b9..03878a3 100644 --- a/nikola/plugins/compile/rest/chart.py +++ b/nikola/plugins/compile/rest/chart.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/compile/rest/doc.py b/nikola/plugins/compile/rest/doc.py index 915a7e1..a150a81 100644 --- a/nikola/plugins/compile/rest/doc.py +++ b/nikola/plugins/compile/rest/doc.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/compile/rest/listing.py b/nikola/plugins/compile/rest/listing.py index 31975bb..ecf885f 100644 --- a/nikola/plugins/compile/rest/listing.py +++ b/nikola/plugins/compile/rest/listing.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/compile/rest/media.py b/nikola/plugins/compile/rest/media.py index d1930dd..ccda559 100644 --- a/nikola/plugins/compile/rest/media.py +++ b/nikola/plugins/compile/rest/media.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/compile/rest/post_list.py b/nikola/plugins/compile/rest/post_list.py index eae4016..6804b58 100644 --- a/nikola/plugins/compile/rest/post_list.py +++ b/nikola/plugins/compile/rest/post_list.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2013 Udo Spallek, Roberto Alsina and others. +# Copyright © 2013-2014 Udo Spallek, Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -33,6 +33,9 @@ from docutils.parsers.rst import Directive, directives from nikola import utils from nikola.plugin_categories import RestExtension +# WARNING: the directive name is post-list +# (with a DASH instead of an UNDERSCORE) + class Plugin(RestExtension): name = "rest_post_list" diff --git a/nikola/plugins/compile/rest/slides.py b/nikola/plugins/compile/rest/slides.py index 41c3314..203ae51 100644 --- a/nikola/plugins/compile/rest/slides.py +++ b/nikola/plugins/compile/rest/slides.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/compile/rest/soundcloud.py b/nikola/plugins/compile/rest/soundcloud.py index 6fb3e99..a26806c 100644 --- a/nikola/plugins/compile/rest/soundcloud.py +++ b/nikola/plugins/compile/rest/soundcloud.py @@ -15,12 +15,13 @@ class Plugin(RestExtension): def set_site(self, site): self.site = site directives.register_directive('soundcloud', SoundCloud) + directives.register_directive('soundcloud_playlist', SoundCloudPlaylist) return super(Plugin, self).set_site(site) CODE = ("""<iframe width="{width}" height="{height}" scrolling="no" frameborder="no" -src="https://w.soundcloud.com/player/?url=http://api.soundcloud.com/tracks/""" +src="https://w.soundcloud.com/player/?url=http://api.soundcloud.com/{preslug}/""" """{sid}"> </iframe>""") @@ -40,6 +41,7 @@ class SoundCloud(Directive): 'width': directives.positive_int, 'height': directives.positive_int, } + preslug = "tracks" def run(self): """ Required by the Directive interface. Create docutils nodes """ @@ -48,6 +50,7 @@ class SoundCloud(Directive): 'sid': self.arguments[0], 'width': 600, 'height': 160, + 'preslug': self.preslug, } options.update(self.options) return [nodes.raw('', CODE.format(**options), format='html')] @@ -58,3 +61,7 @@ class SoundCloud(Directive): raise self.warning("This directive does not accept content. The " "'key=value' format for options is deprecated, " "use ':key: value' instead") + + +class SoundCloudPlaylist(SoundCloud): + preslug = "playlists" diff --git a/nikola/plugins/compile/rest/template.txt b/nikola/plugins/compile/rest/template.txt new file mode 100644 index 0000000..2591bce --- /dev/null +++ b/nikola/plugins/compile/rest/template.txt @@ -0,0 +1,8 @@ +%(head_prefix)s +%(head)s +%(stylesheet)s +%(body_prefix)s +%(body_pre_docinfo)s +%(docinfo)s +%(body)s +%(body_suffix)s diff --git a/nikola/plugins/compile/rest/vimeo.py b/nikola/plugins/compile/rest/vimeo.py index 6d66648..82c4dc1 100644 --- a/nikola/plugins/compile/rest/vimeo.py +++ b/nikola/plugins/compile/rest/vimeo.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/compile/rest/youtube.py b/nikola/plugins/compile/rest/youtube.py index 3d4bdd3..19e12d1 100644 --- a/nikola/plugins/compile/rest/youtube.py +++ b/nikola/plugins/compile/rest/youtube.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated |
