Repository: getnikola/nikola

Issue:
Pelican/Docinfo metadata not removed
<!--
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 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.6.6, 3.7.0, etc.

**Nikola Version:** 8.0.0, 8.0.0rc1

**Operating System:** OSX

### Description:

Title header entry and docinfo are not being removed with Pelican style metadata configuration.

By building a docinfo/pelican metadata site against different git commits of nikola, I have narrowed the reversion to #3158
Pelican/Docinfo metadata not removed
<!--
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 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.6.6, 3.7.0, etc.

**Nikola Version:** 8.0.0, 8.0.0rc1

**Operating System:** OSX

### Description:

Title header entry and docinfo are not being removed with Pelican style metadata configuration.

By building a docinfo/pelican metadata site against different git commits of nikola, I have narrowed the reversion to #3158


Discussion:
Did you set the `HIDE_REST_DOCINFO` setting?
Yes, I have:

```python
METADATA_FORMAT = "Pelican"
USE_REST_DOCINFO_METADATA = True
HIDE_REST_DOCINFO = True
```

My config works immediately before #3158 (as of commit 8ec9fc8035052784eae3ce79a6823b621f3eef31) and fails immediately after #3158 (as of commit 0ac289e4004594ece0876c76a1e9842fc90f9c12)

It fails to strip initial header and docinfo for all of my files.

Given as input:

```restructuredtext
Test Post
=========

:slug: test-post
:date: 2018-09-18 07:49:29+00:00
:tags: test
:category: meta

This is a test post.
```

Prior to #3158 I get `<main>` output of:

```html
    <main id="content">
      <article class="post-text h-entry hentry postpage" itemscope="itemscope" itemtype="http://schema.org/Article">
        <header>
          <h1 class="p-name entry-title" itemprop="headline name"><a class="u-url" href="/blog/test-post.html">Test Post</a></h1>
          <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn" itemprop="author">George Leslie-Waksman</span></p>
            <p class="dateline"><a href="/blog/test-post.html" rel="bookmark"><time class="published dt-published" datetime="2018-09-18T07:49:29Z" itemprop="datePublished" title="2018-09-18 07:49 UTC">2018-09-18 07:49 UTC</time></a></p>
            <p class="sourceline"><a class="sourcelink" href="/blog/test-post.rst">Source</a></p>
          </div>
        </header>
        <div class="e-content entry-content" itemprop="articleBody text">
          <p>This is a test post.</p>
        </div>
        <aside class="postpromonav">
          <nav>
            <div class="row tags" itemprop="keywords">
              <a class="tag p-category button button-primary" href="/blog/categories/test.html" rel="tag">test</a>
            </div>
            <div class="row pager hidden-print">
              <a class="button u-pull-left previous" href="/blog/2018/09/fortune-cookie-2018-09-04.html" rel="prev" title="Fortune Cookie: 2018-09-04">Previous post</a>
            </div>
          </nav>
        </aside>
      </article>
    </main>
```

After #3158 I get `<main>` output of:

```html
    <main id="content">
      <article class="post-text h-entry hentry postpage" itemscope="itemscope" itemtype="http://schema.org/Article">
        <header>
          <h1 class="p-name entry-title" itemprop="headline name"><a class="u-url" href="/blog/test-post.html">Test Post</a></h1>
          <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn" itemprop="author">George Leslie-Waksman</span></p>
            <p class="dateline"><a href="/blog/test-post.html" rel="bookmark"><time class="published dt-published" datetime="2018-09-18T07:49:29Z" itemprop="datePublished" title="2018-09-18 07:49 UTC">2018-09-18 07:49 UTC</time></a></p>
            <p class="sourceline"><a class="sourcelink" href="/blog/test-post.rst">Source</a></p>
          </div>
        </header>
        <div class="e-content entry-content" itemprop="articleBody text">
          <div class="section" id="test-post">
            <h2>Test Post</h2>
            <table class="docutils field-list" frame="void" rules="none">
              <col class="field-name">
              <col class="field-body">
              <tbody valign="top">
                <tr class="field">
                  <th class="field-name">slug:</th>
                  <td class="field-body">test-post</td>
                </tr>
                <tr class="field">
                  <th class="field-name">date:</th>
                  <td class="field-body">2018-09-18 07:49:29+00:00</td>
                </tr>
                <tr class="field">
                  <th class="field-name">tags:</th>
                  <td class="field-body">test</td>
                </tr>
                <tr class="field">
                  <th class="field-name">category:</th>
                  <td class="field-body">meta</td>
                </tr>
              </tbody>
            </table>
            <p>This is a test post.</p>
          </div>
        </div>
        <aside class="postpromonav">
          <nav>
            <div class="row tags" itemprop="keywords">
              <a class="tag p-category button button-primary" href="/blog/categories/test.html" rel="tag">test</a>
            </div>
            <div class="row pager hidden-print">
              <a class="button u-pull-left previous" href="/blog/2018/09/fortune-cookie-2018-09-04.html" rel="prev" title="Fortune Cookie: 2018-09-04">Previous post</a>
            </div>
          </nav>
        </aside>
      </article>
    </main>
```

The only difference between these `nikola build` runs is the version of nikola used.
Did you set the `HIDE_REST_DOCINFO` setting?
Yes, I have:

```python
METADATA_FORMAT = "Pelican"
USE_REST_DOCINFO_METADATA = True
HIDE_REST_DOCINFO = True
```

