Module: Ast::Crispr::Markdown::Markly
- Defined in:
- lib/ast/crispr/markdown/markly.rb,
lib/ast/crispr/markdown/markly/version.rb,
sig/ast/crispr/markdown/markly.rbs
Defined Under Namespace
Modules: Selectors, Version Classes: Adapter, Error, HtmlDetailsOwner
Constant Summary collapse
- Targets =
Selectors- VERSION =
Current gem version exposed at the traditional constant location.
Version::VERSION
Class Method Summary collapse
- .adapter ⇒ Object
- .document_context(content:, source_label: 'source', metadata: {}, **options) ⇒ Object
-
.html_details_owners(analysis) ⇒ Object
Markly exposes raw HTML as separate AST blocks rather than a nested HTML tree, so group the parser-owned blocks into selectable details owners.
- .html_summary_text(source) ⇒ Object
Class Method Details
.adapter ⇒ Object
440 441 442 |
# File 'lib/ast/crispr/markdown/markly.rb', line 440 def adapter @adapter ||= Adapter.new end |
.document_context(content:, source_label: 'source', metadata: {}, **options) ⇒ Object
444 445 446 447 448 449 450 451 452 |
# File 'lib/ast/crispr/markdown/markly.rb', line 444 def document_context(content:, source_label: 'source', metadata: {}, **) Ast::Crispr::DocumentContext.new( content: content, source_label: source_label, adapter: adapter, metadata: , ** ) end |
.html_details_owners(analysis) ⇒ Object
Markly exposes raw HTML as separate AST blocks rather than a nested HTML tree, so group the parser-owned blocks into selectable details owners.
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/ast/crispr/markdown/markly.rb', line 382 def self.html_details_owners(analysis) statements = Array(analysis.statements) html_blocks = statements.filter_map do |statement| next unless statement.respond_to?(:merge_type) && statement.merge_type == :html_block position = statement.source_position next unless position { start_line: position[:start_line], end_line: position[:end_line] } end html_blocks.filter_map do |opening| opening_source = analysis.source_range(opening[:start_line], opening[:end_line]) next unless opening_source.lines.any? do |line| stripped = line.lstrip stripped.start_with?('<details>') || stripped.start_with?('<details ') end closing = html_blocks.drop_while { |candidate| candidate != opening }.drop(1).find do |candidate| source = analysis.source_range(candidate[:start_line], candidate[:end_line]) source.lines.any? { |line| line.lstrip.start_with?('</details>') } end next unless closing source = analysis.source_range(opening[:start_line], closing[:end_line]) summary_text = html_summary_text(source) next if summary_text.empty? HtmlDetailsOwner.new( location: ::Markdown::Merge::FileAnalysis::Location.new( start_line: opening[:start_line], end_line: closing[:end_line] ), summary_text: summary_text, source: source ) end end |
.html_summary_text(source) ⇒ Object
424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/ast/crispr/markdown/markly.rb', line 424 def self.html_summary_text(source) open_tag_start = source.index('<summary') return '' unless open_tag_start open_tag_end = source.index('>', open_tag_start) return '' unless open_tag_end close_tag_start = source.index('</summary>', open_tag_end) return '' unless close_tag_start source[(open_tag_end + 1)...close_tag_start].to_s.strip end |