pdftomd-url-tools 0.1.0

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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +19 -0
  4. data/ruby/lib/pdftomd_url_tools.rb +60 -0
  5. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0801d4241edd492fc5597b3202c544446c66d6f0d87b3b1544c4c1532e72a542'
4
+ data.tar.gz: abacd143ba7e531983618dbbc1c88e35b99b418d1d7e1272700d12f547b0f363
5
+ SHA512:
6
+ metadata.gz: f24e401f9b9c4de8e190a750fe8f18217610673c7cec1bdda441c3b055520120d03015786bed1ee3580be13a7d7da7dcd403a525f32fef9593c77f1c016b4f52
7
+ data.tar.gz: e81544458e91325d17e5ecf0c4ca6c18a0eed2e8b791e421a551c9dc2372b946be95e45e2346812831869bff022a378a5a89cc9c2422b5283aaad1eb3daf7b3d
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 wangneo276-lgtm
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # pdftomd-url-tools
2
+
3
+ Builds canonical HTTPS URLs for pages that exist on [PDF to MD Converter](https://pdftomd.tools/).
4
+
5
+ Free in-browser pdf to md tool. Drop a text PDF, preview Markdown, copy or download—files stay on your device. No account required.
6
+
7
+ Not an official SDK. The helper only accepts paths that are already on the public site. It does not upload files or call the site.
8
+
9
+ ## Examples
10
+
11
+ - `canonicalUrl("/")` → https://pdftomd.tools/
12
+ - `canonicalUrl("https://pdftomd.tools/md-to-pdf?ref=1#top")` → https://pdftomd.tools/md-to-pdf
13
+ - `pageUrl("pdf-to-md")` → https://pdftomd.tools/pdf-to-md-converter
14
+ - `pageUrl("markdown-to-pdf")` → https://pdftomd.tools/markdown-to-pdf
15
+ - `blogUrl("convert-pdf-tables-to-markdown")` → https://pdftomd.tools/blog/convert-pdf-tables-to-markdown
16
+
17
+ Source: https://github.com/wangneo276-lgtm/pdftomd-url-tools
18
+
19
+ License: MIT.
@@ -0,0 +1,60 @@
1
+ module PdfToMdUrlTools
2
+ ORIGIN = 'https://pdftomd.tools'.freeze
3
+ DESCRIPTION = 'Free in-browser pdf to md tool. Drop a text PDF, preview Markdown, copy or download—files stay on your device. No account required.'.freeze
4
+ HOST = 'pdftomd.tools'.freeze
5
+ PATHS = ['/', '/about', '/batch-pdf-to-markdown', '/blog', '/blog/best-document-format-for-chatgpt', '/blog/convert-multiple-pdfs-to-markdown', '/blog/convert-pdf-tables-to-markdown', '/blog/convert-pdf-to-markdown-locally', '/blog/convert-pdf-to-markdown-without-losing-formatting', '/blog/import-pdf-into-obsidian-as-notes', '/blog/markdown-to-pdf-page-breaks', '/blog/print-markdown-to-pdf-with-tables', '/blog/pymupdf4llm-vs-pdfplumber-vs-marker', '/convert-pdf-to-md', '/markdown-to-pdf', '/md-to-pdf', '/pdf-to-markdown-for-llm', '/pdf-to-markdown-obsidian', '/pdf-to-markdown-python', '/pdf-to-md-converter', '/privacy-policy', '/terms-of-service'].freeze
6
+ PAGES = {'home' => '/', 'pdf-to-md' => '/pdf-to-md-converter', 'convert' => '/convert-pdf-to-md', 'md-to-pdf' => '/md-to-pdf', 'markdown-to-pdf' => '/markdown-to-pdf', 'llm' => '/pdf-to-markdown-for-llm', 'batch' => '/batch-pdf-to-markdown', 'obsidian' => '/pdf-to-markdown-obsidian', 'python' => '/pdf-to-markdown-python', 'about' => '/about', 'privacy' => '/privacy-policy', 'terms' => '/terms-of-service', 'blog' => '/blog'}.freeze
7
+ BLOGS = {'pymupdf4llm-vs-pdfplumber-vs-marker' => '/blog/pymupdf4llm-vs-pdfplumber-vs-marker', 'import-pdf-into-obsidian-as-notes' => '/blog/import-pdf-into-obsidian-as-notes', 'convert-multiple-pdfs-to-markdown' => '/blog/convert-multiple-pdfs-to-markdown', 'convert-pdf-to-markdown-locally' => '/blog/convert-pdf-to-markdown-locally', 'markdown-to-pdf-page-breaks' => '/blog/markdown-to-pdf-page-breaks', 'best-document-format-for-chatgpt' => '/blog/best-document-format-for-chatgpt', 'convert-pdf-to-markdown-without-losing-formatting' => '/blog/convert-pdf-to-markdown-without-losing-formatting', 'print-markdown-to-pdf-with-tables' => '/blog/print-markdown-to-pdf-with-tables', 'convert-pdf-tables-to-markdown' => '/blog/convert-pdf-tables-to-markdown'}.freeze
8
+
9
+ module_function
10
+
11
+ def canonical_url(input)
12
+ raise ArgumentError, 'path required' unless input.is_a?(String)
13
+ raw = input.strip
14
+ raise ArgumentError, 'path required' if raw.empty?
15
+ raise ArgumentError, 'invalid path' if raw.include?('\\') || raw.include?('%')
16
+ raw = raw.split('#', 2)[0].split('?', 2)[0]
17
+ lower = raw.downcase
18
+ if lower.start_with?('https://') || lower.start_with?('http://') || raw.start_with?('//')
19
+ rest = if lower.start_with?('https://')
20
+ raw.delete_prefix('https://')
21
+ elsif lower.start_with?('http://')
22
+ raw.delete_prefix('http://')
23
+ else
24
+ raw.delete_prefix('//')
25
+ end
26
+ slash = rest.index('/')
27
+ hostport = slash.nil? ? rest : rest[0...slash]
28
+ path = slash.nil? ? '/' : rest[slash..]
29
+ raise ArgumentError, 'userinfo not allowed' if hostport.include?('@')
30
+ raise ArgumentError, 'port not allowed' if hostport.include?(':')
31
+ raise ArgumentError, 'host not allowed' unless hostport.casecmp(HOST).zero?
32
+ elsif raw.start_with?('/')
33
+ path = raw
34
+ else
35
+ path = '/' + raw
36
+ end
37
+ path = path.downcase.gsub(%r{//+}, '/')
38
+ path.split('/').each do |seg|
39
+ raise ArgumentError, 'path traversal' if seg == '.' || seg == '..'
40
+ end
41
+ path = path.sub(%r{/+$}, '') if path.length > 1
42
+ path = '/' if path.empty?
43
+ raise ArgumentError, "unknown path: #{path}" unless PATHS.include?(path)
44
+ path == '/' ? ORIGIN + '/' : ORIGIN + path
45
+ end
46
+
47
+ def home_url
48
+ canonical_url('/')
49
+ end
50
+
51
+ def page_url(name)
52
+ path = PAGES[name] or raise ArgumentError, "unknown page: #{name}"
53
+ canonical_url(path)
54
+ end
55
+
56
+ def blog_url(slug)
57
+ path = BLOGS[slug] or raise ArgumentError, "unknown blog: #{slug}"
58
+ canonical_url(path)
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pdftomd-url-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - wangneo276-lgtm
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Free in-browser pdf to md tool. Drop a text PDF, preview Markdown, copy
13
+ or download—files stay on your device. No account required.
14
+ executables: []
15
+ extensions: []
16
+ extra_rdoc_files: []
17
+ files:
18
+ - LICENSE
19
+ - README.md
20
+ - ruby/lib/pdftomd_url_tools.rb
21
+ homepage: https://pdftomd.tools/
22
+ licenses:
23
+ - MIT
24
+ metadata:
25
+ homepage_uri: https://pdftomd.tools/
26
+ source_code_uri: https://github.com/wangneo276-lgtm/pdftomd-url-tools
27
+ rdoc_options: []
28
+ require_paths:
29
+ - ruby/lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '3.0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 4.0.11
42
+ specification_version: 4
43
+ summary: Free in-browser pdf to md tool. Drop a text PDF, preview Markdown, copy or
44
+ download—files stay on your device. No account required.
45
+ test_files: []