@@ -60,9 +60,15 @@ results tothe next filter. A pipeline has several kinds of filters available to
6060
6161You can assemble each sequence into a single pipeline, or choose to call each filter individually.
6262
63- As an example, suppose we want to transform Commonmark source text into Markdown HTML. With the content, we also want to :
63+ As an example, suppose we want to transform Commonmark source text into Markdown HTML:
6464
65- - change every instance of ` $NAME ` to "`Johnny"
65+ ```
66+ Hey there, @gjtorikian
67+ ```
68+
69+ With the content, we also want to:
70+
71+ - change every instance of ` Hey ` to ` Hello `
6672- strip undesired HTML
6773- linkify @mention
6874
@@ -73,7 +79,7 @@ require 'html_pipeline'
7379
7480class HelloJohnnyFilter < HTMLPipelineFilter
7581 def call
76- text.gsub (" $NAME " , " Johnny " )
82+ text.gsub (" Hey " , " Hello " )
7783 end
7884end
7985
@@ -104,11 +110,21 @@ used to pass around arguments and metadata between filters in a pipeline. For
104110example, if you want to disable footnotes in the ` MarkdownFilter ` , you can pass an option in the context hash:
105111
106112``` ruby
107- context = { markdown: { extensions: { footnotes: false } } }
113+ context = { markdown: { extensions: { footnotes: false } } }
108114filter = HTMLPipeline ::ConvertFilter ::MarkdownFilter .new (context: context)
109115filter.call(" Hi **world**!" )
110116```
111117
118+ Alternatively, you can construct a pipeline, and pass in a context during the call:
119+
120+ ``` ruby
121+ pipeline = HTMLPipeline .new (
122+ convert_filter: HTMLPipeline ::ConvertFilter ::MarkdownFilter .new ,
123+ node_filters: [HTMLPipeline ::NodeFilter ::MentionFilter .new ]
124+ )
125+ pipeline.call(user_supplied_text, context: { markdown: { extensions: { footnotes: false } } })
126+ ```
127+
112128Please refer to the documentation for each filter to understand what configuration options are available.
113129
114130### More Examples
0 commit comments