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.
| VERSION | = | '2.10.0'.freeze | ||
| 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 | |
| DocumentFragment | = | Nokogiri::HTML::DocumentFragment | Our DOM implementation. |
| 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. |
Parse a String into a DocumentFragment object. When a DocumentFragment is provided, return it verbatim.
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.
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.