internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: getnikola/nikola

Issue:
Deduplicate math code and automate adding KaTeX CSS
- [x] Currently, MathJax/KaTeX code is in two files (`index_helper.tmpl` and `post_helper.tmpl`). We could make a separate `math_helper.tmpl` that handles the common parts.
- [x] To use KaTeX, users need to add a CSS file to `EXTRA_HEAD_DATA`, and then keep the version in sync with Nikola. This is pretty bad from an usability perspective, so we should just add that CSS file ourselves. Perhaps even by adding a `page_uses_math` context variable.


Discussion:

Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -828,6 +828,11 @@ def __init__(self, **config):
             utils.LOGGER.warn('The moot comment system has been renamed to muut by the upstream.  Setting COMMENT_SYSTEM to "muut".')
             self.config['COMMENT_SYSTEM'] = 'muut'
 
+        # Detect manually added KaTeX CSS (#2715/#2717)
+        # TODO: remove on v8
+        if any('katex.min.css' in v for v in self.config['EXTRA_HEAD_DATA'].values.values()):
+            utils.LOGGER.warn("KaTeX CSS is now added by Nikola whenever needed (if your theme supports it). Please remove katex.min.css from EXTRA_HEAD_DATA in conf.py.")
+
         # Handle old plugin names (from before merging the taxonomy PR #2535)
         for old_plugin_name, new_plugin_names in TAXONOMY_COMPATIBILITY_PLUGIN_NAME_MAP.items():
             if old_plugin_name in self.config['DISABLED_PLUGINS']:


Test patch:
Repository: getnikola/nikola

Issue:
Where can I find what default fields are available in templates?
For example, in templates, we have `${header.html_site_title()}` for the site title. Where can I find the whole list?


Discussion:
That is template dependent. You can grep for `<%def name"` to find all Mako block definitions.

