Click here to Skip to main content
15,893,814 members
Articles / Web Development / HTML

Minify contents - Reduce page size

Rate me:
Please Sign up or sign in to vote.
4.75/5 (4 votes)
19 Jul 2012CPOL2 min read 31.2K   1.8K   12  
A library to minify HTML and CSS content.
using System.Collections.Generic;
using System.Text.RegularExpressions;


namespace MinifyContent.Expressions
{
    /// <summary>
    /// Delegate allows to define method for minify content
    /// </summary>
    /// <param name="sender">Expression object</param>
    /// <param name="input">Content string</param>
    /// <returns></returns>
    internal delegate string Replace(Expression sender, string input);

    /// <summary>
    /// A class to define expressions to minify content
    /// </summary>
    class Expression
    {
        public Expression()
        { }

        public Expression(Regex expr, string replaceWith = "")
        { RegularExpression = expr; ReplaceWith = replaceWith; }

        public Expression(List<Regex> exprs, string replaceWith = "")
        { RegularExpressions = exprs; ReplaceWith = replaceWith; }

        public bool EscapeInCss { get; set; }

        public bool EscapeInJs { get; set; }

        public Regex RegularExpression { get; private set; }

        public List<Regex> RegularExpressions { get; private set; }

        public string ReplaceWith { get; private set; }

        public Replace ReplaceHandler { get; set; }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India
Mehul Thakkar is having 8 yrs of experience in IT industry. He is having good command over Ms .Net and Ms Sql Server

Comments and Discussions