Class HTML::Pipeline
In: lib/html/pipeline/emoji_filter.rb
lib/html/pipeline/text_filter.rb
lib/html/pipeline/sanitization_filter.rb
lib/html/pipeline/syntax_highlight_filter.rb
lib/html/pipeline/body_content.rb
lib/html/pipeline/textile_filter.rb
lib/html/pipeline/image_max_width_filter.rb
lib/html/pipeline/https_filter.rb
lib/html/pipeline/plain_text_input_filter.rb
lib/html/pipeline/absolute_source_filter.rb
lib/html/pipeline/autolink_filter.rb
lib/html/pipeline/@mention_filter.rb
lib/html/pipeline/filter.rb
lib/html/pipeline/email_reply_filter.rb
lib/html/pipeline/camo_filter.rb
lib/html/pipeline/image_filter.rb
lib/html/pipeline/toc_filter.rb
lib/html/pipeline/version.rb
lib/html/pipeline/markdown_filter.rb
lib/html/pipeline.rb
Parent: Object

GitHub HTML processing filters and utilities. This module includes a small framework for defining DOM based content filters and applying them to user provided content.

See HTML::Pipeline::Filter for information on building filters.

Construct a Pipeline for running multiple HTML filters. A pipeline is created once with one to many filters, and it then can be `call`ed many times over the course of its lifetime with input.

filters - Array of Filter objects. Each must respond to call(doc,

                  context) and return the modified DocumentFragment or a
                  String containing HTML markup. Filters are performed in the
                  order provided.

default_context - The default context hash. Values specified here will be merged

                  into values from the each individual pipeline run.  Can NOT be
                  nil.  Default: empty Hash.

result_class - The default Class of the result object for individual

                  calls.  Default: Hash.  Protip:  Pass in a Struct to get
                  some semblance of type safety.

Methods

Classes and Modules

Class HTML::Pipeline::AbsoluteSourceFilter
Class HTML::Pipeline::AutolinkFilter
Class HTML::Pipeline::BodyContent
Class HTML::Pipeline::CamoFilter
Class HTML::Pipeline::EmailReplyFilter
Class HTML::Pipeline::EmojiFilter
Class HTML::Pipeline::Filter
Class HTML::Pipeline::HttpsFilter
Class HTML::Pipeline::ImageFilter
Class HTML::Pipeline::ImageMaxWidthFilter
Class HTML::Pipeline::MarkdownFilter
Class HTML::Pipeline::MentionFilter
Class HTML::Pipeline::MissingDependencyError
Class HTML::Pipeline::PlainTextInputFilter
Class HTML::Pipeline::SanitizationFilter
Class HTML::Pipeline::SyntaxHighlightFilter
Class HTML::Pipeline::TableOfContentsFilter
Class HTML::Pipeline::TextFilter
Class HTML::Pipeline::TextileFilter

Constants

UsernamePattern = /[a-z0-9][a-z0-9-]*/   Default pattern used to extract usernames from text. The value can be overriden by providing the username_pattern variable in the context.
MentionLogins = %w[ mention mentions mentioned mentioning ].freeze   List of username logins that, when mentioned, link to the blog post about @mentions instead of triggering a real mention.
IGNORE_PARENTS = %w(pre code a style script).to_set   Don‘t look for mentions in text nodes that are children of these elements
VERSION = '2.10.0'.freeze
DocumentFragment = Nokogiri::HTML::DocumentFragment   Our DOM implementation.

Attributes

default_instrumentation_service  [RW]  Public: Default instrumentation service for new pipeline objects.
filters  [R]  Public: Returns an Array of Filter objects for this Pipeline.
instrumentation_name  [W]  Public: String name for this Pipeline. Defaults to Class name.
instrumentation_service  [RW]  Public: Instrumentation service for the pipeline. Set an ActiveSupport::Notifications compatible object to enable.

Public Class methods

Parse a String into a DocumentFragment object. When a DocumentFragment is provided, return it verbatim.

Public Instance methods

Apply all filters in the pipeline to the given HTML.

html - A String containing HTML or a DocumentFragment object. context - The context hash passed to each filter. See the Filter docs

          for more info on possible values. This object MUST NOT be modified
          in place by filters.  Use the Result for passing state back.

result - The result Hash passed to each filter for modification. This

          is where Filters store extracted information from the content.

Returns the result Hash after being filtered by this Pipeline. Contains an :output key with the DocumentFragment or String HTML markup based on the output of the last filter in the pipeline.

Internal: Default payload for instrumentation.

Accepts a Hash of additional payload data to be merged.

Returns a Hash.

The URL to provide when someone @mentions a "mention" name, such as @mention or @mentioned, that will give them more info on mentions.

Internal: if the `instrumentation_service` object is set, instruments the block, otherwise the block is ran without instrumentation.

Returns the result of the provided block.

Replace user @mentions in text with links to the mentioned user‘s profile page.

text - String text to replace @mention usernames in. base_url - The base URL used to construct user profile URLs. info_url - The "more info" URL used to link to more info on @mentions.

            If nil we don't link @mention or @mentioned.

username_pattern - Regular expression used to identify usernames in

                    text

Returns a string with @mentions replaced with links. All links have a ‘user-mention’ class name attached for styling.

Internal: Applies a specific filter to the supplied doc.

The filter is instrumented.

Returns the result of the filter.

Public: setup instrumentation for this pipeline.

Returns nothing.

Like call but guarantee the value returned is a DocumentFragment. Pipelines may return a DocumentFragment or a String. Callers that need a DocumentFragment should use this method.

Like call but guarantee the value returned is a string of HTML markup.

[Validate]