diff options
| author | 2021-12-04 22:39:11 -0500 | |
|---|---|---|
| committer | 2021-12-04 22:39:11 -0500 | |
| commit | fd4d5145ab7a29c62d97c7aaec0ec70cca7a9738 (patch) | |
| tree | b63c6548647f206d4fde4ed0b94c734a4f86bdad /plugins/asciidoc | |
| parent | 4367aec103dc55822f72f7e2c73ed9e3fd4c669b (diff) | |
Update from nikola 8.x template, update asciidoc plugin.
Diffstat (limited to 'plugins/asciidoc')
| -rw-r--r-- | plugins/asciidoc/README.md | 4 | ||||
| -rw-r--r-- | plugins/asciidoc/asciidoc.plugin | 5 | ||||
| -rw-r--r-- | plugins/asciidoc/asciidoc.py | 64 | ||||
| -rw-r--r-- | plugins/asciidoc/conf.py.sample | 7 |
4 files changed, 59 insertions, 21 deletions
diff --git a/plugins/asciidoc/README.md b/plugins/asciidoc/README.md index 44c1cb2..556f12f 100644 --- a/plugins/asciidoc/README.md +++ b/plugins/asciidoc/README.md @@ -1,5 +1,9 @@ Compiler plugin to support the AsciiDoc markup. +Example usage of Nikola's *path handlers* in Asciidoc: + + link:link://slug/demo-page[Click here to go to the demo page] + [More information about AsciiDoc](http://www.methods.co.nz/asciidoc/) diff --git a/plugins/asciidoc/asciidoc.plugin b/plugins/asciidoc/asciidoc.plugin index dfc4c9f..f0ae6eb 100644 --- a/plugins/asciidoc/asciidoc.plugin +++ b/plugins/asciidoc/asciidoc.plugin @@ -2,8 +2,11 @@ Name = asciidoc Module = asciidoc +[Nikola] +PluginCategory = PageCompiler + [Documentation] Author = Roberto Alsina -Version = 0.3 +Version = 0.6 Website = http://plugins.getnikola.com/#asciidoc Description = Compile ASCIIDoc into HTML diff --git a/plugins/asciidoc/asciidoc.py b/plugins/asciidoc/asciidoc.py index 1a35c00..b7be3ef 100644 --- a/plugins/asciidoc/asciidoc.py +++ b/plugins/asciidoc/asciidoc.py @@ -30,12 +30,13 @@ You will need, of course, to install asciidoc """ -import codecs +import io import os +import shlex import subprocess from nikola.plugin_categories import PageCompiler -from nikola.utils import makedirs, req_missing, write_metadata +from nikola.utils import makedirs, write_metadata try: from collections import OrderedDict @@ -49,28 +50,55 @@ class CompileAsciiDoc(PageCompiler): name = "asciidoc" demote_headers = True - def compile_html(self, source, dest, is_two_file=True): - makedirs(os.path.dirname(dest)) + def compile_string(self, data, source_path=None, is_two_file=True, post=None, lang=None): + """Compile asciidoc into HTML strings.""" binary = self.site.config.get('ASCIIDOC_BINARY', 'asciidoc') - try: - subprocess.check_call((binary, '-b', 'html5', '-s', '-o', dest, source)) - except OSError as e: - if e.strreror == 'No such file or directory': - req_missing(['asciidoc'], 'build this site (compile with asciidoc)', python=False) + options = self.site.config.get('ASCIIDOC_OPTIONS', '') + options = shlex.split(options) + command = [binary, '-b', 'html5', '-s'] + options + ['-'] + if not is_two_file: + m_data, data = self.split_metadata(data, post, lang) + + from nikola import shortcodes as sc + new_data, shortcodes = sc.extract_shortcodes(data) + p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + output = p.communicate(input=new_data.encode('utf8'))[0].decode('utf8') + output, shortcode_deps = self.site.apply_shortcodes_uuid(output, shortcodes, filename=source_path, extra_context={'post': post}) + return output, p.returncode, [], shortcode_deps + + def compile(self, source, dest, is_two_file=True, post=None, lang=None): + """Compile the source file into HTML and save as dest.""" + makedirs(os.path.dirname(dest)) + with io.open(dest, "w+", encoding="utf8") as out_file: + with io.open(source, "r", encoding="utf8") as in_file: + data = in_file.read() + output, error_level, deps, shortcode_deps = self.compile_string(data, source, is_two_file, post, lang) + out_file.write(output) + if post is None: + if deps.list: + self.logger.error( + "Cannot save dependencies for post {0} (post unknown)", + source) + else: + post._depfile[dest] += shortcode_deps + if error_level == 0: + return True + else: + return False def create_post(self, path, **kw): - content = kw.pop('content', 'Write your post here.') - one_file = kw.pop('onefile', False) # NOQA - is_page = kw.pop('is_page', False) # NOQA - metadata = OrderedDict() + """Create a new post.""" + content = kw.pop('content', None) + onefile = kw.pop('onefile', False) + # is_page is not used by create_post as of now. + kw.pop('is_page', False) + metadata = {} metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) if not content.endswith('\n'): content += '\n' - with codecs.open(path, "wb+", "utf8") as fd: - if one_file: - fd.write("////\n") - fd.write(write_metadata(metadata)) - fd.write("////\n") + with io.open(path, "w+", encoding="utf8") as fd: + if onefile: + fd.write(write_metadata(metadata, comment_wrap=('///', '///'), site=self.site, compiler=self)) fd.write(content) diff --git a/plugins/asciidoc/conf.py.sample b/plugins/asciidoc/conf.py.sample index 1dd5d3a..b8fda52 100644 --- a/plugins/asciidoc/conf.py.sample +++ b/plugins/asciidoc/conf.py.sample @@ -1,11 +1,14 @@ # Add the asciidoc compiler to your COMPILERS dict. -COMPILERS["asciidoc"] = ('.asc',) +COMPILERS["asciidoc"] = ['.asc'] # Add asciidoc files to your POSTS, PAGES POSTS = POSTS + (("posts/*.asc", "posts", "post.tmpl"),) -PAGES = PAGES + (("stories/*.asc", "posts", "post.tmpl"),) +PAGES = PAGES + (("pages/*.asc", "pages", "page.tmpl"),) # You can choose what command to use for processing. # For example, you can replace asciidoc with asciidoctor # Or use the full path to the program. # ASCIIDOC_BINARY = "asciidoc" + +# Specify options to the asciidoc compiler (as a string). +# ASCIIDOC_OPTIONS = "" |
