@@ -116,4 +116,82 @@ def test_kitchen_sink
116116
117117 assert_equal ( "<p>!>eeuqram/eeuqram< ees ot evoL .yllib@ ,ereht <strong>yeH</strong></p>" , result )
118118 end
119+
120+ def test_context_is_carried_over_in_call
121+ text = "yeH! I _think_ <marquee>@gjtorikian is ~great~</marquee>!"
122+
123+ pipeline = HTMLPipeline . new (
124+ text_filters : [ YehBolderFilter . new ] ,
125+ convert_filter : HTMLPipeline ::ConvertFilter ::MarkdownFilter . new ,
126+ node_filters : [ HTMLPipeline ::NodeFilter ::MentionFilter . new ] ,
127+ )
128+ result = pipeline . call ( text ) [ :output ]
129+
130+ # note:
131+ # - yeH is bolded
132+ # - strikethroughs are rendered
133+ # - mentions are not linked
134+ assert_equal ( "<p><strong>yeH</strong>! I <em>think</em> <a href=\" /gjtorikian\" >@gjtorikian</a> is <del>great</del>!</p>" , result )
135+
136+ context = {
137+ bolded : false ,
138+ markdown : { extension : { strikethrough : false } } ,
139+ base_url : "http://your-domain.com" ,
140+ }
141+ result_with_context = pipeline . call ( text , context : context ) [ :output ]
142+
143+ # note:
144+ # - yeH is not bolded
145+ # - strikethroughs are not rendered
146+ # - mentions are linked
147+ assert_equal ( "<p>yeH! I <em>think</em> <a href=\" http://your-domain.com/gjtorikian\" >@gjtorikian</a> is ~great~!</p>" , result_with_context )
148+ end
149+
150+ def test_text_filter_instance_context_is_carried_over_in_call
151+ text = "yeH! I _think_ <marquee>@gjtorikian is ~great~</marquee>!"
152+
153+ pipeline = HTMLPipeline . new (
154+ text_filters : [ YehBolderFilter . new ( context : { bolded : false } ) ] ,
155+ convert_filter : HTMLPipeline ::ConvertFilter ::MarkdownFilter . new ,
156+ node_filters : [ HTMLPipeline ::NodeFilter ::MentionFilter . new ] ,
157+ )
158+
159+ result = pipeline . call ( text ) [ :output ]
160+
161+ # note:
162+ # - yeH is not bolded due to previous context
163+ assert_equal ( "<p>yeH! I <em>think</em> <a href=\" /gjtorikian\" >@gjtorikian</a> is <del>great</del>!</p>" , result )
164+ end
165+
166+ def test_convert_filter_instance_context_is_carried_over_in_call
167+ text = "yeH! I _think_ <marquee>@gjtorikian is ~great~</marquee>!"
168+
169+ pipeline = HTMLPipeline . new (
170+ text_filters : [ YehBolderFilter . new ] ,
171+ convert_filter : HTMLPipeline ::ConvertFilter ::MarkdownFilter . new ( context : { extension : { strikethrough : false } } ) ,
172+ node_filters : [ HTMLPipeline ::NodeFilter ::MentionFilter . new ] ,
173+ )
174+
175+ result = pipeline . call ( text ) [ :output ]
176+
177+ # note:
178+ # - strikethroughs are not rendered due to previous context
179+ assert_equal ( "<p><strong>yeH</strong>! I <em>think</em> <a href=\" /gjtorikian\" >@gjtorikian</a> is <del>great</del>!</p>" , result )
180+ end
181+
182+ def test_node_filter_instance_context_is_carried_over_in_call
183+ text = "yeH! I _think_ <marquee>@gjtorikian is ~great~</marquee>!"
184+
185+ pipeline = HTMLPipeline . new (
186+ text_filters : [ YehBolderFilter . new ] ,
187+ convert_filter : HTMLPipeline ::ConvertFilter ::MarkdownFilter . new ,
188+ node_filters : [ HTMLPipeline ::NodeFilter ::MentionFilter . new ( context : { base_url : "http://your-domain.com" } ) ] ,
189+ )
190+
191+ result = pipeline . call ( text ) [ :output ]
192+
193+ # note:
194+ # - mentions are linked
195+ assert_equal ( "<p><strong>yeH</strong>! I <em>think</em> <a href=\" http://your-domain.com/gjtorikian\" >@gjtorikian</a> is <del>great</del>!</p>" , result )
196+ end
119197end
0 commit comments