prawndown-ext 0.1.7 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1bd6519db873bccdf6e70d074fef2de91fed77183cf0bc3d5c98c7141a9ed401
4
- data.tar.gz: 6c1437518072c4a8f4e638de7d4d2afb57f9486118393d426ca72a37b5295e55
3
+ metadata.gz: 01be81f1ee2b7abfc146e5965bd1c70cf70c4194070ca69c6be11c51bb492a84
4
+ data.tar.gz: 63a75b0bdffb9d985b45895201e6b4edd9e3f76d2da934be413153331409858d
5
5
  SHA512:
6
- metadata.gz: 4f998d15bf130fe474b49c511933814ef921f5357206ab8dc04f627464d443618a0e3b2f83b2b411244736b49689f423d27ad6cd16793ba724608c83e658cca9
7
- data.tar.gz: 654ab49b3a3e398ca247609ce5e4035494c7c83cacce614a96cb7b02d729b41dfc15fb53c683bd97a6d86365400986af220e931ef7ea921b720b7f8dc85d4b2f
6
+ metadata.gz: 356e6b501c171868581103a98614f4ac5ffc1975712833d06ad818c67155e093b9468bc1c8f8810d261b70a3c1dc2191a0d65554c15887cef99f08bd2a25e206
7
+ data.tar.gz: 9bc56bc6ce9444aa13e63b0c4d4471d2f66ffbbc22a1d82c3d475c7c3d6dc38fd02df746ac3d789d64e72b3450ee01769f9c9c8f13f6528ba300c312212890a8
@@ -31,36 +31,49 @@ module PrawndownExt
31
31
  "header5_font" => nil,
32
32
  "header6_font" => nil,
33
33
  "quote_margin" => 20,
34
+ "header1_margin" => 4,
35
+ "header2_margin" => 4,
36
+ "header3_margin" => 4,
37
+ "header4_margin" => 4,
38
+ "header5_margin" => 4,
39
+ "header6_margin" => 4,
40
+ "img_dir" => "",
34
41
  }
35
42
 
