Repository: getnikola/nikola

Issue:
Problem with post-list and markdown when using date with <, >, <=, ...
<!--
Before creating an issue:
* make sure you are using an up-to-date version of Nikola
* search for existing issues that might be related

If you are reporting a bug:
* provide information about your environment (below)
* include all the output you get, and any other information related to your problem

Nikola v7.6.4, as provided by Debian/Ubuntu, is NOT SUPPORTED.
If you are using this version, you should upgrade: https://getnikola.com/getting-started.html
-->

### Environment (if reporting a bug)

**Python Version: 3.5.3**

**Nikola Version: Nikola v7.8.3**

**Operating System: Debian Jessie**

### Description:

When I try to use a post-list in markdown like this:

```
{{% post-list sections=vorlesungen sort=date template=postlistdir.tmpl date="day<now" %}}{{% /post-list %}}
```

nikola build fails with the following error:

```
TaskError - taskid:render_posts:cache/pages/index.html
PythonAction Error
Traceback (most recent call last):
  File "/scratch/user/programs/anaconda3/envs/nikola/lib/python3.5/site-packages/doit-0.30.3-py3.5.egg/doit/action.py", line 403, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/home/user/Downloads/nikola/nikola/post.py", line 554, in compile
    lang)
  File "/home/user/Downloads/nikola/nikola/plugins/compile/markdown/__init__.py", line 106, in compile
    output, shortcode_deps = self.compile_string(data, source, is_two_file, post)
  File "/home/user/Downloads/nikola/nikola/plugins/compile/markdown/__init__.py", line 95, in compile_string
    output, shortcode_deps = self.site.apply_shortcodes(output, filename=source_path, with_dependencies=True, extra_context={'post': post})
  File "/home/user/Downloads/nikola/nikola/nikola.py", line 1657, in apply_shortcodes
    return shortcodes.apply_shortcodes(data, self.shortcode_registry, self, filename, lang=lang, with_dependencies=with_dependencies, extra_context=extra_context)
  File "/home/user/Downloads/nikola/nikola/shortcodes.py", line 320, in apply_shortcodes
    res = f(*args, **kw)
  File "/home/user/Downloads/nikola/nikola/plugins/compile/rest/post_list.py", line 277, in _do_post_list
    filtered_timeline = [p for p in filtered_timeline if date_in_range(date, p.date, now=_now)]
  File "/home/user/Downloads/nikola/nikola/plugins/compile/rest/post_list.py", line 277, in <listcomp>
    filtered_timeline = [p for p in filtered_timeline if date_in_range(date, p.date, now=_now)]
  File "/home/user/Downloads/nikola/nikola/packages/datecond/__init__.py", line 75, in date_in_range
    item.strip()).groups()
AttributeError: 'NoneType' object has no attribute 'groups'
```

I think the problem is that the function date_in_range does not get the "raw" date_range parameter (which in this case should be day<now), but instead the special character gets escaped before, so it looks like "day\&lt;now".)
The quickest fix would probably be to add "\&gt;", "\&lt;" and so on to CLAUSE and OPERATORS in nikola/packages/datecond/\_\_init\_\_.py, but it is probably a bit hackish...





Discussion:
We could change it in the post list code itself, or perhaps globally for all shortcodes, as part of the parser — would the latter work well? (@felixfontein @ralsina)
The only solution which works well with all kinds of compilers would be to first replace shortcodes by unique random identifiers, then to run the compiler, and finally to replace the identifiers with the evaluated shortcodes. Everything else is just a hacky mess.
(Except if you make the compiler shortcode-aware. But that doesn't work for most of them.)
No idea, I don't understand the shortcodes implementation nowadays.
I‘d say to special-case post lists. Other shortcodes may be better suited by lt/gt and may be unaware of any API changes…

Resolving patch:
diff --git a/nikola/plugins/compile/rest/post_list.py b/nikola/plugins/compile/rest/post_list.py
--- a/nikola/plugins/compile/rest/post_list.py
+++ b/nikola/plugins/compile/rest/post_list.py
@@ -274,7 +274,7 @@ def _do_post_list(start=None, stop=None, reverse=False, tags=None, require_all_t
 
     if date:
         _now = utils.current_time()
-        filtered_timeline = [p for p in filtered_timeline if date_in_range(date, p.date, now=_now)]
+        filtered_timeline = [p for p in filtered_timeline if date_in_range(utils.html_unescape(date), p.date, now=_now)]
 
     for post in filtered_timeline[start:stop:step]:
         if slugs:
diff --git a/nikola/utils.py b/nikola/utils.py
--- a/nikola/utils.py
+++ b/nikola/utils.py
@@ -2032,12 +2032,12 @@ def load_data(path):
     html_unescape = html.unescape
 except (AttributeError, ImportError):
     try:
-        from HTMLParser import HTMLParser  # Python 2.6 and 2.7
+        from HTMLParser import HTMLParser  # Python 2.7
     except ImportError:
         from html.parser import HTMLParser  # Python 3 (up to 3.4)
 
     def html_unescape(s):
-        """Convert all named and numeric character references  in the string s to the corresponding unicode characters."""
+        """Convert all named and numeric character references in the string s to the corresponding unicode characters."""
         h = HTMLParser()
         return h.unescape(s)
 


Test patch: