diff --git a/.gitignore b/.gitignore
index d623314..22875f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,8 @@ docs/_build/
mincss.egg-info/
/build/
/dist/
+simple.js
+*.pyc
+__pycache__/
+.cache/
+.eggs/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..884c645
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,32 @@
+sudo: no
+
+language: python
+
+cache: pip
+
+python:
+- '2.7'
+- '3.3'
+- '3.4'
+- '3.5'
+
+install:
+ - pip install -r requirements.txt
+ - python setup.py install
+
+script:
+- nosetests
+- mincss https://news.ycombinator.com
+
+branches:
+ only:
+ - master
+
+deploy:
+ provider: pypi
+ user: peterbe
+ password:
+ secure: MWefB3EHYL8Nsoq0Fy0w+V0OFAOM4PKmYXxkYN/BAoMAYUTFbPm0CCNnafl72aQAKJkyuHXsYQf3dqRMtSPVkzMYJfniZ+LBxouk36v5+f2OXuMaSiLUug3nBAnNhMIyverWBBghF53IaKowyB/FzqC00U006K5aUzE6dFWEhF4=
+ on:
+ repo: peterbe/mincss
+ distributions: "sdist bdist_wheel"
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d57d175
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) Peter Bengtsson.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ 3. Neither the name of Peter Bengtsson nor the names of its contributors may be used
+ to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..dd38543
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,5 @@
+include LICENSE
+include README.rst
+include docs/changelog.rst
+include requirements.txt
+include mincss/download.js
diff --git a/README.md b/README.md
deleted file mode 100644
index df5853c..0000000
--- a/README.md
+++ /dev/null
@@ -1,50 +0,0 @@
-mincss
-======
-
-Clears the junk out of your CSS but finding out which selectors are
-actually not used in your HTML.
-
-By Peter Bengtsson, 2012-2013
-
-Why?
-----
-
-With the onslaught of Twitter Bootstrap upon the world it's very
-tempting to just download their whole fat 80+Kb CSS and serve it up
-even though you're not using half of the HTML that it styles.
-
-There's also the case of websites that have changed over time but
-without the CSS getting the same amount of love refactoring. Then it's
-very likely that you get CSS selectors that you're no longer or never
-using.
-
-This tool can help you get started reducing all those selectors that
-you're not using.
-
-Whitespace compression?
------------------------
-
-No, that's a separate concern. This tool works indendent of
-whitespace compression/optimization.
-
-For example, if you have a build step or a runtime step that converts
-all your CSS files into one (concatenation) and trims away all the
-excess whitespace (compression) then the output CSS can still contain
-selectors that are never actually used.
-
-What about AJAX?
-----------------
-
-If you have a script that creates DOM elements in some sort of
-``window.onload`` event then ``mincss`` will not be able to know this
-because at the moment ``mincss`` is entirely static.
-
-So what is a web developer to do? Simple, use ``/* no mincss */`` like
-this for example:
-
- .logged-in-info {
- /* no mincss */
- color: pink;
- }
-
-That tells ``mincss`` to ignore the whole block and all its selectors.
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..24eaf8f
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,102 @@
+**UPDATE April 2019**
+
+INSTEAD OF USING THIS, A MUCH BETTER ALTERNATIVE IS https://github.com/peterbe/minimalcss/ WHICH SUPPORTS JAVASCRIPT AND THE CSS PARSING AND TRANSFORMATIONS ARE DONE WITH A PARSED AST.
+
+
+
+mincss
+======
+
+.. image:: https://travis-ci.org/peterbe/mincss.png?branch=master
+ :target: https://travis-ci.org/peterbe/mincss
+ :alt: Build status
+
+Clears the junk out of your CSS by finding out which selectors are
+actually not used in your HTML.
+
+By Peter Bengtsson, 2012-2018
+
+Tested in Python 2.7, 3.3, 3.4 and 3.5
+
+Example
+-------
+
+::
+
+ $ mincss https://github.com
+
+
+Installation
+------------
+
+From pip::
+
+ $ pip install mincss
+
+Why?
+----
+
+With the onslaught of Twitter Bootstrap upon the world it's very
+tempting to just download their whole fat 80+Kb CSS and serve it up even
+though you're not using half of the HTML that it styles.
+
+There's also the case of websites that have changed over time but
+without the CSS getting the same amount of love refactoring. Then it's
+very likely that you get CSS selectors that you're no longer or never
+using.
+
+This tool can help you get started reducing all those selectors that
+you're not using.
+
+Whitespace compression?
+-----------------------
+
+No, that's a separate concern. This tool works independent of whitespace
+compression/optimization.
+
+For example, if you have a build step or a runtime step that converts
+all your CSS files into one (concatenation) and trims away all the
+excess whitespace (compression) then the output CSS can still contain
+selectors that are never actually used.
+
+What about AJAX?
+----------------
+
+If you have a script that creates DOM elements in some sort of
+``window.onload`` event then ``mincss`` will not be able to know this
+because at the moment ``mincss`` is entirely static.
+
+So what is a web developer to do? Simple, use ``/* no mincss */`` like
+this for example:
+
+::
+
+ .logged-in-info {
+ /* no mincss */
+ color: pink;
+ }
+
+That tells ``mincss`` to ignore the whole block and all its selectors.
+
+Ignore CSS
+----------
+
+By default, ``mincss`` will find all ```` tags and process them. If you have a link or an inline
+tag that you don't want ``mincss`` to even notice, simply add this attribute
+to the tag:
+
+::
+
+ data-mincss="ignore"
+
+Leave CSS as is
+---------------
+
+One technique to have a specific CSS selector be ignored by ``mincss`` is to
+put in a comment like ``/* no mincss */`` inside the CSS selectors
+block.
+
+Another way is to leave the whole stylesheet as is. The advantage of doing
+this is if you have a ``link`` or ``style`` tag that you want ``mincss``
+to ignore but still find and include in the parsed result.
diff --git a/docs/api.rst b/docs/api.rst
index f6e9854..b303e1b 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -7,9 +7,34 @@ API
**This is work in progress and is likely to change in future version**
-* ``process.Processor([debug=False])``
+* ``process.Processor([debug=False, preserve_remote_urls=True])``
Creates a processor instance that you can feed HTML and URLs.
+ The arguments:
+
+ * ``debug=False``
+ Currently does nothing particular.
+
+ * ``preserve_remote_urls=True``
+ If you run a URL like ``http://www.example.org`` that references
+ ``http://cdn.cloudware.com/foo.css`` which contains
+ ``url(/background.png)`` then the CSS will be rewritten to become
+ ``url(http://cdn.cloudware.com/background.png)``
+
+ * ``phantomjs=None``
+ If ``True`` will default to ``phantomjs``, If a string it's
+ assume it's the path to the executable ``phantomjs`` path.
+
+ * ``phantomjs_options={}``
+ Additional options/switches to the ``phantomjs`` command. This
+ has to be a dict. So, for example ``{'script-encoding': 'latin1'}``
+ becomes ``--script-encoding=latin1``.
+
+ * ``optimize_lookup=True``
+ If true, will make a set of all ids and class names in all
+ processed documents and use these to avoid some expensive CSS
+ query searches.
+
Instances of this allows you to use the following methods:
* ``process(*urls)``
@@ -26,6 +51,10 @@ API
If you for some reason already have the HTML you can jump straight
to this method. Note, you still need to provide the URL where you
got the HTML from so it can use that to download any external CSS.
+
+ * When calling ``process_url()`` or ``process_html()``, you have to call ``process()``
+ at the end without arguments, in order to post process the pages that were
+ processed individually.
The ``Processor`` instance will make two attributes available
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 04fd15e..0e1a6e1 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -5,6 +5,44 @@
Changelog
=========
+v0.8.1 (2013-04-05)
+-------------------
+
+The file ``download.js`` was missing from the tarball.
+
+v0.8.0 (2013-02-26)
+-------------------
+
+Much faster! Unless you pass ``Processor(optimize_lookup=False)`` when
+creating the processor instance. See
+http://www.peterbe.com/plog/mincss-0.8
+
+v0.7.0 (2013-02-13)
+-------------------
+
+Fixed bug with make absolute url of url like `http://peterbe.com` +
+`./style.css`. Thanks @erfaan!
+
+v0.6.1 (2013-02-12)
+-------------------
+
+The proxy app would turn `` into `
`. Same for iframe, textarea and divs.
+
+v0.6.0 (2013-02-01)
+-------------------
+
+New option, `phantomjs` that allows you to download the HTML using
+phantomjs instead of regular Python's urllib.
+
+
+v0.5.0 (2013-01-24)
+-------------------
+
+New option `preserve_remote_urls` to `Processor()` class. Useful when
+the hrefs in link tags are of different domain than the URL you're
+processing.
+
v0.1 (2013-01-14)
-----------------
diff --git a/docs/conf.py b/docs/conf.py
index 12798d0..0bfa03f 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -3,7 +3,8 @@
# mincss documentation build configuration file, created by
# sphinx-quickstart on Fri Jan 11 14:08:28 2013.
#
-# This file is execfile()d with the current directory set to its containing dir.
+# This file is execfile()d with the current directory set to its containing
+# dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
@@ -11,20 +12,19 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
-import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
-# -- General configuration -----------------------------------------------------
+# -- General configuration -----------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
-# Add any Sphinx extension module names here, as strings. They can be extensions
-# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = []
# Add any paths that contain templates here, relative to this directory.
@@ -66,7 +66,8 @@
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
-# The reST default role (used for this markup: `text`) to use for all documents.
+# The reST default role (used for this markup: `text`) to use for all
+# documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
@@ -87,7 +88,7 @@
#modindex_common_prefix = []
-# -- Options for HTML output ---------------------------------------------------
+# -- Options for HTML output ---------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
@@ -167,24 +168,25 @@
htmlhelp_basename = 'mincssdoc'
-# -- Options for LaTeX output --------------------------------------------------
+# -- Options for LaTeX output --------------------------------------------
latex_elements = {
-# The paper size ('letterpaper' or 'a4paper').
-#'papersize': 'letterpaper',
+ # The paper size ('letterpaper' or 'a4paper').
+ #'papersize': 'letterpaper',
-# The font size ('10pt', '11pt' or '12pt').
-#'pointsize': '10pt',
+ # The font size ('10pt', '11pt' or '12pt').
+ #'pointsize': '10pt',
-# Additional stuff for the LaTeX preamble.
-#'preamble': '',
+ # Additional stuff for the LaTeX preamble.
+ #'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
-# (source start file, target name, title, author, documentclass [howto/manual]).
+# (source start file, target name, title, author, documentclass
+# [howto/manual]).
latex_documents = [
- ('index', 'mincss.tex', u'mincss Documentation',
- u'Peter Bengtsson', 'manual'),
+ ('index', 'mincss.tex', u'mincss Documentation',
+ u'Peter Bengtsson', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
@@ -208,7 +210,7 @@
#latex_domain_indices = True
-# -- Options for manual page output --------------------------------------------
+# -- Options for manual page output --------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
@@ -221,15 +223,15 @@
#man_show_urls = False
-# -- Options for Texinfo output ------------------------------------------------
+# -- Options for Texinfo output ------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
- ('index', 'mincss', u'mincss Documentation',
- u'Peter Bengtsson', 'mincss', 'One line description of project.',
- 'Miscellaneous'),
+ ('index', 'mincss', u'mincss Documentation',
+ u'Peter Bengtsson', 'mincss', 'One line description of project.',
+ 'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
diff --git a/docs/features.rst b/docs/features.rst
index 67a051f..c7733fc 100644
--- a/docs/features.rst
+++ b/docs/features.rst
@@ -31,12 +31,12 @@ Supported Features and Limitations
**Things that don't yet work:**
* Javascript events that manipulate the DOM tree.
- A future version might use a parser that supports Javascript but
- likely it will never be perfect.
+ You can use PhantomJS to do the downloading but it still won't get
+ every possible piece of HTML generated based on complex Javascript.
* keyframes are always left untouched even if it's never referenced
-* Broken HTML or broken/invalid CSS isn't support and good results can
+* Broken HTML or broken/invalid CSS isn't supported and good results can
not be guaranteed.
diff --git a/docs/gettingstarted.rst b/docs/gettingstarted.rst
index f625f6f..cd14570 100644
--- a/docs/gettingstarted.rst
+++ b/docs/gettingstarted.rst
@@ -18,6 +18,7 @@ Suppose you have a page like this::