2017 © Pedro Peláez
 

library html-formatter

Performs transformations of HTML by wrapping around libxml2 and working around its countless bugs.

image

wikimedia/html-formatter

Performs transformations of HTML by wrapping around libxml2 and working around its countless bugs.

  • Friday, June 1, 2018
  • by mediawiki
  • Repository
  • 17 Watchers
  • 0 Stars
  • 141,574 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 8 % Grown

The README.md

HtmlFormatter is a library spun off MediaWiki that allows you to load HTML into DomDocument, perform manipulations on it, and then return a HTML string., (*1)

Usage

use HtmlFormatter\HtmlFormatter;
// Load HTML that already has doctype and stuff
$formatter = new HtmlFormatter( $html );

// ...or one that doesn't have it
$formatter = new HtmlFormatter( HtmlFormatter::wrapHTML( $html ) );

// Add rules to remove some stuff
$formatter->remove( 'img' );
$formatter->remove( [ '.some_css_class', '#some_id', 'div.some_other_class' ] );
// Only the above syntax is supported, not full CSS/jQuery selectors

// These tags get replaced with their inner HTML,
// e.g. <tag>foo</tag> --> foo
// Only tag names are supported here
$formatter->flatten( 'span' );
$formatter->flatten( [ 'code', 'pre' ] );

// Actually perform the removals
$formatter->filterContent();

// Direct DomDocument manipulations are possible
$formatter->getDoc()->createElement( 'p', 'Appended paragraph' );

// Get resulting HTML
$processedHtml = $formatter->getText();

License

Copyright 2011-2024 MediaWiki contributors, (*2)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version., (*3)

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details., (*4)

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. http://www.gnu.org/copyleft/gpl.html, (*5)

The Versions

01/06 2018

dev-master

9999999-dev https://www.mediawiki.org/wiki/HtmlFormatter

Performs transformations of HTML by wrapping around libxml2 and working around its countless bugs.

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

  • ext-mbstring *
  • php >=5.5.9

 

The Development Requires

by MediaWiki contributors

14/04 2018

1.0.2

1.0.2.0 https://www.mediawiki.org/wiki/HtmlFormatter

Performs transformations of HTML by wrapping around libxml2 and working around its countless bugs.

  Sources   Download

GPL-2.0-or-later

The Requires

  • php >=5.5
  • ext-mbstring *

 

The Development Requires

by MediaWiki contributors

07/04 2016

1.0.1

1.0.1.0 https://www.mediawiki.org/wiki/HtmlFormatter

Performs transformations of HTML by wrapping around libxml2 and working around its countless bugs.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5
  • ext-mbstring *

 

The Development Requires

by MediaWiki contributors

07/04 2016

1.0.0

1.0.0.0 https://www.mediawiki.org/wiki/HtmlFormatter

Performs transformations of HTML by wrapping around libxml2 and working around its countless bugs.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5
  • ext-intl *
  • ext-mbstring *

 

The Development Requires

by MediaWiki contributors