Class: Swift::Playground::Util::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/swift/playground/util/pipeline.rb,
lib/swift/playground/util/pipeline/section_filter.rb,
lib/swift/playground/util/pipeline/unicode_emoji_filter.rb

Defined Under Namespace

Classes: SectionFilter, UnicodeEmojiFilter

Constant Summary collapse

HTMLWhitelist =
HTML::Pipeline::SanitizationFilter::WHITELIST.deep_dup.tap do |whitelist|
  # Allow <section> elements to have a 'role' attribute (which we use to
  # distinguish between sections):
  whitelist[:elements] << 'section'
  whitelist[:attributes]['section'] = ['role']
end
MarkdownFilterChain =
[
  HTML::Pipeline::MarkdownFilter,

  # Filter for splitting out resulting HTML into separate HTML and swift
  # <section> elements, with appropriate metadata attached:
  SectionFilter,

  HTML::Pipeline::SanitizationFilter
]
EmojiFilter =

Custom Emoji filter than replaces with unicode characters rather than images (because a Swift Playground will always be opened on OS X which supports rendering the unicode version natively):

UnicodeEmojiFilter
SyntaxHighlightFilter =
(HTML::Pipeline::SyntaxHighlightFilter if SyntaxHighlighting.available?)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filters = []) ⇒ Pipeline

Returns a new instance of Pipeline.



36
37
38
# File 'lib/swift/playground/util/pipeline.rb', line 36

def initialize(filters = [])
  self.filters = filters
end

Instance Attribute Details

#filtersObject

Returns the value of attribute filters.



34
35
36
# File 'lib/swift/playground/util/pipeline.rb', line 34

def filters
  @filters
end

Instance Method Details

#call(html, context = {}, result = nil) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/swift/playground/util/pipeline.rb', line 44

def call(html, context = {}, result = nil)
  context = {
    gfm: true, # Enable support for GitHub formatted Markdown
    whitelist: HTMLWhitelist # Control HTML elements that are sanitized
  }.merge(context)

  HTML::Pipeline.new(filters.compact, context).call(html, context, result)
end

#has_filters?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/swift/playground/util/pipeline.rb', line 40

def has_filters?
  self.filters.any?
end