{"id":253,"date":"2023-07-21T08:46:00","date_gmt":"2023-07-21T15:46:00","guid":{"rendered":"https:\/\/dejal.com\/blog\/?p=253"},"modified":"2023-07-21T08:46:48","modified_gmt":"2023-07-21T15:46:48","slug":"simon-context-filter","status":"publish","type":"post","link":"https:\/\/dejal.com\/blog\/simon-context-filter\/","title":{"rendered":"Simon Context filter"},"content":{"rendered":"<body><p><\/p>\n<p>The <strong>Context<\/strong> filter in <a href=\"https:\/\/dejal.com\/simon\/\">Simon<\/a> is a sophisticated filter that takes the previous filter\u2019s input and match range to output some context around that filter\u2019s output text.<\/p>\n<p>It includes controls to specify the maximum number of characters before and\/or after the matched range, and\/or a delimiter before and\/or after the matched range. So for example you can show up to 50 characters, stopping at a line break.<\/p>\n<p>This filter is unusual in that it requires a previous filter to be used, and that needs to be either a <strong>Block<\/strong>\u2013 or <strong>Find<\/strong>-based filter, as those are the only ones that output the needed match range information.<\/p>\n<p>The <strong>Context<\/strong> filter uses the <strong>Input<\/strong> specified in the test to determine which filter\u2019s input and match variables to use: if you have two previous filters, you can make the <strong>Context<\/strong> filter look at the first one by choosing <code>Filter<strong>1<\/strong>OutputText<\/code> instead of the default <code>FilterOutputText<\/code> (which means the proceeding filter).<\/p>\n<p>The match range is available in variables used by the <strong>Context<\/strong> filter, and can be used in your custom filters or notifiers if you wish:<\/p>\n<ul>\n<li><code>{FilterMatchLocation}<\/code>: the position of the match in the input text, e.g. the text between the <strong>Block<\/strong>s, or the <strong>Find<\/strong> result. Note that the location is zero-based.<\/li>\n<li><code>{FilterMatchLength}<\/code>: The length of that match.<\/li>\n<li><code>{FilterMatchEnd}<\/code>: The location plus the length, for convenience.<\/li>\n<\/ul>\n<p>You don\u2019t need to worry about these variables for the <strong>Context<\/strong> filter, though; it uses them internally.<\/p>\n<p>Here\u2019s a simple example of this filter in action.<\/p>\n<p>This is from a Web test that looks at the <a href=\"http:\/\/daringfireball.net\">Daring Fireball<\/a> site. It has a <strong>Find Required<\/strong> filter to look for the word \u201cfinally\u201d, then if that succeeds a <strong>Context<\/strong> filter to output the enclosing paragraph. To round it out, if the <strong>Find<\/strong> filter fails, the <strong>Override as Unchanged<\/strong> failure case is used, to avoid the test resulting in a failure if Gruber hasn\u2019t used the word \u201cfinally\u201d recently.<\/p>\n<p>Below the filters, you can see the <strong>Preview<\/strong> pane\u2019s output, which you\u2019ll notice includes the word \u201cfinally\u201d towards the end.<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/dejal.com\/files\/2016\/simon\/context.png?resize=698%2C568&#038;ssl=1\" alt=\"Context filter\" width=\"698\" height=\"568\" border=\"0\" loading=\"lazy\"><\/p>\n<p>I hope this will be a useful filter for many of your tests. Simon is a powerful tool, with lots of other handy filters, services, and notifiers.<\/p>\n<p><\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>The Context filter in Simon is a sophisticated filter that takes the previous filter\u2019s input and match range to output some context around that filter\u2019s output text. It includes controls to specify the maximum number of characters before and\/or after the matched range, and\/or a delimiter before and\/or after the matched range. So for example [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[16,4],"tags":[],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry","category-faq","category-simon"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/dejal.com\/blog\/wp-json\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dejal.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dejal.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dejal.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dejal.com\/blog\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":1,"href":"https:\/\/dejal.com\/blog\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":254,"href":"https:\/\/dejal.com\/blog\/wp-json\/wp\/v2\/posts\/253\/revisions\/254"}],"wp:attachment":[{"href":"https:\/\/dejal.com\/blog\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dejal.com\/blog\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dejal.com\/blog\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}