Class: JekyllHighlightCards::FreezeArchives::ArchiveInserter

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-highlight-cards/freeze_archives/archive_inserter.rb

Overview

Surgically insert an archive token into a located tag span.

Single-line tags splice after the last non-whitespace of the markup. Multiline tags add a new line before the closer, indented like the last content line (see creative-source-scan-rewrite).

Instance Method Summary collapse

Instance Method Details

#insert(content, span, archive_url) ⇒ String

Insert archive URL into content at span

Parameters:

  • content (String)

    full file contents

  • span (Hash)

    locator span with :tag, :markup, :range

  • archive_url (String)

    Wayback (or other) archive URL to freeze

Returns:

  • (String)

    updated file contents



17
18
19
20
21
22
# File 'lib/jekyll-highlight-cards/freeze_archives/archive_inserter.rb', line 17

def insert(content, span, archive_url)
  range = span.fetch(:range)
  tag_text = content[range]
  updated = rewrite_tag(tag_text, span.fetch(:tag), archive_url)
  content[0...range.begin] + updated + content[range.end..]
end