coridoc-adoc 2.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/Rakefile +8 -0
- data/grammar/coridoc-adoc.artifact.json +1 -0
- data/grammar/coridoc-adoc.parg +445 -0
- data/lib/coridoc/asciidoc/bindings/definition_list_tree.rb +125 -0
- data/lib/coridoc/asciidoc/bindings/structure_hooks.rb +153 -0
- data/lib/coridoc/asciidoc/bindings.rb +393 -0
- data/lib/coridoc/asciidoc/builder/block_builder.rb +49 -0
- data/lib/coridoc/asciidoc/builder/detection.rb +184 -0
- data/lib/coridoc/asciidoc/builder/element_builder.rb +135 -0
- data/lib/coridoc/asciidoc/builder/list_builder.rb +126 -0
- data/lib/coridoc/asciidoc/builder/text_builder.rb +23 -0
- data/lib/coridoc/asciidoc/builder.rb +227 -0
- data/lib/coridoc/asciidoc/delimiter_mapping.rb +16 -0
- data/lib/coridoc/asciidoc/formatter.rb +75 -0
- data/lib/coridoc/asciidoc/lint/document_title.rb +26 -0
- data/lib/coridoc/asciidoc/lint/empty_section.rb +45 -0
- data/lib/coridoc/asciidoc/lint/registrations.rb +56 -0
- data/lib/coridoc/asciidoc/lint.rb +26 -0
- data/lib/coridoc/asciidoc/model/admonition.rb +42 -0
- data/lib/coridoc/asciidoc/model/anchorable.rb +64 -0
- data/lib/coridoc/asciidoc/model/attached.rb +26 -0
- data/lib/coridoc/asciidoc/model/attribute.rb +22 -0
- data/lib/coridoc/asciidoc/model/attribute_list/matchers.rb +45 -0
- data/lib/coridoc/asciidoc/model/attribute_list.rb +257 -0
- data/lib/coridoc/asciidoc/model/attribute_list_attribute.rb +11 -0
- data/lib/coridoc/asciidoc/model/audio.rb +44 -0
- data/lib/coridoc/asciidoc/model/author.rb +36 -0
- data/lib/coridoc/asciidoc/model/base.rb +148 -0
- data/lib/coridoc/asciidoc/model/bibliography.rb +37 -0
- data/lib/coridoc/asciidoc/model/bibliography_entry.rb +61 -0
- data/lib/coridoc/asciidoc/model/block/core.rb +139 -0
- data/lib/coridoc/asciidoc/model/block/example.rb +14 -0
- data/lib/coridoc/asciidoc/model/block/listing.rb +14 -0
- data/lib/coridoc/asciidoc/model/block/literal.rb +14 -0
- data/lib/coridoc/asciidoc/model/block/open.rb +14 -0
- data/lib/coridoc/asciidoc/model/block/pass.rb +14 -0
- data/lib/coridoc/asciidoc/model/block/quote.rb +14 -0
- data/lib/coridoc/asciidoc/model/block/reviewer_comment.rb +14 -0
- data/lib/coridoc/asciidoc/model/block/side.rb +14 -0
- data/lib/coridoc/asciidoc/model/block/source_code.rb +14 -0
- data/lib/coridoc/asciidoc/model/block.rb +21 -0
- data/lib/coridoc/asciidoc/model/break.rb +33 -0
- data/lib/coridoc/asciidoc/model/comment_block.rb +33 -0
- data/lib/coridoc/asciidoc/model/comment_line.rb +30 -0
- data/lib/coridoc/asciidoc/model/content_list.rb +334 -0
- data/lib/coridoc/asciidoc/model/document.rb +205 -0
- data/lib/coridoc/asciidoc/model/document_attributes.rb +43 -0
- data/lib/coridoc/asciidoc/model/glossaries.rb +11 -0
- data/lib/coridoc/asciidoc/model/header.rb +57 -0
- data/lib/coridoc/asciidoc/model/highlight.rb +11 -0
- data/lib/coridoc/asciidoc/model/image/attribute_extractor.rb +142 -0
- data/lib/coridoc/asciidoc/model/image/block_image/attribute_list.rb +23 -0
- data/lib/coridoc/asciidoc/model/image/block_image.rb +33 -0
- data/lib/coridoc/asciidoc/model/image/core/attribute_list.rb +43 -0
- data/lib/coridoc/asciidoc/model/image/core.rb +81 -0
- data/lib/coridoc/asciidoc/model/image/inline_image.rb +24 -0
- data/lib/coridoc/asciidoc/model/image.rb +15 -0
- data/lib/coridoc/asciidoc/model/include.rb +66 -0
- data/lib/coridoc/asciidoc/model/inline/anchor.rb +41 -0
- data/lib/coridoc/asciidoc/model/inline/attribute_reference.rb +25 -0
- data/lib/coridoc/asciidoc/model/inline/base.rb +15 -0
- data/lib/coridoc/asciidoc/model/inline/bold.rb +38 -0
- data/lib/coridoc/asciidoc/model/inline/cross_reference.rb +29 -0
- data/lib/coridoc/asciidoc/model/inline/cross_reference_arg.rb +15 -0
- data/lib/coridoc/asciidoc/model/inline/footnote.rb +34 -0
- data/lib/coridoc/asciidoc/model/inline/hard_line_break.rb +24 -0
- data/lib/coridoc/asciidoc/model/inline/highlight.rb +36 -0
- data/lib/coridoc/asciidoc/model/inline/italic.rb +38 -0
- data/lib/coridoc/asciidoc/model/inline/link.rb +46 -0
- data/lib/coridoc/asciidoc/model/inline/monospace.rb +39 -0
- data/lib/coridoc/asciidoc/model/inline/passthrough.rb +14 -0
- data/lib/coridoc/asciidoc/model/inline/quotation.rb +25 -0
- data/lib/coridoc/asciidoc/model/inline/small.rb +25 -0
- data/lib/coridoc/asciidoc/model/inline/span.rb +38 -0
- data/lib/coridoc/asciidoc/model/inline/stem.rb +24 -0
- data/lib/coridoc/asciidoc/model/inline/strikethrough.rb +39 -0
- data/lib/coridoc/asciidoc/model/inline/subscript.rb +33 -0
- data/lib/coridoc/asciidoc/model/inline/superscript.rb +33 -0
- data/lib/coridoc/asciidoc/model/inline/underline.rb +25 -0
- data/lib/coridoc/asciidoc/model/inline.rb +32 -0
- data/lib/coridoc/asciidoc/model/line_break.rb +11 -0
- data/lib/coridoc/asciidoc/model/list/base.rb +41 -0
- data/lib/coridoc/asciidoc/model/list/core.rb +41 -0
- data/lib/coridoc/asciidoc/model/list/definition.rb +34 -0
- data/lib/coridoc/asciidoc/model/list/definition_item.rb +62 -0
- data/lib/coridoc/asciidoc/model/list/item.rb +72 -0
- data/lib/coridoc/asciidoc/model/list/nestable.rb +18 -0
- data/lib/coridoc/asciidoc/model/list/ordered.rb +34 -0
- data/lib/coridoc/asciidoc/model/list/unordered.rb +34 -0
- data/lib/coridoc/asciidoc/model/list.rb +31 -0
- data/lib/coridoc/asciidoc/model/named_attribute.rb +12 -0
- data/lib/coridoc/asciidoc/model/paragraph.rb +59 -0
- data/lib/coridoc/asciidoc/model/rejected_positional_attribute.rb +12 -0
- data/lib/coridoc/asciidoc/model/resolvable.rb +71 -0
- data/lib/coridoc/asciidoc/model/resolver.rb +430 -0
- data/lib/coridoc/asciidoc/model/reviewer_note.rb +52 -0
- data/lib/coridoc/asciidoc/model/revision.rb +47 -0
- data/lib/coridoc/asciidoc/model/section.rb +122 -0
- data/lib/coridoc/asciidoc/model/serialization/asciidoc_adapter.rb +28 -0
- data/lib/coridoc/asciidoc/model/serialization/asciidoc_mapping.rb +42 -0
- data/lib/coridoc/asciidoc/model/serialization/asciidoc_mapping_rule.rb +41 -0
- data/lib/coridoc/asciidoc/model/serialization/asciidoc_transform.rb +211 -0
- data/lib/coridoc/asciidoc/model/serialization/errors.rb +57 -0
- data/lib/coridoc/asciidoc/model/serialization.rb +39 -0
- data/lib/coridoc/asciidoc/model/spacing.rb +282 -0
- data/lib/coridoc/asciidoc/model/table.rb +44 -0
- data/lib/coridoc/asciidoc/model/table_cell.rb +122 -0
- data/lib/coridoc/asciidoc/model/table_row.rb +26 -0
- data/lib/coridoc/asciidoc/model/tag.rb +36 -0
- data/lib/coridoc/asciidoc/model/term.rb +48 -0
- data/lib/coridoc/asciidoc/model/text_element.rb +117 -0
- data/lib/coridoc/asciidoc/model/title.rb +85 -0
- data/lib/coridoc/asciidoc/model/video/attribute_list.rb +43 -0
- data/lib/coridoc/asciidoc/model/video.rb +49 -0
- data/lib/coridoc/asciidoc/model.rb +75 -0
- data/lib/coridoc/asciidoc/parse_error.rb +161 -0
- data/lib/coridoc/asciidoc/parser/admonition.rb +35 -0
- data/lib/coridoc/asciidoc/parser/attribute_list.rb +113 -0
- data/lib/coridoc/asciidoc/parser/base.rb +143 -0
- data/lib/coridoc/asciidoc/parser/bibliography.rb +31 -0
- data/lib/coridoc/asciidoc/parser/block.rb +239 -0
- data/lib/coridoc/asciidoc/parser/block_assembler.rb +120 -0
- data/lib/coridoc/asciidoc/parser/block_header.rb +78 -0
- data/lib/coridoc/asciidoc/parser/cache.rb +155 -0
- data/lib/coridoc/asciidoc/parser/citation.rb +38 -0
- data/lib/coridoc/asciidoc/parser/content.rb +85 -0
- data/lib/coridoc/asciidoc/parser/document_attributes.rb +32 -0
- data/lib/coridoc/asciidoc/parser/fix_files.rb +76 -0
- data/lib/coridoc/asciidoc/parser/frontmatter_parser.rb +24 -0
- data/lib/coridoc/asciidoc/parser/header.rb +31 -0
- data/lib/coridoc/asciidoc/parser/inline.rb +313 -0
- data/lib/coridoc/asciidoc/parser/list.rb +334 -0
- data/lib/coridoc/asciidoc/parser/metadata_detector.rb +164 -0
- data/lib/coridoc/asciidoc/parser/paragraph.rb +66 -0
- data/lib/coridoc/asciidoc/parser/positioned_string.rb +71 -0
- data/lib/coridoc/asciidoc/parser/rule_dispatcher.rb +161 -0
- data/lib/coridoc/asciidoc/parser/section.rb +60 -0
- data/lib/coridoc/asciidoc/parser/stem.rb +19 -0
- data/lib/coridoc/asciidoc/parser/table.rb +163 -0
- data/lib/coridoc/asciidoc/parser/term.rb +70 -0
- data/lib/coridoc/asciidoc/parser/text.rb +174 -0
- data/lib/coridoc/asciidoc/parser/tree_materializer.rb +28 -0
- data/lib/coridoc/asciidoc/parser.rb +14 -0
- data/lib/coridoc/asciidoc/reference_materializers/navigation.rb +52 -0
- data/lib/coridoc/asciidoc/reference_materializers.rb +18 -0
- data/lib/coridoc/asciidoc/serializer/adoc_serializer.rb +86 -0
- data/lib/coridoc/asciidoc/serializer/element_registry.rb +65 -0
- data/lib/coridoc/asciidoc/serializer/fallback_serializer.rb +21 -0
- data/lib/coridoc/asciidoc/serializer/formatter.rb +144 -0
- data/lib/coridoc/asciidoc/serializer/registrations.rb +25 -0
- data/lib/coridoc/asciidoc/serializer/serialization_context.rb +238 -0
- data/lib/coridoc/asciidoc/serializer/serializers/admonition.rb +19 -0
- data/lib/coridoc/asciidoc/serializer/serializers/attribute.rb +23 -0
- data/lib/coridoc/asciidoc/serializer/serializers/attribute_list.rb +40 -0
- data/lib/coridoc/asciidoc/serializer/serializers/attribute_list_attribute.rb +18 -0
- data/lib/coridoc/asciidoc/serializer/serializers/audio.rb +33 -0
- data/lib/coridoc/asciidoc/serializer/serializers/author.rb +20 -0
- data/lib/coridoc/asciidoc/serializer/serializers/base.rb +152 -0
- data/lib/coridoc/asciidoc/serializer/serializers/bibliography.rb +35 -0
- data/lib/coridoc/asciidoc/serializer/serializers/bibliography_entry.rb +24 -0
- data/lib/coridoc/asciidoc/serializer/serializers/block/core.rb +70 -0
- data/lib/coridoc/asciidoc/serializer/serializers/block/example.rb +17 -0
- data/lib/coridoc/asciidoc/serializer/serializers/block/listing.rb +22 -0
- data/lib/coridoc/asciidoc/serializer/serializers/block/literal.rb +17 -0
- data/lib/coridoc/asciidoc/serializer/serializers/block/open.rb +22 -0
- data/lib/coridoc/asciidoc/serializer/serializers/block/pass.rb +17 -0
- data/lib/coridoc/asciidoc/serializer/serializers/block/quote.rb +17 -0
- data/lib/coridoc/asciidoc/serializer/serializers/block/reviewer_comment.rb +17 -0
- data/lib/coridoc/asciidoc/serializer/serializers/block/side.rb +22 -0
- data/lib/coridoc/asciidoc/serializer/serializers/block/source_code.rb +24 -0
- data/lib/coridoc/asciidoc/serializer/serializers/block.rb +23 -0
- data/lib/coridoc/asciidoc/serializer/serializers/break.rb +18 -0
- data/lib/coridoc/asciidoc/serializer/serializers/comment_block.rb +22 -0
- data/lib/coridoc/asciidoc/serializer/serializers/comment_line.rb +22 -0
- data/lib/coridoc/asciidoc/serializer/serializers/document.rb +70 -0
- data/lib/coridoc/asciidoc/serializer/serializers/document_attributes.rb +21 -0
- data/lib/coridoc/asciidoc/serializer/serializers/header.rb +24 -0
- data/lib/coridoc/asciidoc/serializer/serializers/highlight.rb +23 -0
- data/lib/coridoc/asciidoc/serializer/serializers/image/core.rb +32 -0
- data/lib/coridoc/asciidoc/serializer/serializers/image.rb +14 -0
- data/lib/coridoc/asciidoc/serializer/serializers/include.rb +19 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/anchor.rb +20 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/attribute_reference.rb +20 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/bold.rb +26 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/cross_reference.rb +30 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/cross_reference_arg.rb +20 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/footnote.rb +24 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/hard_line_break.rb +20 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/highlight.rb +26 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/italic.rb +26 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/link.rb +38 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/monospace.rb +26 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/passthrough.rb +25 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/quotation.rb +21 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/small.rb +20 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/span.rb +35 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/stem.rb +23 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/strikethrough.rb +29 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/subscript.rb +29 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/superscript.rb +26 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline/underline.rb +20 -0
- data/lib/coridoc/asciidoc/serializer/serializers/inline.rb +33 -0
- data/lib/coridoc/asciidoc/serializer/serializers/line_break.rb +18 -0
- data/lib/coridoc/asciidoc/serializer/serializers/list/core.rb +47 -0
- data/lib/coridoc/asciidoc/serializer/serializers/list/definition.rb +37 -0
- data/lib/coridoc/asciidoc/serializer/serializers/list/definition_item.rb +58 -0
- data/lib/coridoc/asciidoc/serializer/serializers/list/item.rb +124 -0
- data/lib/coridoc/asciidoc/serializer/serializers/list/ordered.rb +24 -0
- data/lib/coridoc/asciidoc/serializer/serializers/list/unordered.rb +29 -0
- data/lib/coridoc/asciidoc/serializer/serializers/list.rb +19 -0
- data/lib/coridoc/asciidoc/serializer/serializers/named_attribute.rb +22 -0
- data/lib/coridoc/asciidoc/serializer/serializers/paragraph.rb +65 -0
- data/lib/coridoc/asciidoc/serializer/serializers/reviewer_note.rb +28 -0
- data/lib/coridoc/asciidoc/serializer/serializers/revision.rb +26 -0
- data/lib/coridoc/asciidoc/serializer/serializers/section.rb +37 -0
- data/lib/coridoc/asciidoc/serializer/serializers/table.rb +30 -0
- data/lib/coridoc/asciidoc/serializer/serializers/table_cell.rb +75 -0
- data/lib/coridoc/asciidoc/serializer/serializers/table_row.rb +24 -0
- data/lib/coridoc/asciidoc/serializer/serializers/tag.rb +19 -0
- data/lib/coridoc/asciidoc/serializer/serializers/term.rb +20 -0
- data/lib/coridoc/asciidoc/serializer/serializers/text_element.rb +25 -0
- data/lib/coridoc/asciidoc/serializer/serializers/title.rb +55 -0
- data/lib/coridoc/asciidoc/serializer/serializers/video.rb +33 -0
- data/lib/coridoc/asciidoc/serializer/spacing_strategy.rb +70 -0
- data/lib/coridoc/asciidoc/serializer.rb +75 -0
- data/lib/coridoc/asciidoc/transform/attribute_list_to_metadata.rb +33 -0
- data/lib/coridoc/asciidoc/transform/callout_merger.rb +117 -0
- data/lib/coridoc/asciidoc/transform/element_transformers/admonition_styles.rb +70 -0
- data/lib/coridoc/asciidoc/transform/element_transformers/block_transformer.rb +316 -0
- data/lib/coridoc/asciidoc/transform/element_transformers/document_transformer.rb +117 -0
- data/lib/coridoc/asciidoc/transform/element_transformers/include_transformer.rb +57 -0
- data/lib/coridoc/asciidoc/transform/element_transformers/inline_transformer.rb +106 -0
- data/lib/coridoc/asciidoc/transform/element_transformers/list_transformer.rb +163 -0
- data/lib/coridoc/asciidoc/transform/element_transformers/other_transformer.rb +77 -0
- data/lib/coridoc/asciidoc/transform/element_transformers/table_transformer.rb +52 -0
- data/lib/coridoc/asciidoc/transform/element_transformers.rb +18 -0
- data/lib/coridoc/asciidoc/transform/from_core_model/list_building.rb +86 -0
- data/lib/coridoc/asciidoc/transform/from_core_model.rb +664 -0
- data/lib/coridoc/asciidoc/transform/from_core_model_registrations.rb +135 -0
- data/lib/coridoc/asciidoc/transform/frontmatter_attribute_map.rb +113 -0
- data/lib/coridoc/asciidoc/transform/inline_transform_visitor.rb +85 -0
- data/lib/coridoc/asciidoc/transform/text_extract_visitor.rb +161 -0
- data/lib/coridoc/asciidoc/transform/to_core_model.rb +173 -0
- data/lib/coridoc/asciidoc/transform/to_core_model_registrations.rb +276 -0
- data/lib/coridoc/asciidoc/transform/transformer_registry.rb +80 -0
- data/lib/coridoc/asciidoc/transform.rb +21 -0
- data/lib/coridoc/asciidoc/transformer/attribute_list_normalizer.rb +69 -0
- data/lib/coridoc/asciidoc/transformer/block_type_classifier.rb +65 -0
- data/lib/coridoc/asciidoc/transformer/source_line_extractor.rb +66 -0
- data/lib/coridoc/asciidoc/transformer/table_cell_builder.rb +172 -0
- data/lib/coridoc/asciidoc/transformer/table_layout.rb +135 -0
- data/lib/coridoc/asciidoc/transformer.rb +257 -0
- data/lib/coridoc/asciidoc/typographic_quotes.rb +37 -0
- data/lib/coridoc/asciidoc/version.rb +7 -0
- data/lib/coridoc/asciidoc.rb +177 -0
- data/lib/coridoc/util/asciidoc.rb +127 -0
- data/lib/coridoc/util.rb +8 -0
- metadata +387 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Coridoc
|
|
4
|
+
module AsciiDoc
|
|
5
|
+
module Parser
|
|
6
|
+
module Block
|
|
7
|
+
# AsciiDoc Block Delimiter Patterns:
|
|
8
|
+
# - "4+" means 4 or more identical characters
|
|
9
|
+
# - "2+" means 2 or more identical characters
|
|
10
|
+
#
|
|
11
|
+
# Block types by delimiter character:
|
|
12
|
+
# - "=" (4+): Example block (====, =====, etc.)
|
|
13
|
+
# - "-" (4+): Source/listing block (----, -----, etc.)
|
|
14
|
+
# - "-" (2): Open block (--)
|
|
15
|
+
# - "_" (4+): Quote block (____, _____, etc.)
|
|
16
|
+
# - "*" (4+): Sidebar block (****, *****, etc.)
|
|
17
|
+
# - "+" (4+): Pass block (++++, +++++, etc.)
|
|
18
|
+
# - "." (4+): Literal block (...., ....., etc.)
|
|
19
|
+
#
|
|
20
|
+
# Table delimiters:
|
|
21
|
+
# - "|===" defines table boundaries
|
|
22
|
+
# - "|" separates cells within the table
|
|
23
|
+
|
|
24
|
+
def block(n_deep = 3)
|
|
25
|
+
(markdown_code_block(n_deep) |
|
|
26
|
+
example_block(n_deep) |
|
|
27
|
+
sidebar_block(n_deep) |
|
|
28
|
+
source_block(n_deep) |
|
|
29
|
+
quote_block(n_deep) |
|
|
30
|
+
pass_block(n_deep) |
|
|
31
|
+
literal_block(n_deep) |
|
|
32
|
+
open_block(n_deep)).as(:block)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def example_block(n_deep)
|
|
36
|
+
block_style(n_deep, '=', 4)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def pass_block(n_deep)
|
|
40
|
+
block_style(n_deep, '+', 4, verbatim: true)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def quote_block(n_deep)
|
|
44
|
+
block_style(n_deep, '_', 4)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def sidebar_block(n_deep)
|
|
48
|
+
block_style(n_deep, '*', 4)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def source_block(n_deep)
|
|
52
|
+
block_style(n_deep, '-', 4, verbatim: true)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def literal_block(n_deep)
|
|
56
|
+
block_style(n_deep, '.', 4, verbatim: true)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Open block: exactly 2 dashes (cannot nest within itself)
|
|
60
|
+
def open_block(n_deep)
|
|
61
|
+
block_style_exact(n_deep, '-', 2)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Markdown-style fenced code block: triple-backtick (or longer)
|
|
65
|
+
# fence with an optional language tag on the opening line. Behaves
|
|
66
|
+
# as a verbatim source block — same model as `[source,lang]\n----`.
|
|
67
|
+
# Pragmatic permissiveness for content that originates from (or is
|
|
68
|
+
# edited alongside) Markdown; not standard AsciiDoc but widely
|
|
69
|
+
# accepted (GitHub's renderer treats ``` as a listing delimiter).
|
|
70
|
+
def markdown_code_block(n_deep = 3)
|
|
71
|
+
capture_key = :"md_fence_#{n_deep}"
|
|
72
|
+
opening_fence = str('`').repeat(3).capture(capture_key)
|
|
73
|
+
closing_fence = dynamic do |_s, c|
|
|
74
|
+
str(c.captures[capture_key].to_s.strip)
|
|
75
|
+
end
|
|
76
|
+
language = (space? >> match('[A-Za-z0-9_+.-]').repeat(1).as(:language)).maybe
|
|
77
|
+
|
|
78
|
+
block_content_with_closing = dynamic do |_s, c|
|
|
79
|
+
c.captures[capture_key].to_s.strip
|
|
80
|
+
closing_pattern = closing_fence >> space? >> newline
|
|
81
|
+
|
|
82
|
+
content = text_line(false, unguarded: true, verbatim: true) |
|
|
83
|
+
empty_line.as(:line_break)
|
|
84
|
+
|
|
85
|
+
(closing_pattern.absent? >> content).repeat(1)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
block_header >>
|
|
89
|
+
line_start? >>
|
|
90
|
+
opening_fence.as(:delimiter) >> language >> newline >>
|
|
91
|
+
block_content_with_closing.as(:lines) >>
|
|
92
|
+
line_start? >>
|
|
93
|
+
closing_fence >> space? >> newline
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def block_title
|
|
97
|
+
(line_start? >> block_delimiter.absent?) >>
|
|
98
|
+
str('.') >> space.absent? >> text.as(:title) >> newline
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def block_type(type)
|
|
102
|
+
(line_start? >> str('[') >> str('[').absent? >>
|
|
103
|
+
str(type).as(:type) >>
|
|
104
|
+
str(']')) >> newline # |
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def block_content(n_deep = 3)
|
|
108
|
+
block_container_content(n_deep).repeat(1)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Single source of truth for "what can appear inside a non-verbatim
|
|
112
|
+
# block container". Used by block_content, block_style (non-verbatim
|
|
113
|
+
# branch), and block_style_exact (non-verbatim branch).
|
|
114
|
+
#
|
|
115
|
+
# `table` is listed before `text_line` so a leading `|===` is parsed
|
|
116
|
+
# as a table rather than mis-bracketed as text. The recursive `block`
|
|
117
|
+
# alternative handles every other delimited block.
|
|
118
|
+
def block_container_content(n_deep)
|
|
119
|
+
c = table.as(:table)
|
|
120
|
+
c |= block_image
|
|
121
|
+
c |= block(n_deep - 1) if n_deep.positive?
|
|
122
|
+
c |= list
|
|
123
|
+
c |= text_line(false, unguarded: true)
|
|
124
|
+
c |= empty_line.as(:line_break)
|
|
125
|
+
c
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Block delimiter: 4+ identical characters, or 2 dashes for open
|
|
129
|
+
# blocks, or 3+ backticks for Markdown-style code fences. Used by
|
|
130
|
+
# paragraph.rb to reject lines that look like block delimiters.
|
|
131
|
+
# NOTE: repeat(4,) means 4 or more (not exactly 4)
|
|
132
|
+
def block_delimiter
|
|
133
|
+
line_start? >>
|
|
134
|
+
((str('*') |
|
|
135
|
+
str('=') |
|
|
136
|
+
str('_') |
|
|
137
|
+
str('+') |
|
|
138
|
+
str('.') |
|
|
139
|
+
str('-')).repeat(4) | # 4+ characters for most blocks
|
|
140
|
+
str('-').repeat(2, 2) | # Exactly 2 for open block
|
|
141
|
+
str('`').repeat(3)) >> # 3+ for Markdown code fences
|
|
142
|
+
newline
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Block style parser with variable delimiter length
|
|
146
|
+
# @param n_deep [Integer] Nesting depth for nested blocks
|
|
147
|
+
# @param delimiter [String] The delimiter character ("=", "-", "_", "*", "+", ".")
|
|
148
|
+
# @param repeater [Integer] Minimum number of delimiter characters (default: 4)
|
|
149
|
+
# @param verbatim [Boolean] Treat body as raw text (no substitutions, no nested blocks)
|
|
150
|
+
def block_style(n_deep = 3, delimiter = '*', repeater = 4, verbatim: false)
|
|
151
|
+
capture_key = :"delimit_#{delimiter}_#{n_deep}"
|
|
152
|
+
current_delimiter = str(delimiter).repeat(repeater).capture(capture_key)
|
|
153
|
+
closing_delimiter = dynamic do |_s, c|
|
|
154
|
+
str(c.captures[capture_key].to_s.strip)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
block_content_with_closing = dynamic do |_s, c|
|
|
158
|
+
delim_str = c.captures[capture_key].to_s.strip
|
|
159
|
+
closing_pattern = str(delim_str) >> newline
|
|
160
|
+
|
|
161
|
+
# Verbatim blocks (source/listing/literal/pass) treat their body
|
|
162
|
+
# as literal text per the AsciiDoc spec — no substitutions, no
|
|
163
|
+
# nested blocks. Allowing nested block parsing here would consume
|
|
164
|
+
# shorter inner delimiters (e.g. `----` inside `------`) and
|
|
165
|
+
# strip the original structure when serializing back.
|
|
166
|
+
content = if verbatim
|
|
167
|
+
text_line(false, unguarded: true, verbatim: true) |
|
|
168
|
+
empty_line.as(:line_break)
|
|
169
|
+
else
|
|
170
|
+
block_container_content(n_deep)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
(closing_pattern.absent? >> content).repeat(1)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
block_header >>
|
|
177
|
+
line_start? >>
|
|
178
|
+
current_delimiter.as(:delimiter) >> newline >>
|
|
179
|
+
block_content_with_closing.as(:lines) >>
|
|
180
|
+
line_start? >>
|
|
181
|
+
closing_delimiter >> newline
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
# Block style parser with EXACT delimiter length (for open blocks).
|
|
185
|
+
# Open blocks use exactly 2 dashes. A `[source]`/`[listing]`/`[literal]`
|
|
186
|
+
# positional attribute casts the body to verbatim — block macros like
|
|
187
|
+
# `image::` must survive byte-for-byte, same as delimited source blocks.
|
|
188
|
+
def block_style_exact(n_deep = 3, delimiter = '-', exact_chars = 2)
|
|
189
|
+
capture_key = :"delimit_#{delimiter}_exact_#{exact_chars}_#{n_deep}"
|
|
190
|
+
attr_capture_key = :"#{capture_key}_attrs"
|
|
191
|
+
current_delimiter = str(delimiter).repeat(exact_chars, exact_chars).capture(capture_key)
|
|
192
|
+
closing_delimiter = dynamic do |_s, c|
|
|
193
|
+
str(c.captures[capture_key].to_s.strip)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Closure so the call bypasses Parsanol's method_missing inside the
|
|
197
|
+
# dynamic block. capture() stashes the parsed AST (a nested Hash for
|
|
198
|
+
# a `[source,ruby]` header). Inspect the structure directly so we
|
|
199
|
+
# don't depend on Ruby's Hash#to_s format (it changed in 3.4).
|
|
200
|
+
verbatim_cast = lambda do |raw|
|
|
201
|
+
values = []
|
|
202
|
+
queue = [raw]
|
|
203
|
+
while (node = queue.shift)
|
|
204
|
+
case node
|
|
205
|
+
when Hash then queue.concat(node.values)
|
|
206
|
+
when Array then queue.concat(node)
|
|
207
|
+
else values << node
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
castable = %w[source listing literal]
|
|
211
|
+
values.any? { |v| castable.include?(v.to_s) }
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
block_content_with_closing = dynamic do |_s, c|
|
|
215
|
+
delim_str = c.captures[capture_key].to_s.strip
|
|
216
|
+
raw_header = c.captures[attr_capture_key]
|
|
217
|
+
closing_pattern = str(delim_str) >> newline
|
|
218
|
+
|
|
219
|
+
content = if verbatim_cast.call(raw_header)
|
|
220
|
+
text_line(false, unguarded: true, verbatim: true) |
|
|
221
|
+
empty_line.as(:line_break)
|
|
222
|
+
else
|
|
223
|
+
block_container_content(n_deep)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
(closing_pattern.absent? >> content).repeat(1)
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
block_header.capture(attr_capture_key) >>
|
|
230
|
+
line_start? >>
|
|
231
|
+
current_delimiter.as(:delimiter) >> newline >>
|
|
232
|
+
block_content_with_closing.as(:lines) >>
|
|
233
|
+
line_start? >>
|
|
234
|
+
closing_delimiter >> newline
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Coridoc
|
|
4
|
+
module AsciiDoc
|
|
5
|
+
module Parser
|
|
6
|
+
# Single Responsibility: Assemble block AST from metadata hints
|
|
7
|
+
# Takes metadata analysis and input text, returns proper AST structure
|
|
8
|
+
class BlockAssembler
|
|
9
|
+
# Main entry point: assemble block AST from input and metadata.
|
|
10
|
+
#
|
|
11
|
+
# The result hash always includes :delimiter and :lines. :title and
|
|
12
|
+
# :attribute_list are included only when present in the metadata.
|
|
13
|
+
# The previous 4-arm `case pattern` switch collapsed into this single
|
|
14
|
+
# method once it became clear the only difference between arms was
|
|
15
|
+
# which optional keys appeared in the result hash.
|
|
16
|
+
#
|
|
17
|
+
# @param input [String] The input text to parse
|
|
18
|
+
# @param metadata [Hash] Analysis from MetadataDetector
|
|
19
|
+
# @return [Hash, nil] AST hash, or nil if metadata is nil
|
|
20
|
+
def self.assemble(input, metadata)
|
|
21
|
+
return nil unless metadata
|
|
22
|
+
|
|
23
|
+
lines = input.lines
|
|
24
|
+
delimiter_line = metadata[:delimiter_line]
|
|
25
|
+
delimiter = metadata[:delimiter][:delimiter]
|
|
26
|
+
|
|
27
|
+
result = {
|
|
28
|
+
delimiter: delimiter,
|
|
29
|
+
lines: extract_block_lines(lines, delimiter_line, delimiter)
|
|
30
|
+
}
|
|
31
|
+
result[:title] = metadata[:title][:text] if metadata[:title]
|
|
32
|
+
result[:attribute_list] = parse_attribute_list(metadata[:attributes]) if metadata[:attributes]
|
|
33
|
+
result
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Helper: Extract content between delimiters
|
|
37
|
+
# @param lines [Array<String>] All lines of input
|
|
38
|
+
# @param delimiter_line [Integer] Line number of opening delimiter
|
|
39
|
+
# @param delimiter [String] The delimiter string (e.g., "****")
|
|
40
|
+
# @return [Array<Hash>] Array of {:text => "...", :line_break => "\n"}
|
|
41
|
+
def self.extract_block_lines(lines, delimiter_line, delimiter)
|
|
42
|
+
block_lines = []
|
|
43
|
+
|
|
44
|
+
# Start from line after opening delimiter
|
|
45
|
+
i = delimiter_line + 1
|
|
46
|
+
|
|
47
|
+
# Collect lines until closing delimiter
|
|
48
|
+
while i < lines.length
|
|
49
|
+
line = lines[i]
|
|
50
|
+
|
|
51
|
+
# Check if this is the closing delimiter
|
|
52
|
+
break if line.strip == delimiter
|
|
53
|
+
|
|
54
|
+
stripped = line.strip
|
|
55
|
+
if nested_delimiter?(stripped) && stripped != delimiter
|
|
56
|
+
nested_delimiter = stripped
|
|
57
|
+
nested_lines = extract_block_lines(lines, i, nested_delimiter)
|
|
58
|
+
|
|
59
|
+
block_lines << { block: { delimiter: nested_delimiter, lines: nested_lines } }
|
|
60
|
+
|
|
61
|
+
i += nested_lines.length + 1
|
|
62
|
+
elsif line.strip.empty?
|
|
63
|
+
# Handle empty lines vs content lines
|
|
64
|
+
block_lines << { line_break: "\n" }
|
|
65
|
+
else
|
|
66
|
+
# Remove trailing newline for processing
|
|
67
|
+
text = line.chomp
|
|
68
|
+
block_lines << { text: text, line_break: "\n" }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
i += 1
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
block_lines
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def self.nested_delimiter?(str)
|
|
78
|
+
return false if str.length < 2
|
|
79
|
+
|
|
80
|
+
char = str[0]
|
|
81
|
+
return false unless ['-', '*', '=', '_', '+'].include?(char)
|
|
82
|
+
return false unless str.chars.all? { |c| c == char }
|
|
83
|
+
|
|
84
|
+
(char == '-' && str.length == 2) || str.length >= 4
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Parse attribute list to match expected AST structure
|
|
88
|
+
# @param attr_meta [Hash] Attribute metadata from detector
|
|
89
|
+
# @return [Hash] Properly formatted attribute_list hash
|
|
90
|
+
def self.parse_attribute_list(attr_meta)
|
|
91
|
+
return nil unless attr_meta
|
|
92
|
+
|
|
93
|
+
# Get the raw content (without brackets)
|
|
94
|
+
content = attr_meta[:content]
|
|
95
|
+
attr_content = content[1...-1] # Remove [ and ]
|
|
96
|
+
|
|
97
|
+
# Get attributes array from metadata
|
|
98
|
+
attributes = attr_meta[:attributes]
|
|
99
|
+
|
|
100
|
+
# Build attribute_array in expected format
|
|
101
|
+
attribute_array = attributes.map do |attr|
|
|
102
|
+
# Check if it's a named attribute (key=value)
|
|
103
|
+
if attr.include?('=')
|
|
104
|
+
key, value = attr.split('=', 2)
|
|
105
|
+
{ named: { named_key: key.strip, named_value: value.strip } }
|
|
106
|
+
else
|
|
107
|
+
# Positional attribute
|
|
108
|
+
{ positional: attr.strip }
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
{
|
|
113
|
+
attr_content: attr_content,
|
|
114
|
+
attribute_array: attribute_array
|
|
115
|
+
}
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Coridoc
|
|
4
|
+
module AsciiDoc
|
|
5
|
+
module Parser
|
|
6
|
+
# Single Responsibility: parse the optional header that precedes a
|
|
7
|
+
# structural element (block or section).
|
|
8
|
+
#
|
|
9
|
+
# Encapsulates the canonical AsciiDoc header grammar in one place
|
|
10
|
+
# (DRY, MECE, single source of truth). Two flavours live here because
|
|
11
|
+
# blocks and sections have different header grammars:
|
|
12
|
+
#
|
|
13
|
+
# block_header = block_title? >> element_id? >> attribute_blocks?
|
|
14
|
+
# section_header = element_id? >> attribute_blocks?
|
|
15
|
+
#
|
|
16
|
+
# Asciidoctor does NOT permit `.Title` to apply to a section — sections
|
|
17
|
+
# accept `[role]` attribute lists and `[[id]]` anchors but not block
|
|
18
|
+
# titles. The section's heading IS its title. Mixing the two shapes
|
|
19
|
+
# into one rule caused `section_block` to admit `.Foo` lines that
|
|
20
|
+
# collided with `section_title`'s `:title` capture, triggering
|
|
21
|
+
# Parsanol's "Duplicate subtrees while merging result … (keys:
|
|
22
|
+
# [:title])" warning and silently dropping the block title.
|
|
23
|
+
#
|
|
24
|
+
# Before this module existed, every block-like rule inlined its own
|
|
25
|
+
# header rule with subtly different slot orderings — and several
|
|
26
|
+
# captured the same Parsanol key more than once in a single sequence,
|
|
27
|
+
# which triggered Parsanol's "Duplicate subtrees" warning and silently
|
|
28
|
+
# discarded one of the captured values.
|
|
29
|
+
#
|
|
30
|
+
# `attribute_blocks` accepts one or more consecutive `[...]` attribute
|
|
31
|
+
# lists, captured as a Parsanol sequence under the :attribute_list key.
|
|
32
|
+
# Real-world AsciiDoc often stacks attribute lists before a block:
|
|
33
|
+
#
|
|
34
|
+
# [role=quote]
|
|
35
|
+
# [source, ruby]
|
|
36
|
+
# ----
|
|
37
|
+
# code
|
|
38
|
+
# ----
|
|
39
|
+
#
|
|
40
|
+
# Capturing the sequence (rather than one slot per `[...]`) preserves
|
|
41
|
+
# every attribute and lets the transformer merge them into a single
|
|
42
|
+
# Coridoc::AsciiDoc::Model::AttributeList downstream.
|
|
43
|
+
module BlockHeader
|
|
44
|
+
# Canonical block header rule. Includes the block title — every
|
|
45
|
+
# real block (delimited block, table, paragraph, image) accepts
|
|
46
|
+
# an optional `.Title` line before its body. Single canonical
|
|
47
|
+
# order; each of title, id, and attribute_blocks is optional and
|
|
48
|
+
# matched at most once.
|
|
49
|
+
# @return [Parsanol::Atoms::Base]
|
|
50
|
+
def block_header
|
|
51
|
+
block_title.maybe >>
|
|
52
|
+
element_id.maybe >>
|
|
53
|
+
attribute_blocks.maybe
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Section header rule. Asciidoctor does not permit `.Title` on
|
|
57
|
+
# sections — the section heading itself is the title. Sections
|
|
58
|
+
# still accept the same element_id and attribute_blocks slots
|
|
59
|
+
# that blocks do (`[[anchor]]`, `[appendix]`, `[role=x]`, etc.).
|
|
60
|
+
# @return [Parsanol::Atoms::Base]
|
|
61
|
+
def section_header
|
|
62
|
+
element_id.maybe >>
|
|
63
|
+
attribute_blocks.maybe
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# One or more consecutive attribute_list + newline sequences, captured
|
|
67
|
+
# as a Parsanol sequence under :attribute_list. When multiple `[...]`
|
|
68
|
+
# blocks precede a delimiter, all of them reach the transformer; when
|
|
69
|
+
# only one appears, the sequence has a single element and the existing
|
|
70
|
+
# transformer rule handles it the same way as before.
|
|
71
|
+
# @return [Parsanol::Atoms::Base]
|
|
72
|
+
def attribute_blocks
|
|
73
|
+
(attribute_list >> newline).repeat(1).as(:attribute_list)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'digest'
|
|
4
|
+
|
|
5
|
+
module Coridoc
|
|
6
|
+
module AsciiDoc
|
|
7
|
+
module Parser
|
|
8
|
+
# Parser cache for optimizing repeated parses of the same content
|
|
9
|
+
#
|
|
10
|
+
# This is an opt-in feature that caches parse results based on content hashing.
|
|
11
|
+
# Useful for IDE integrations, watch mode, or any scenario where the same
|
|
12
|
+
# content is parsed multiple times.
|
|
13
|
+
#
|
|
14
|
+
# @example Basic usage
|
|
15
|
+
# cache = Coridoc::AsciiDoc::Parser::Cache.new
|
|
16
|
+
# ast = cache.fetch_or_parse(content) { Parser::Base.parse(content) }
|
|
17
|
+
#
|
|
18
|
+
# @example With size limit
|
|
19
|
+
# cache = Coridoc::AsciiDoc::Parser::Cache.new(max_size: 100)
|
|
20
|
+
#
|
|
21
|
+
# @example Global cache (use with caution)
|
|
22
|
+
# Coridoc::AsciiDoc::Parser::Cache.global do |c|
|
|
23
|
+
# c.fetch_or_parse(content) { Parser::Base.parse(content) }
|
|
24
|
+
# end
|
|
25
|
+
class Cache
|
|
26
|
+
# Default maximum cache size
|
|
27
|
+
DEFAULT_MAX_SIZE = 50
|
|
28
|
+
|
|
29
|
+
# Get the global cache instance
|
|
30
|
+
# @return [Cache, nil] The global cache instance
|
|
31
|
+
def self.global
|
|
32
|
+
@global ||= nil
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Set the global cache instance
|
|
36
|
+
# @param cache [Cache, nil] The cache instance
|
|
37
|
+
class << self
|
|
38
|
+
attr_writer :global
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Execute a block with a global cache
|
|
42
|
+
# @param max_size [Integer] Maximum cache entries
|
|
43
|
+
# @yield [Cache] The cache instance
|
|
44
|
+
# @return [Object] The block result
|
|
45
|
+
def self.with_global(max_size: DEFAULT_MAX_SIZE)
|
|
46
|
+
previous = @global
|
|
47
|
+
@global = new(max_size: max_size)
|
|
48
|
+
begin
|
|
49
|
+
yield @global
|
|
50
|
+
ensure
|
|
51
|
+
@global = previous
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Clear the global cache
|
|
56
|
+
def self.clear_global!
|
|
57
|
+
@global&.clear
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Initialize a new cache
|
|
61
|
+
# @param max_size [Integer] Maximum number of entries to cache
|
|
62
|
+
def initialize(max_size: DEFAULT_MAX_SIZE)
|
|
63
|
+
@max_size = max_size
|
|
64
|
+
@cache = {}
|
|
65
|
+
@access_order = []
|
|
66
|
+
@mutex = Mutex.new
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Fetch a cached result or parse and cache
|
|
70
|
+
#
|
|
71
|
+
# @param content [String] The content to parse
|
|
72
|
+
# @yield Block to execute if cache miss
|
|
73
|
+
# @return [Object] The parsed AST
|
|
74
|
+
def fetch_or_parse(content)
|
|
75
|
+
key = content_hash(content)
|
|
76
|
+
|
|
77
|
+
mutex.synchronize do
|
|
78
|
+
if cache.key?(key)
|
|
79
|
+
# Move to end of access order (most recently used)
|
|
80
|
+
access_order.delete(key)
|
|
81
|
+
access_order.push(key)
|
|
82
|
+
return cache[key]
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Parse outside the lock for concurrency
|
|
87
|
+
result = yield if block_given?
|
|
88
|
+
|
|
89
|
+
mutex.synchronize do
|
|
90
|
+
# Evict oldest if at capacity
|
|
91
|
+
evict_oldest if cache.size >= max_size
|
|
92
|
+
|
|
93
|
+
cache[key] = result
|
|
94
|
+
access_order.push(key)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
result
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Check if content is cached
|
|
101
|
+
# @param content [String] The content to check
|
|
102
|
+
# @return [Boolean] True if cached
|
|
103
|
+
def cached?(content)
|
|
104
|
+
key = content_hash(content)
|
|
105
|
+
mutex.synchronize { cache.key?(key) }
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Get cache statistics
|
|
109
|
+
# @return [Hash] Statistics including size, max_size, hits, misses
|
|
110
|
+
def stats
|
|
111
|
+
mutex.synchronize do
|
|
112
|
+
{
|
|
113
|
+
size: cache.size,
|
|
114
|
+
max_size: max_size,
|
|
115
|
+
keys: access_order.dup
|
|
116
|
+
}
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Clear the cache
|
|
121
|
+
def clear
|
|
122
|
+
mutex.synchronize do
|
|
123
|
+
cache.clear
|
|
124
|
+
access_order.clear
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Get the current cache size
|
|
129
|
+
# @return [Integer] Number of cached entries
|
|
130
|
+
def size
|
|
131
|
+
mutex.synchronize { cache.size }
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
private
|
|
135
|
+
|
|
136
|
+
attr_reader :cache, :max_size, :access_order, :mutex
|
|
137
|
+
|
|
138
|
+
# Generate a hash key for content
|
|
139
|
+
# @param content [String] The content
|
|
140
|
+
# @return [String] SHA256 hash of content
|
|
141
|
+
def content_hash(content)
|
|
142
|
+
Digest::SHA256.hexdigest(content)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Evict the oldest (least recently used) entry
|
|
146
|
+
def evict_oldest
|
|
147
|
+
return if access_order.empty?
|
|
148
|
+
|
|
149
|
+
oldest_key = access_order.shift
|
|
150
|
+
cache.delete(oldest_key)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Coridoc
|
|
4
|
+
module AsciiDoc
|
|
5
|
+
module Parser
|
|
6
|
+
module Citation
|
|
7
|
+
# In `<<target,text>>`, the target is everything up to the first comma
|
|
8
|
+
# or closing `>`. The text is everything else up to `>` — it can
|
|
9
|
+
# contain commas, quotes, and any other punctuation.
|
|
10
|
+
def cross_reference
|
|
11
|
+
(str('<<') >>
|
|
12
|
+
match('[^,>]').repeat(1).as(:href) >>
|
|
13
|
+
(str(',') >> match('[^>]').repeat(0).as(:text)).maybe >>
|
|
14
|
+
str('>>')
|
|
15
|
+
).as(:cross_reference)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# AsciiDoc escape: `\<<` produces the literal text `<<` without
|
|
19
|
+
# firing the cross-reference rule. Without this, documentation that
|
|
20
|
+
# shows AsciiDoc xref syntax as a literal example gets rewritten
|
|
21
|
+
# into a broken link to a non-existent anchor.
|
|
22
|
+
def escaped_xref
|
|
23
|
+
str('\\') >> str('<<').as(:text)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# General AsciiDoc escape: \X (X punctuation, minus < for
|
|
27
|
+
# escaped_xref and \ itself) yields the literal character X
|
|
28
|
+
# without firing any inline rule (#281).
|
|
29
|
+
def escape_char
|
|
30
|
+
# Explicit class (all ASCII punctuation except < for
|
|
31
|
+
# escaped_xref and \ itself): the native engine does not
|
|
32
|
+
# compile && class intersections.
|
|
33
|
+
str('\\') >> match("[!\"#$%&'()*+,\\-./:;=?@\\[\\]^_`{|}~]").as(:text)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|