summaryrefslogtreecommitdiff
path: root/spec/link_spec.rb
blob: bd4bdc5a19e0766e01b52d7a5810fef6668509e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require_relative 'spec_helper'

describe 'Asciidoctor::PDF::Converter - Link' do
  it 'should convert a raw URL to a link' do
    input = 'The home page for Asciidoctor is located at https://asciidoctor.org.'
    pdf = to_pdf input
    annotations = get_annotations pdf, 1
    (expect annotations).to have_size 1
    link_annotation = annotations[0]
    (expect link_annotation[:Subtype]).to eql :Link
    (expect link_annotation[:A][:URI]).to eql 'https://asciidoctor.org'

    pdf = to_pdf input, analyze: true
    link_text = (pdf.find_text 'https://asciidoctor.org')[0]
    (expect link_text).not_to be_nil
    (expect link_text[:font_color]).to eql '428BCA'
    (expect link_text[:x]).to eql link_annotation[:Rect][0]
  end

  it 'should decode character references in the href' do
    input = 'https://github.com/asciidoctor/asciidoctor-pdf/milestones?direction=asc&sort=<>&state=open'
    pdf = to_pdf input
    text = (pdf.page 1).text
    (expect text).to eql input
    link = (get_annotations pdf, 1)[0]
    (expect link[:A][:URI]).to eql input
  end

  it 'should reveal URL of link when media=print or media=prepress' do
    %w(print prepress).each do |media|
      pdf = to_pdf <<~'EOS', attribute_overrides: { 'media' => 'print' }, analyze: true
      https://asciidoctor.org[Asciidoctor] is a text processor.
      EOS

      (expect pdf.lines).to eql ['Asciidoctor [https://asciidoctor.org] is a text processor.']
    end
  end
end