36
43
  MATCHERS = {
44
+ # Removes carriage returns, they cause issues
45
+ /\r/ => '',
37
46
  /<iframe ([^\[]+)<\/iframe>/ => '', # Embeds are just removed
38
47
  /(\*\*|__)(.*?)\1/ => '<b>\2</b>', # Bold
39
48
  /(\*|_)(.*?)\1/ => '<i>\2</i>', # Italic
40
49
  /\~\~(.*?)\~\~/ => '<strikethrough>\1</strikethrough>', # Strikethrough
41
50
  ## Regular markdown
42
51
  ## Header 1
43
- /^# (.+)/ => '<command_break>{"command":"header1","margin":QUOTE_MARGIN,"text":"<font name=\'HEADER1_FONT\' size=\'HEADER1_SIZE\'><b>\1</b></font>"}<command_break>',
52
+ /(^# )(.+)/ => '<command_break>{"command":"header1","margin":HEADER1_MARGIN,"text":"<font name=\'HEADER1_FONT\' size=\'HEADER1_SIZE\'><b>\2</b></font>"}<command_break>',
44
53
  ## Header 2
45
- /^## (.+)/ => '<command_break>{"command":"header2","margin":QUOTE_MARGIN,"text":"<font name=\'HEADER2_FONT\' size=\'HEADER2_SIZE\'><b>\1</b></font>"}<command_break>',
54
+ /(^## )(.*)/ => '<command_break>{"command":"header2","margin":HEADER2_MARGIN,"text":"<font name=\'HEADER2_FONT\' size=\'HEADER2_SIZE\'><b>\2</b></font>"}<command_break>',
46
55
  ## Header 3
47
- /^### (.+)/ => '<command_break>{"command":"header3","margin":QUOTE_MARGIN,"text":"<font name=\'HEADER3_FONT\' size=\'HEADER3_SIZE\'><b>\1</b></font>"}<command_break>',
56
+ /(^### )(.*)/ => '<command_break>{"command":"header3","margin":HEADER3_MARGIN,"text":"<font name=\'HEADER3_FONT\' size=\'HEADER3_SIZE\'><b>\2</b></font>"}<command_break>',
48
57
  ## Header 4
49
- /^#### (.+)/ => '<command_break>{"command":"header4","margin":QUOTE_MARGIN,"text":"<font name=\'HEADER4_FONT\' size=\'HEADER4_SIZE\'><b>\1</b></font>"}<command_break>',
58
+ /(^#### )(.*)/ => '<command_break>{"command":"header4","margin":HEADER4_MARGIN,"text":"<font name=\'HEADER4_FONT\' size=\'HEADER4_SIZE\'><b>\2</b></font>"}<command_break>',
50
59
  ## Header 5
51
- /^##### (.+)/ => '<command_break>{"command":"header5","margin":QUOTE_MARGIN,"text":"<font name=\'HEADER5_FONT\' size=\'HEADER5_SIZE\'><b>\1</b></font>"}<command_break>',
60
+ /(^##### )(.*)/ => '<command_break>{"command":"header5","margin":HEADER5_MARGIN,"text":"<font name=\'HEADER5_FONT\' size=\'HEADER5_SIZE\'><b>\2</b></font>"}<command_break>',
52
61
  ## Header 6
53
- /^###### (.+)/ => '<command_break>{"command":"header6","margin":QUOTE_MARGIN,"text":"<font name=\'HEADER6_FONT\' size=\'HEADER6_SIZE\'><b>\1</b></font>"}<command_break>',
62
+ /(^###### )(.*)/ => '<command_break>{"command":"header6","margin":HEADER6_MARGIN,"text":"<font name=\'HEADER6_FONT\' size=\'HEADER6_SIZE\'><b>\2</b></font>"}<command_break>',
54
63
 
55
64
  # Command Break items
56
65
  # These split into multiple commands for output
57
66
 
58
67
  # Images
59
68
  /!\[([^\[]+)\]\(([^\)]+)\)/ => '<command_break>{"command":"img", "alt":"\1", "path":"\2"}<command_break>',
60
- /^> (.+)/ => '<command_break>{"command":"quote","margin":QUOTE_MARGIN,"text":"<font name=\'QUOTE_FONT\' character_spacing=\'QUOTE_FONT_SPACING\' size=\'QUOTE_SIZE\'>\\1</font>"}<command_break>', # Quote
69
+ /^> (.+)/ => '<command_break>{"command":"quote","margin":QUOTE_MARGIN,"text":"<font name=\'QUOTE_FONT\' character_spacing=\'QUOTE_FONT_SPACING\' size=\'QUOTE_SIZE\'>\1</font>"}<command_break>', # Quote
61
70
 
62
71
  # Stuff to process last
63
72
  /\[([^\[]+)\]\(([^\)]+)\)/ => '<link href="\2">\1</link>', # Link
73
+
74
+ # Special commands exclusive to prawndown-ext to control output
75
+ # Two breaks in a row signifies a new page
76
+ /<br><br>/ => '<command_break>{"command":"newpage"}<command_break>'
64
77
  }
65
78
 
66
79
  def escape_text text
@@ -2,6 +2,6 @@
2
2
 
3
3
  module PrawndownExt
4
4
  module Ext
5
- VERSION = "0.1.7"
5
+ VERSION = "0.1.10"
6
6
  end
7
7
  end
data/lib/prawndown-ext.rb CHANGED
@@ -19,6 +19,7 @@ module PrawndownExt
19
19
  "header4" => -> (args,pdf, options) { cl_text_box(args, pdf, options) },
20
20
  "header5" => -> (args,pdf, options) { cl_text_box(args, pdf, options) },
21
21
  "header6" => -> (args,pdf, options) { cl_text_box(args, pdf, options) },
22
+ "newpage" => -> (args,pdf, options) { cl_newline(args, pdf, options) }
22
23
  }
23
24
 
24
25
  def self.cl_text args, pdf, options
@@ -31,7 +32,7 @@ module PrawndownExt
31
32
  if !options.key?(args["command"] + "_line_spacing")
32
33
  options[args["command"] + "_line_spacing"] = 0
33
34
  end
34
-
35
+
35
36
  if !options.key?("margin")
36
37
  args["margin"] = 0
37
38
  end
@@ -45,9 +46,31 @@ module PrawndownExt
45
46
  end
46
47
 
47
48
  def self.cl_img args, pdf, options
48
- pdf.image(args["path"],
49
- width: pdf.bounds.width,
50
- position: :center)
49
+ if options.key?("no_image")
50
+ if options["no_image"]
51
+ return
52
+ end
53
+ end
54
+
55
+ if args["path"][0] == "/"
56
+ args["path"] = args["path"][1..-1]
57
+ end
58
+
59
+ file = options["image_dir"] + "/" + args["path"]
60
+
61
+ if !File.file?(file)
62
+ file = "." + options["image_dir"] + "/" + args["path"]
63
+ end
64
+
65
+ if File.extname(file) != ".gif"
66
+ pdf.image(file,
67
+ width: pdf.bounds.width,
68
+ position: :center)
69
+ end
70
+ end
71
+
72
+ def self.cl_newline args, pdf, options
73
+ pdf.start_new_page()
51
74
  end
52
75
 
53
76
 
@@ -78,6 +101,7 @@ module PrawndownExt
78
101
  # markdown '**Important:** We _hope_ you enjoy your stay!'
79
102
  # end
80
103
  def markdown(string, options: {})
104
+
81
105
  if !options.key?("default_line_spacing")
82
106
  options["default_line_spacing"] = 0
83
107
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawndown-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - PunishedFelix
@@ -30,8 +30,8 @@ dependencies:
30
30
  - !ruby/object:Gem::Version
31
31
  version: 2.5.0
32
32
  description: Extension of Prawndown to include additional Markdown features. Currently
33
- supports custom header sizes, removing iframe content. Need to write more to make
34
- images work.
33
+ supports custom header sizes, fonts, and other properties; removing iframe content,
34
+ and support for images and quotes.
35
35
  email:
36
36
  - labadore1844@gmail.com
37
37
  executables: []
@@ -61,5 +61,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  requirements: []
62
62
  rubygems_version: 3.6.9
63
63
  specification_version: 4
64
- summary: Extension of Prawndown to include additional features.
64
+ summary: Extension of Prawndown to include additional features, such as customizing
65
+ text fonts, sizes, and support for images and quotes.
65
66
  test_files: []