Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
The Wiki.Filters package provides a simple filter framework that allows to plug specific filters when a wiki document is parsed and processed. The Filter_Type implements the Document_Reader interface to catch all the wiki document operations and it forwards the different calls to a next wiki document instance. A filter can do some operations while calls are made so that it can:
- Get the text content and filter it by looking at forbidden words in some dictionary,
- Ignore some formatting construct (for example to forbid the use of links),
- Verify and do some corrections on HTML content embedded in wiki text,
- Expand some plugins, specific links to complex content.
To implement a new filter, the Filter_Type type must be used as a base type and some of the operations have to be overriden. The default Filter_Type operations just propagate the call to the attached wiki document instance (ie, a kind of pass through filter).
The TOC_Filter is a filter used to build the table of contents. It collects the headers with the section level as they are added to the wiki document. The TOC is built in the wiki document as a separate node and it can be retrieved by using the Get_TOC function. To use the filter, declare an aliased instance:
TOC : aliased Wiki.Filters.TOC.TOC_Filter;
and add the filter to the Wiki parser engine:
The Wiki.Filters.Html package implements a customizable HTML filter that verifies the HTML content embedded in the Wiki text. The HTML filter can be customized to indicate the HTML tags that must be accepted or ignored. By default, the filter accepts all HTML tags except 'script', 'style'.
The HTML filter may be declared and configured as follows:
F : aliased Wiki.Filters.Html.Html_Filter_Type; ... F.Forbidden (Wiki.Filters.Html.SCRIPT_TAG); F.Forbidden (Wiki.Filters.Html.A_TAG);
The filter is added to the Wiki parser filter chain by using the Add_Filter operation:
The Wiki.Filters.Collectors package defines three filters that can be used to collect words, links or images contained in a Wiki document. The collector filters are inserted in the filter chain and they collect the data as the Wiki text is parsed. After the parsing, the collector filters have collected either the words or the links and they can be queried by using the Find or Iterate operations.
The filter is inserted in the filter chain before parsing the Wiki document.
Words : aliased Wiki.Filters.Collectors.Word_Collector_Type; ... Engine.Add_Filter (Words'Unchecked_Access);
Once the document is parsed, the collector filters contains the data that was collected. The Iterate procedure can be used to have a procedure called for each value collected by the filter.
The Wiki.Filters.Autolink package defines a filter that transforms URLs in the Wiki text into links. The filter should be inserted in the filter chain after the HTML and after the collector filters. The filter looks for the text and transforms http:// and https:// links into real links. When such links are found, the text is split so that next filters see only the text without links and the Add_Link filter operations are called with the link.
Generated by Dynamo from wiki-filters.ads