alphagov/govspeak — pull request #8 by floehopper (2012-10-31 19:33:01+00:00)
Title: Pass document options to custom parser to fix bug.

We were seeing a problem where the use of a call-to-action ($CTA)
govspeak extension was breaking the automatic adding of "rel=external"
to external links for Inside Government.

The reason this was breaking was that a number of extensions like
call-to-action cause the construction of another Document instance, but
importantly these other instances were not being passed the same options
as the original document.

The `document_domains` option value was being set as a class instance
variable on the custom parser when the "outer" document instance was
created, but this value was then being overwritten as nil by the
document instances created by the extensions when pre-processing was
run.

Storing the option value as a class instance variable on the custom
parser was always a bit ugly. By digging a bit further into how Kramdown
works, I was able to introduce an intializer for the custom parser which
(once I had defined the `document_domains` option as a valid Kramdown
option) is passed the option value from the original document instance.
This feels like a more robust solution.

I've added a test for the specific scenario we were seeing, but this fix
will also fix the same problem with other extensions that use the
Govspeak::Document parser e.g. "place" ($P), "information" ($I), and
"example" ($E).