MaxSem has uploaded a new change for review. https://gerrit.wikimedia.org/r/282083
Change subject: Add docs ...................................................................... Add docs Change-Id: Ia3ce65a7f227ccba6ec75bcf6431c129efb8d695 --- M README.md 1 file changed, 32 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/HtmlFormatter refs/changes/83/282083/1 diff --git a/README.md b/README.md index 499e5b4..555ea07 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,36 @@ -TODO Write stuff here +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. +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 + +// Theses 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 ------- -- To view, visit https://gerrit.wikimedia.org/r/282083 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia3ce65a7f227ccba6ec75bcf6431c129efb8d695 Gerrit-PatchSet: 1 Gerrit-Project: HtmlFormatter Gerrit-Branch: master Gerrit-Owner: MaxSem <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