My config works immediately before #3158 (as of commit 8ec9fc8035052784eae3ce79a6823b621f3eef31) and fails immediately after #3158 (as of commit 0ac289e4004594ece0876c76a1e9842fc90f9c12)

It fails to strip initial header and docinfo for all of my files.

Given as input:

```restructuredtext
Test Post
=========

:slug: test-post
:date: 2018-09-18 07:49:29+00:00
:tags: test
:category: meta

This is a test post.
```

Prior to #3158 I get `<main>` output of:

```html
    <main id="content">
      <article class="post-text h-entry hentry postpage" itemscope="itemscope" itemtype="http://schema.org/Article">
        <header>
          <h1 class="p-name entry-title" itemprop="headline name"><a class="u-url" href="/blog/test-post.html">Test Post</a></h1>
          <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn" itemprop="author">George Leslie-Waksman</span></p>
            <p class="dateline"><a href="/blog/test-post.html" rel="bookmark"><time class="published dt-published" datetime="2018-09-18T07:49:29Z" itemprop="datePublished" title="2018-09-18 07:49 UTC">2018-09-18 07:49 UTC</time></a></p>
            <p class="sourceline"><a class="sourcelink" href="/blog/test-post.rst">Source</a></p>
          </div>
        </header>
        <div class="e-content entry-content" itemprop="articleBody text">
          <p>This is a test post.</p>
        </div>
        <aside class="postpromonav">
          <nav>
            <div class="row tags" itemprop="keywords">
              <a class="tag p-category button button-primary" href="/blog/categories/test.html" rel="tag">test</a>
            </div>
            <div class="row pager hidden-print">
              <a class="button u-pull-left previous" href="/blog/2018/09/fortune-cookie-2018-09-04.html" rel="prev" title="Fortune Cookie: 2018-09-04">Previous post</a>
            </div>
          </nav>
        </aside>
      </article>
    </main>
```

After #3158 I get `<main>` output of:

```html
    <main id="content">
      <article class="post-text h-entry hentry postpage" itemscope="itemscope" itemtype="http://schema.org/Article">
        <header>
          <h1 class="p-name entry-title" itemprop="headline name"><a class="u-url" href="/blog/test-post.html">Test Post</a></h1>
          <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn" itemprop="author">George Leslie-Waksman</span></p>
            <p class="dateline"><a href="/blog/test-post.html" rel="bookmark"><time class="published dt-published" datetime="2018-09-18T07:49:29Z" itemprop="datePublished" title="2018-09-18 07:49 UTC">2018-09-18 07:49 UTC</time></a></p>
            <p class="sourceline"><a class="sourcelink" href="/blog/test-post.rst">Source</a></p>
          </div>
        </header>
        <div class="e-content entry-content" itemprop="articleBody text">
          <div class="section" id="test-post">
            <h2>Test Post</h2>
            <table class="docutils field-list" frame="void" rules="none">
              <col class="field-name">
              <col class="field-body">
              <tbody valign="top">
                <tr class="field">
                  <th class="field-name">slug:</th>
                  <td class="field-body">test-post</td>
                </tr>
                <tr class="field">
                  <th class="field-name">date:</th>
                  <td class="field-body">2018-09-18 07:49:29+00:00</td>
                </tr>
                <tr class="field">
                  <th class="field-name">tags:</th>
                  <td class="field-body">test</td>
                </tr>
                <tr class="field">
                  <th class="field-name">category:</th>
                  <td class="field-body">meta</td>
                </tr>
              </tbody>
            </table>
            <p>This is a test post.</p>
          </div>
        </div>
        <aside class="postpromonav">
          <nav>
            <div class="row tags" itemprop="keywords">
              <a class="tag p-category button button-primary" href="/blog/categories/test.html" rel="tag">test</a>
            </div>
            <div class="row pager hidden-print">
              <a class="button u-pull-left previous" href="/blog/2018/09/fortune-cookie-2018-09-04.html" rel="prev" title="Fortune Cookie: 2018-09-04">Previous post</a>
            </div>
          </nav>
        </aside>
      </article>
    </main>
```

The only difference between these `nikola build` runs is the version of nikola used.

Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -842,12 +842,12 @@ def __init__(self, **config):
                 metadata_extractors.DEFAULT_EXTRACTOR_NAME))
             sys.exit(1)
 
-        # The pelican metadata format requires a markdown extension
+        # The Pelican metadata format requires a markdown extension
         if config.get('METADATA_FORMAT', 'nikola').lower() == 'pelican':
             if 'markdown.extensions.meta' not in config.get('MARKDOWN_EXTENSIONS', []) \
                     and 'markdown' in self.config['COMPILERS']:
                 utils.LOGGER.warn(
-                    'To use the pelican metadata format you need to add '
+                    'To use the Pelican metadata format, you need to add '
                     '"markdown.extensions.meta" to your MARKDOWN_EXTENSIONS setting.')
 
         # We use one global tzinfo object all over Nikola.
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
@@ -125,7 +125,7 @@ def compile_string(self, data, source_path=None, is_two_file=True, post=None, la
             'math_output': 'mathjax /assets/js/mathjax.js',
             'template': default_template_path,
             'language_code': LEGAL_VALUES['DOCUTILS_LOCALES'].get(LocaleBorg().current_lang, 'en'),
-            'doctitle_xform': not self.site.config.get('USE_REST_DOCINFO_METADATA'),
+            'doctitle_xform': self.site.config.get('USE_REST_DOCINFO_METADATA'),
         }
 
         from nikola import shortcodes as sc


Test patch: