File: inline.rb

package info (click to toggle)
ruby-prawn 2.5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,528 kB
  • sloc: ruby: 17,688; sh: 43; makefile: 20
file content (48 lines) | stat: -rw-r--r-- 1,674 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

require 'prawn/manual_builder'

Prawn::ManualBuilder::Chapter.new do
  title 'Inline Formatting'

  text do
    prose <<~TEXT
      Inline formatting gives you the option to format specific portions of a
      text. It uses HTML-esque syntax inside the text string. Supported tags
      are: <code>b</code> (bold), <code>i</code> (italic), <code>u</code>
      (underline), <code>strikethrough</code>, <code>sub</code> (subscript),
      <code>sup</code> (superscript).

      The following tags accept specific attributes: <code>font</code> accepts
      <code>size</code>, <code>name</code>, and <code>character_spacing</code>;
      <code>color</code> accepts <code>rgb</code> and set of <code>c</code>,
      <code>m</code>, <code>y</code>, and <code>k</code>;
      <code>link</code> accepts <code>href</code> for external links.
    TEXT
  end

  example do
    %w[b i u strikethrough sub sup].each do |tag|
      text "Just your regular text <#{tag}>except this portion</#{tag}> " \
        "is using the #{tag} tag",
        inline_format: true
      # move_down 10
    end

    text "This <font size='18'>line</font> uses " \
      "<font name='Courier'>all the font tag</font> attributes in " \
      "<font character_spacing='2'>a single line</font>. ",
      inline_format: true
    # move_down 10

    text "Coloring in <color rgb='FF00FF'>both RGB</color> " \
      "<color c='100' m='0' y='0' k='0'>and CMYK</color>",
      inline_format: true
    # move_down 10

    text 'This an external link to the ' \
      "<u><link href='https://prawnpdf.org/'>Prawn home page" \
      '</link></u>',
      inline_format: true
  end
end