(You might also be interested in #2328, which deals with variables available in templates.)
Unfortunately, we don’t have complete theme documentation. In this case, `html_site_title()` is a function that comes from whatever was imported as `header` — using `<%namespace name="header" file="base_header.tmpl" import="*"/>`.
Ok, I see... What about the `${blog_title}` kind of variables?
Variables and functions may come from three places:

* the global Nikola context, eg. `blog_title` — search for `GLOBAL_CONTEXT` in [nikola.py](https://github.com/getnikola/nikola/blob/master/nikola/nikola.py)
* the local context of a function, eg. `post` in `post.tmpl` — those are hidden in every
* imported templates, eg. `header.html_site_title()` — see the imports at the top of a template

Documenting it is a task we’ve never really gotten to, sorry.
Ok, got it. Thx.
It’s not really solved, so reopening.

Resolving patch:
diff --git a/nikola/plugin_categories.py b/nikola/plugin_categories.py
--- a/nikola/plugin_categories.py
+++ b/nikola/plugin_categories.py
@@ -560,7 +560,7 @@ class Taxonomy(BasePlugin):
         Whether to show the posts for one classification as an index or
         as a post list.
 
-    subcategories_list_template = "taxonomy_list":
+    subcategories_list_template = "taxonomy_list.tmpl":
         The template to use for the subcategories list when
         show_list_as_subcategories_list is True.
 
@@ -617,7 +617,7 @@ class Taxonomy(BasePlugin):
     include_posts_into_hierarchy_root = False
     show_list_as_subcategories_list = False
     show_list_as_index = False
-    subcategories_list_template = "taxonomy_list"
+    subcategories_list_template = "taxonomy_list.tmpl"
     generate_atom_feeds_for_post_lists = False
     template_for_single_list = "tagindex.tmpl"
     template_for_classification_overview = "list.tmpl"


Test patch:
Repository: getnikola/nikola

Issue:
Nikola serve lists 0.0.0.0:8000 but actually served at http://127.0.0.1:8000/
### Environment 
**Python Version:** 3.6.1
**Nikola Version:** Nikola (7.8.4)
**Operating System:** Windows 10
### Description:  When I type `nikola serve --browser` a page is opened at 0.0.0.0:8000 but it returns a 'can't be reached' error (ERR_ADDRESS_INVALID).  The site is however being correctly served at http://127.0.0.1:8000/


I'm new to Nikola I've really just followed the demo (choosing defaults for most values).  

```
G:\E\nikola\demo>nikola serve --browser
[2017-05-11T18:01:40Z] INFO: serve: Serving HTTP on 0.0.0.0 port 8000...
[2017-05-11T18:01:40Z] INFO: serve: Opening http://0.0.0.0:8000/ in the default web browser...
```
This opens up this page:

![image](https://cloud.githubusercontent.com/assets/5048607/25964565/499e7b0c-3653-11e7-8918-72ab8cda9acb.png)

The site is however being served correctly to  http://127.0.0.1:8000/

![image](https://cloud.githubusercontent.com/assets/5048607/25964961/93a562b4-3654-11e7-91a6-82230e6da174.png)

Did something recently change or is something in my configuration redirecting? Thanks

p.s. -- http://127.0.0.1:8000/ and http://127.1.1.1:8000/ both serve the site.
p.p.s -- edited issue title and body to fix address (I meant http://127.0.0.1:8000/ not http://127.1.1.1:8000/


Discussion:
Does `127.0.0.1` work? Does `0.0.0.0:8000` work after a refresh? Does it work in a different browser?

(We *do* use `0.0.0.0`, and on Linux/macOS it works — it is the “all local interfaces” IP)
Yes, `127.0.0.1` also works.   I tried a refresh on `0.0.0.0` but that did not work. I'm on Windows 10.
Does any other browser work?
I've tried `0.0.0.0' on chrome (my default) and firefox ('unable to connect') 

Resolving patch:
diff --git a/nikola/plugins/command/serve.py b/nikola/plugins/command/serve.py
--- a/nikola/plugins/command/serve.py
+++ b/nikola/plugins/command/serve.py
@@ -146,6 +146,8 @@ def _execute(self, options, args):
             if options['browser']:
                 if ipv6:
                     server_url = "http://[{0}]:{1}/".format(*sa)
+                elif sa[0] == '0.0.0.0':
+                    server_url = "http://127.0.0.1:{1}/".format(*sa)
                 else:
                     server_url = "http://{0}:{1}/".format(*sa)
                 self.logger.info("Opening {0} in the default web browser...".format(server_url))


Test patch:
Repository: getnikola/nikola

Issue:
nikola new_post should guess formats from extensions
* Running `nikola new_post -i /path/to/foo.ipynb` will create something like `posts/foo-title.rst`, which will result in completely broken output (turns out reST isn’t really good at rendering JSON not in a code block)
* Running `nikola new_post posts/bar.ipynb` will create reST-style metadata in that file, instead of a JSON file for ipynb.

(Replace *reST, ipynb* with *default compiler, any other compiler*)


Discussion:

Resolving patch:
diff --git a/nikola/plugins/command/new_post.py b/nikola/plugins/command/new_post.py
--- a/nikola/plugins/command/new_post.py
+++ b/nikola/plugins/command/new_post.py
@@ -265,16 +265,33 @@ def _execute(self, options, args):
         if "@" in content_format:
             content_format, content_subformat = content_format.split("@")
 
-        if not content_format:  # Issue #400
+        if not content_format and path:
+            # content_format not specified. If path was given, use
+            # it to guess (Issue #2798)
+            extension = os.path.splitext(path)[-1]
+            for compiler, extensions in self.site.config['COMPILERS'].items():
+                if extension in extensions:
+                    content_format = compiler
+
+        elif not content_format and import_file:
+            # content_format not specified. If import_file was given, use
+            # it to guess (Issue #2798)
+            extension = os.path.splitext(import_file)[-1]
+            for compiler, extensions in self.site.config['COMPILERS'].items():
+                if extension in extensions:
+                    content_format = compiler
+
+        elif not content_format:  # Issue #400
             content_format = get_default_compiler(
                 is_post,
                 self.site.config['COMPILERS'],
                 self.site.config['post_pages'])
 
-        if content_format not in compiler_names:
+        elif content_format not in compiler_names:
             LOGGER.error("Unknown {0} format {1}, maybe you need to install a plugin or enable an existing one?".format(content_type, content_format))
             self.print_compilers()
             return
+
         compiler_plugin = self.site.plugin_manager.getPluginByName(
             content_format, "PageCompiler").plugin_object
 


Test patch:
Repository: getnikola/nikola

Issue:
Ignoring assets
Use cases:

* no more colorbox-i18n mess
* simpler base themes (cf. #2744, #2810)
* one lightbox is enough

Implementation: `.theme` files, of course!


Discussion:

Resolving patch:
diff --git a/nikola/plugins/task/copy_assets.py b/nikola/plugins/task/copy_assets.py
--- a/nikola/plugins/task/copy_assets.py
+++ b/nikola/plugins/task/copy_assets.py
@@ -33,6 +33,10 @@
 
 from nikola.plugin_categories import Task
 from nikola import utils
+from nikola.nikola import LEGAL_VALUES
+
+_COLORBOX_PREFIX = 'js|colorbox-i18n|jquery.colorbox-'.replace('|', os.sep)
+_COLORBOX_SLICE = slice(len(_COLORBOX_PREFIX), -3)
 
 
 class CopyAssets(Task):
@@ -48,6 +52,7 @@ def gen_tasks(self):
         """
         kw = {
             "themes": self.site.THEMES,
+            "translations": self.site.translations,
             "files_folders": self.site.config['FILES_FOLDERS'],
             "output_folder": self.site.config['OUTPUT_FOLDER'],
             "filters": self.site.config['FILTERS'],
@@ -63,12 +68,33 @@ def gen_tasks(self):
                                               files_folders=kw['files_folders'], output_dir=None)
         yield self.group_task()
 
+        main_theme = utils.get_theme_path(kw['themes'][0])
+        theme_ini = utils.parse_theme_meta(main_theme)
+        if theme_ini:
+            ignored_assets = theme_ini.get("Nikola", "ignored_assets", fallback='').split(',')
+            ignore_colorbox_i18n = theme_ini.get("Nikola", "ignore_colorbox_i18n", fallback="unused")
+        else:
+            ignored_assets = []
+            ignore_colorbox_i18n = "unused"
+
+        if ignore_colorbox_i18n == "unused":
+            # Check what colorbox languages we need so we can ignore the rest
+            needed_colorbox_languages = [LEGAL_VALUES['COLORBOX_LOCALES'][i] for i in kw['translations']]
+
         for theme_name in kw['themes']:
             src = os.path.join(utils.get_theme_path(theme_name), 'assets')
             dst = os.path.join(kw['output_folder'], 'assets')
             for task in utils.copy_tree(src, dst):
-                if task['name'] in tasks:
+                asset_name = os.path.relpath(task['name'], dst)
+                if task['name'] in tasks or asset_name in ignored_assets:
                     continue
+                elif asset_name.startswith(_COLORBOX_PREFIX):
+                    if ignore_colorbox_i18n == "all" or ignore_colorbox_i18n is True:
+                        continue
+
+                    colorbox_lang = asset_name[_COLORBOX_SLICE]
+                    if ignore_colorbox_i18n == "unused" and colorbox_lang not in needed_colorbox_languages:
+                        continue
                 tasks[task['name']] = task
                 task['uptodate'] = [utils.config_changed(kw, 'nikola.plugins.task.copy_assets')]
                 task['basename'] = self.name


Test patch:
Repository: getnikola/nikola

Issue:
jinja-themes broken without warning if parent-file exists 
When a jinja-template contains a "parent"-file (how theme parents were handled before 7.8.6) referencing base-jinja nikola screws up templateing and renders the template-files instead of the actual content. Presumably it uses the mako engine to render the jinja templates.

This happens without a warning, website could be deployed completely broken without the user noticing unless they manually check the output-folder. This is probably affects all people who are using old-style parent-files with jinja templates.

Affects Nikola v7.8.6. Im running python3.6.1 on an arch linux. 
jinja-themes broken without warning if parent-file exists 
When a jinja-template contains a "parent"-file (how theme parents were handled before 7.8.6) referencing base-jinja nikola screws up templateing and renders the template-files instead of the actual content. Presumably it uses the mako engine to render the jinja templates.

This happens without a warning, website could be deployed completely broken without the user noticing unless they manually check the output-folder. This is probably affects all people who are using old-style parent-files with jinja templates.

Affects Nikola v7.8.6. Im running python3.6.1 on an arch linux. 


Discussion:
This happens when `engine` does not exist in the child theme. It used to work because `base-jinja` would provide a parent name, but that went out of the window when theme meta files were introduced. I’ll fix it tomorrow. (This might be fast-release-worthy.)
This happens when `engine` does not exist in the child theme. It used to work because `base-jinja` would provide a parent name, but that went out of the window when theme meta files were introduced. I’ll fix it tomorrow. (This might be fast-release-worthy.)

Resolving patch:
diff --git a/nikola/utils.py b/nikola/utils.py
--- a/nikola/utils.py
+++ b/nikola/utils.py
@@ -646,8 +646,8 @@ def get_template_engine(themes):
             if os.path.isfile(engine_path):
                 with open(engine_path) as fd:
                     return fd.readlines()[0].strip()
-        # default
-        return 'mako'
+    # default
+    return 'mako'
 
 
 def get_parent_theme_name(theme_name, themes_dirs=None):


Test patch:
Repository: getnikola/nikola

Issue:
Switch to html5 reST writer
http://docutils.sourceforge.net/RELEASE-NOTES.html#release-0-13-1-2016-12-09

Also includes new CSS we need to adapt for.


Discussion:

Resolving patch:
diff --git a/nikola/plugins/command/rst2html/__init__.py b/nikola/plugins/command/rst2html/__init__.py
--- a/nikola/plugins/command/rst2html/__init__.py
+++ b/nikola/plugins/command/rst2html/__init__.py
@@ -53,7 +53,7 @@ def _execute(self, options, args):
             data = in_file.read()
             output, error_level, deps, shortcode_deps = compiler.compile_string(data, source, True)
 
-        rstcss_path = resource_filename('nikola', 'data/themes/base/assets/css/html4css1.css')
+        rstcss_path = resource_filename('nikola', 'data/themes/base/assets/css/rst_base.css')
         with io.open(rstcss_path, "r", encoding="utf8") as fh:
             rstcss = fh.read()
 
diff --git a/nikola/plugins/compile/rest/__init__.py b/nikola/plugins/compile/rest/__init__.py
--- a/nikola/plugins/compile/rest/__init__.py
+++ b/nikola/plugins/compile/rest/__init__.py
@@ -35,7 +35,7 @@
 import docutils.utils
 import docutils.io
 import docutils.readers.standalone
-import docutils.writers.html4css1
+import docutils.writers.html5_polyglot
 import docutils.parsers.rst.directives
 from docutils.parsers.rst import roles
 
@@ -285,9 +285,9 @@ def depart_Math(self, node):
     """
     docutils.nodes._add_node_class_names([node.__name__])
     if visit_function:
-        setattr(docutils.writers.html4css1.HTMLTranslator, 'visit_' + node.__name__, visit_function)
+        setattr(docutils.writers.html5_polygot.HTMLTranslator, 'visit_' + node.__name__, visit_function)
     if depart_function:
-        setattr(docutils.writers.html4css1.HTMLTranslator, 'depart_' + node.__name__, depart_function)
+        setattr(docutils.writers.html5_polyglot.HTMLTranslator, 'depart_' + node.__name__, depart_function)
 
 
 def rst2html(source, source_path=None, source_class=docutils.io.StringInput,


Test patch:
Repository: getnikola/nikola

Issue:
New thumbnail shortcode
Adds a basic thumbnail shortcode, needs work but it's something.


Discussion:

Resolving patch:
diff --git a/nikola/plugins/shortcode/thumbnail.py b/nikola/plugins/shortcode/thumbnail.py
new file mode 100644
--- /dev/null
+++ b/nikola/plugins/shortcode/thumbnail.py
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+
+# Copyright © 2017 Roberto Alsina, Chris Warrick and others.
+
+# Permission is hereby granted, free of charge, to any
+# person obtaining a copy of this software and associated
+# documentation files (the "Software"), to deal in the
+# Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the
+# Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice
+# shall be included in all copies or substantial portions of
+# the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+"""Thumbnail shortcode (equivalent to reST’s thumbnail directive)."""
+
+from nikola.plugin_categories import ShortcodePlugin
+
+import os.path
+
+
+class ThumbnailShortcode(ShortcodePlugin):
+    """Plugin for thumbnail directive."""
+
+    name = "thumbnail"
+
+    def handler(self, uri, alt=None, align=None, target=None, site=None, data=None, lang=None, post=None):
+        """Create HTML for thumbnail."""
+        if uri.endswith('.svg'):
+            # the ? at the end makes docutil output an <img> instead of an object for the svg, which colorbox requires
+            src = '.thumbnail'.join(os.path.splitext(uri)) + '?'
+        else:
+            src = '.thumbnail'.join(os.path.splitext(uri))
+
+        output = '<a href="{0}" class="image-reference"><img src="{1}"'.format(uri, src)
+        if alt:
+            output += ' alt="{}"'.format(alt)
+        if align and not data:
+            output += ' class="align-{}"'.format(align)
+        output += '></a>'
+
+        if data and align:
+            output = '<div class="figure align-{2}">{0}{1}</div>'.format(output, data, align)
+        elif data:
+            output = '<div class="figure">{0}{1}</div>'.format(output, data)
+
+        return output, []


Test patch:
Repository: getnikola/nikola

Issue:
Theme meta file ignored_assets key should ignore whitespace
### Environment (if reporting a bug)

**Python Version:**
3.5.4
**Nikola Version:**
8.0.0dev HEAD
**Operating System:**
gentoo GNU/Linux
### Description:
Current behaviour: The ignored_assets key in theme meta files takes a comma-separated list of filenames, that must not contain leading or trailing whitespace because it's considered to be part of the filename.

Expected behaviour: The comma-separated list may contain the usual amount of whitespace: foo, bar, baz, etc




Discussion:

Resolving patch:
diff --git a/nikola/plugins/task/copy_assets.py b/nikola/plugins/task/copy_assets.py
--- a/nikola/plugins/task/copy_assets.py
+++ b/nikola/plugins/task/copy_assets.py
@@ -67,6 +67,7 @@ def gen_tasks(self):
         theme_ini = utils.parse_theme_meta(main_theme)
         if theme_ini:
             ignored_assets = theme_ini.get("Nikola", "ignored_assets", fallback='').split(',')
+            ignored_assets = [asset_name.strip() for asset_name in ignored_assets]
         else:
             ignored_assets = []
 


Test patch:
Repository: getnikola/nikola

Issue:
nikola serve rewrites URLs with query strings inproperly
When testing `localsearch`, `nikola serve` redirected `http://127.0.0.1:8000/search/?q=welcome` to `http://127.0.0.1:8000/search/?q=welcome/`. Which is really strange. Doesn’t happen with `python -m http.server`, so it’s our fault.
nikola serve rewrites URLs with query strings inproperly
When testing `localsearch`, `nikola serve` redirected `http://127.0.0.1:8000/search/?q=welcome` to `http://127.0.0.1:8000/search/?q=welcome/`. Which is really strange. Doesn’t happen with `python -m http.server`, so it’s our fault.


Discussion:

Resolving patch:
diff --git a/nikola/plugins/command/serve.py b/nikola/plugins/command/serve.py
--- a/nikola/plugins/command/serve.py
+++ b/nikola/plugins/command/serve.py
@@ -217,7 +217,9 @@ def send_head(self):
             if not self.path.endswith('/'):
                 # redirect browser - doing basically what apache does
                 self.send_response(301)
-                self.send_header("Location", self.path + "/")
+                path_parts = list(self.path.partition('?'))
+                path_parts[0] += '/'
+                self.send_header("Location", ''.join(path_parts))
                 # begin no-cache patch
                 # For redirects.  With redirects, caching is even worse and can
                 # break more.  Especially with 301 Moved Permanently redirects,


Test patch:
Repository: getnikola/nikola

Issue:
RSS_PATH doesn't work as advertised (is path and filename, excluding .xml)
* Python Version: 3.5.3
* Nikola Version: v7.8.14
* Operating System: Debian

A fresh config says:

```
# Final location for the blog main RSS feed is:
# output / TRANSLATION[lang] / RSS_PATH / rss.xml
```

which is in line with other `_PATH` variables.

But it seems `RSS_PATH` is actually path+filename (and `.xml` is appended).

With `RSS_PATH = "blog/`I get `render_taxonomies:output/blog/.xml` (instead of `blog/rss.xml`)

With `RSS_PATH = blog/index.xml` I get `render_taxonomies:output/blog/index.xml.xml`



Discussion:
`indexes.py`, line 94 (master) seems to be the culprit:

```py
        if dest_type == 'rss':
            return [self.site.config['RSS_PATH'](lang)], True
```

I’m not sure what fix would be the best. To match the description, we can just add `'rss'` to the path list. But to retain the current undocumented behavior, we’d need to check if RSS_PATH ends with `/`.

@felixfontein, @ralsina: any strong opinions on what to do with this?
Actually, the `True` in that line should have be `'auto'` (see https://github.com/getnikola/nikola/pull/3015#discussion_r179981043; @davidak already included that in #3015).

I think the lines should be
``` .py
        if dest_type == 'rss':
            return [self.site.config['RSS_PATH'](lang), 'rss'], 'auto'
```
That should lead to the documented behavior (`output / TRANSLATION[lang] / RSS_PATH / rss.xml`).

I'm not sure how to keep the current undocumented (and wrong) behavior in a sane way. Actually, I think we simply should not (so far, nobody else complained about it anyway, IIRC).

Resolving patch:
diff --git a/nikola/plugins/task/indexes.py b/nikola/plugins/task/indexes.py
--- a/nikola/plugins/task/indexes.py
+++ b/nikola/plugins/task/indexes.py
@@ -91,7 +91,7 @@ def get_classification_friendly_name(self, classification, lang, only_last_compo
     def get_path(self, classification, lang, dest_type='page'):
         """Return a path for the given classification."""
         if dest_type == 'rss':
-            return [self.site.config['RSS_PATH'](lang)], True
+            return [self.site.config['RSS_PATH'](lang), 'rss'], 'auto'
         # 'page' (index) or 'feed' (Atom)
         page_number = None
         if dest_type == 'page':


Test patch: