Permalink
Browse files

remove METASTYLE configuration parameter, related to #127

As proposed [1]

> * `METASTYLE` is currently the way to switch between (YAML front
> matter) and (reST, Markdown, pandoc). Actually, all file formats are
> very different and easy to distuingish. Therefore, I would like to
> remove the `METASTYLE` variable.

[1] http://librelist.com/browser//acrylamid/2013/2/20/review-remove-a-few-configuration-variables/
  • Loading branch information...
1 parent 8f5602f commit 99cc98e42b796aa84b2bcc3d0d17a626b744683d @posativ committed Mar 23, 2013
Showing with 28 additions and 27 deletions.
  1. +5 −0 acrylamid/defaults/__init__.py
  2. +13 −14 acrylamid/readers.py
  3. +2 −2 acrylamid/tasks/new.py
  4. +0 −5 docs/conf.py.rst
  5. +8 −6 docs/usage.rst
@@ -55,6 +55,11 @@
def normalize(conf):
+ # metastyle has been removed
+ if 'metastyle' in conf:
+ log.info('notice METASTYLE is no longer needed to determine the metadata format ' + \
+ 'and can be removed.')
+
# deprecated since 0.8
if isinstance(conf['static'], list):
conf['static'] = conf['static'][0]
View
@@ -10,9 +10,12 @@
import re
import sys
import abc
+import codecs
import locale
import traceback
+BOM_UTF8 = codecs.BOM_UTF8.decode('utf8')
+
from os.path import join, getmtime, relpath
from fnmatch import fnmatch
from datetime import datetime, tzinfo, timedelta
@@ -264,17 +267,19 @@ def __init__(self, path, conf):
self.filename = path
self.tzinfo = conf.get('tzinfo', None)
- native = conf.get('metastyle', '').lower() == 'native'
with io.open(path, 'r', encoding='utf-8', errors='replace') as fp:
- if native and ispandoc(fp):
- i, meta = pandocstyle(fp)
- elif native and path.endswith(('.md', '.mkdown')):
- i, meta = markdownstyle(fp)
- elif native and path.endswith(('.rst', '.rest')):
+ peak = rchop(fp.read(512), BOM_UTF8)
+ fp.seek(0)
+
+ if peak.startswith('---\n'):
+ i, meta = yamlstyle(fp)
+ elif re.match('^\w+\n=+', peak):
i, meta = reststyle(fp)
+ elif peak.startswith('% '):
+ i, meta = pandocstyle(fp)
else:
- i, meta = yamlstyle(fp)
+ i, meta = markdownstyle(fp)
meta['title'] = unicode(meta['title']) # YAML can convert 42 to an int
@@ -297,7 +302,7 @@ def lastmodified(self):
def source(self):
"""Returns the actual, unmodified content."""
with io.open(self.filename, 'r', encoding='utf-8') as f:
- return ''.join(f.readlines()[self.offset:]).strip()
+ return rchop(''.join(f.readlines()[self.offset:]).strip(), BOM_UTF8)
def __hash__(self):
return self.hashvalue
@@ -605,12 +610,6 @@ def reststyle(fileobj):
return i, meta
-def ispandoc(fileobj):
- """Check for pandoc block (a percentage symbol within the first few bytes)"""
- chunk = fileobj.read(4); fileobj.seek(0)
- return chunk.strip().startswith('%')
-
-
def pandocstyle(fileobj):
"""A function to parse the so called 'Title block' out of Pandoc-formatted documents.
Provides very simple parsing so that Acrylamid won't choke on plain Pandoc documents.
@@ -25,7 +25,7 @@
lambda title, date: u"%s\n" % title + "="*len(title) + '\n\n' + ":date: %s\n\n" % date, \
lambda title, date: u"Title: %s\nDate: %s\n\n" % (title, date)
-formats = {(True, '.md'): md, (True, '.mkdown'): md, (True, '.rst'): rst}
+formats = {'.md': md, '.mkdown': md, '.rst': rst, '.rest': rst}
@task('new', [argument("title", nargs="*", default=None)], help="create a new entry")
@@ -41,7 +41,7 @@ def run(conf, env, options):
fd, tmp = tempfile.mkstemp(suffix=ext, dir='.cache/')
editor = os.getenv('VISUAL') if os.getenv('VISUAL') else os.getenv('EDITOR')
- tt = formats.get((conf.get('metastyle') == 'native', ext), yaml)
+ tt = formats.get(ext, yaml)
if options.title:
title = u(' '.join(options.title))
View
@@ -188,11 +188,6 @@ Miscellaneous
================================================ =====================================================
Variable name (default value) Description
================================================ =====================================================
-`METASTYLE` (*not set*) With ``native`` you can Acrylamid parse Markdown's or
- or reST's native meta data section if the filename
- ends with ``.rst`` or ``.md`` and ``.mkdown``
- respectively. It will also recognize `Pandoc's title
- block`_ on any filename extension.
`DISQUS_SHORTNAME` (*not set*) Enables `Disqus <https://disqus.com/>`_ integration
with your site identifier [#]_.
`DEFAULT_ORPHANS` (``0``) The minimum number of articles allowed on the last
View
@@ -124,12 +124,9 @@ That is the default format of your articles. Similar to Jekyll::
native metadata style
^^^^^^^^^^^^^^^^^^^^^
-With Acrylamid 0.4 you can also use the native metadata section provided by
-Markdown and reStructuredText. Both nativ formats are only active when you set
-``METASTYLE = "native"`` in your :doc:`conf.py` and your filenames end with
-``.rst`` or ``.rest`` for reStructuredText and ``.md`` or ``.mkdown`` for
-Markdown. Keep in mind, that the native metadata style only affects the parser.
-It does *not* set the filter to reST or Markdown.
+If you dislike the YAML front matter you can also use the native metadata
+section format from Markdown, reST or Pandoc. Keep in mind, that a given
+metadata section format will *not* set the appropriate filter.
reStructuredText:
@@ -151,6 +148,11 @@ Markdown::
Here starts my content ...
+Pandoc's `title block <http://johnmacfarlane.net/pandoc/README.html#title-block>`_ ::
+
+ % Title
+ % Author
+
reStructuredText or textile
^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 comments on commit 99cc98e

Please sign in to comment.