Added method Document.getCounter. Interaction with using counters in … #493
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…the Document not possible yet
Fixes #488.
Added methods
Document.getCounter(counterName)
andDocument.getCounter(counterName, initialValue)
to the API.The interaction with using the {counter:mycounter} macro is not possible though.
If I've understood it correctly the counters are finally stored in an attribute having the name of the counter on the Document.
All Document attributes are restored after for example BlockMacros are called in Document#parse.
The counter macro however is invoked in the conversion phase by the Substitutor after the attributes have been reset. Therefore the counter restarts at 1 again.
The first test reflects this behavior.
With a TreeProcessor it works a bit better in so far as the document can continue using the counters as the reset happens before the invocation of the Treeprocessors.
But I'd guess that when having a counter in the document, then reusing the same counter in a TreeProcessor will result in the counter sequence 2, 1.
When using counters both in a processor and the document, I think it would be better to make the processor insert the text
{counter:foocounter}
instead of invoking the method on the Document.To wrap it up I wonder if it makes sense at all to invoke this API from an extension and if it has already been used by Ruby extensions.
(Maybe I completely missed a point, that's also perfectly possible)