CleanHTML-幫你減肥HTML的好用工具
Published: (Updated: )
by .幫你快速減肥HTML的好用工具
Introduction
當你有個很肥的HTML需要清除CSS時的好工具!單純方便清理HTML
An application used to clean dirty html code based on docx to html, built with HtmlSanitizer, C# winForm.
ScreenShot
Usage
Install the HtmlSanitizer NuGet package. Then:
var sanitizer = new HtmlSanitizer();
var dirtyHtml = "<p class='MsoHeader' style='line-height: normal; -ms-layout-grid-mode: char; tab-stops: 24.0pt;'> </p>";
var clean = sanitizer.Sanitize(dirtyHtml);
//result = "<p style="line-height: normal"> </p>"
There’s an online demo, plus there’s also a .NET Fiddle you can play with.
More example code and a description of possible options can be found in the Wiki.
CSS properties allowed by default
background, background-attachment, background-clip, background-color, background-image, background-origin, background-position, background-repeat, background-repeat-x, background-repeat-y, background-size, border, border-bottom, border-bottom-color, border-bottom-left-radius, border-bottom-right-radius, border-bottom-style, border-bottom-width, border-collapse, border-color, border-image, border-image-outset, border-image-repeat, border-image-slice, border-image-source, border-image-width, border-left, border-left-color, border-left-style, border-left-width, border-radius, border-right, border-right-color, border-right-style, border-right-width, border-spacing, border-style, border-top, border-top-color, border-top-left-radius, border-top-right-radius, border-top-style, border-top-width, border-width, bottom, caption-side, clear, clip, color, content, counter-increment, counter-reset, cursor, direction, display, empty-cells, float, font, font-family, font-feature-settings, font-kerning, font-language-override, font-size, font-size-adjust, font-stretch, font-style, font-synthesis, font-variant, font-variant-alternates, font-variant-caps, font-variant-east-asian, font-variant-ligatures, font-variant-numeric, font-variant-position, font-weight, height, left, letter-spacing, line-height, list-style, list-style-image, list-style-position, list-style-type, margin, margin-bottom, margin-left, margin-right, margin-top, max-height, max-width, min-height, min-width, opacity, orphans, outline, outline-color, outline-offset, outline-style, outline-width, overflow, overflow-wrap, overflow-x, overflow-y, padding, padding-bottom, padding-left, padding-right, padding-top, page-break-after, page-break-before, page-break-inside, quotes, right, table-layout, text-align, text-decoration, text-decoration-color, text-decoration-line, text-decoration-skip, text-decoration-style, text-indent, text-transform, top, unicode-bidi, vertical-align, visibility, white-space, widows, width, word-spacing, z-index