Class: Sourcerer::SourceSkim::Skimmer Private
- Inherits:
-
Object
- Object
- Sourcerer::SourceSkim::Skimmer
- Defined in:
- lib/sourcerer/source_skim/skimmer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Traverses a parsed Asciidoctor document and produces a JSON-ready skim hash.
A new instance should be created per-document call; instance variables
accumulate state during a single process pass.
This class is an internal implementation detail. External callers should
use the Sourcerer::SourceSkim module-level methods rather than
instantiating Skimmer directly.
Constant Summary collapse
- INCLUDE_DIRECTIVE_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Scan listing/literal block source for include directives that remain as raw text (i.e., were not resolved by the parser).
/include::[^\[]+\[[^\]]*\]/- INCLUDE_LINE_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Matches a real (non-code-block) include directive at the start of a line, capturing the target path and its attribute list.
/\A\s*include::([^\[]+)\[([^\]]*)\]\s*\z/- FENCE_DELIMITER_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Toggled by classic listing (----) / literal (....) block delimiters, so #detect_general_includes can skip include directives already captured (as literal example text) by the code_blocks/literal_blocks categories.
/\A(?:-{4,}|\.{4,})\s*\z/- RAW_TITLE_LINE_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
A document with a real title line can still end up with no
titledocument attribute if a preceding, unresolved include directive disrupts Asciidoctor's header parsing (a known Asciidoctor quirk, not something this document did wrong). When that happens, Document#doctitle silently falls back to the first section's title. Detect that specific failure mode and recover the real title from the raw source instead. /\A=\s+(\S.*)\z/
Instance Method Summary collapse
Instance Method Details
#process(document, config: Config.new) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sourcerer/source_skim/skimmer.rb', line 36 def process document, config: Config.new @config = config @main_file = document.attr('docfile') @definition_lists = [] @code_blocks = [] @literal_blocks = [] @examples = [] @sidebars = [] @tables = [] @admonitions = [] @quotes = [] @images = [] process_blocks(document.blocks, 0, nil) tree = build_sections_tree(document.sections) doc_end = line_count_for(@main_file) assign_line_ends(tree, doc_end) result = { title: doctitle_for(document), lines: doc_end } if @config.include?(:attributes_custom) result[:attributes_custom] = Sourcerer::AsciiDoc::AttributesFilter.user_attributes(document) end if @config.include?(:attributes_builtin) result[:attributes_builtin] = Sourcerer::AsciiDoc::AttributesFilter.builtin_attributes(document) end result[:sections_tree] = tree if @config.tree? result[:sections_flat] = flatten_sections(tree) if @config.flat? result[:definition_lists] = @definition_lists if @config.include?(:definition_lists) result[:code_blocks] = @code_blocks if @config.include?(:code_blocks) result[:literal_blocks] = @literal_blocks if @config.include?(:literal_blocks) result[:examples] = @examples if @config.include?(:examples) result[:sidebars] = @sidebars if @config.include?(:sidebars) result[:tables] = @tables if @config.include?(:tables) result[:admonitions] = @admonitions if @config.include?(:admonitions) result[:quotes] = @quotes if @config.include?(:quotes) result[:images] = @images if @config.include?(:images) result[:includes] = detect_general_includes(document) if @config.include?(:includes) result end |