olddoc 1.7.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/GIT-VERSION-GEN +1 -1
- data/bin/olddoc +3 -1
- data/lib/olddoc.rb +1 -0
- data/lib/olddoc/man2html.rb +149 -0
- data/lib/oldweb.rb +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4378b26df172806c7c5ea499ed5250d8e3f2e8147ff3827fcc23cdfc3ef63ff5
|
4
|
+
data.tar.gz: 3e35631b9f3624335d0d980573957f412ceb579c08d14e2c5d63a1efa841b38b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99dad6459056957449f10a32f353da293f28ba92045eb74fc117f0517e88ea687b819e6a014c68fff13d3dc56097dfb1bda5d1969652635fc5ecee0765776f2e
|
7
|
+
data.tar.gz: 127c6789a525ba7d8a171a71fe58b8f0ef7356cc47c05c455a103ff433b506e3125405d6918258a8db6c8d52f40d244e2929b97cf3cac08cbe1df6ab5b426a9e
|
data/GIT-VERSION-GEN
CHANGED
data/bin/olddoc
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# Copyright (C) 2015, all contributors <olddoc-public@80x24.org>
|
2
|
+
# Copyright (C) 2015,2019 all contributors <olddoc-public@80x24.org>
|
3
3
|
$stderr.sync = $stdout.sync = true
|
4
4
|
tasks = %w(prepare merge)
|
5
5
|
usage = "Usage: #{File.basename($0)} [#{tasks.join('|')}]"
|
@@ -10,6 +10,8 @@ when "prepare"
|
|
10
10
|
Olddoc::Prepare.new(opts).run
|
11
11
|
when "merge"
|
12
12
|
Olddoc::Merge.new(opts).run
|
13
|
+
when "man2html"
|
14
|
+
Olddoc::Man2HTML.new(opts).run(ARGV[1..-1])
|
13
15
|
else
|
14
16
|
warn "#{$0.inspect} #{ARGV.inspect} not understood"
|
15
17
|
abort usage
|
data/lib/olddoc.rb
CHANGED
@@ -8,6 +8,7 @@ module Olddoc # :nodoc:
|
|
8
8
|
autoload :NewsRdoc, 'olddoc/news_rdoc'
|
9
9
|
autoload :Prepare, 'olddoc/prepare'
|
10
10
|
autoload :Readme, 'olddoc/readme'
|
11
|
+
autoload :Man2HTML, 'olddoc/man2html'
|
11
12
|
|
12
13
|
def self.config(path = ".olddoc.yml")
|
13
14
|
File.readable?(path) and return YAML.load(File.read(path))
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# Copyright (C) 2019 all contributors <olddoc-public@80x24.org>
|
2
|
+
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
|
3
|
+
# frozen_string_literal: true
|
4
|
+
require 'digest'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
# linkifier for manpages rendered to a terminal. man2html(1) and
|
8
|
+
# groff generate too much style
|
9
|
+
|
10
|
+
class Olddoc::Man2HTML # :nodoc:
|
11
|
+
SALT = rand
|
12
|
+
LINK_RE = %r{([\('!])?\b((?:ftps?|https?|nntps?|gopher)://
|
13
|
+
[\@:\w\.-]+(?:/
|
14
|
+
(?:[a-z0-9\-\._~!\$\&\';\(\)\*\+,;=:@/%]*)
|
15
|
+
(?:\?[a-z0-9\-\._~!\$\&\';\(\)\*\+,;=:@/%]+)?
|
16
|
+
(?:\#[a-z0-9\-\._~!\$\&\';\(\)\*\+,;=:@/%\?]+)?
|
17
|
+
)?
|
18
|
+
)}xi
|
19
|
+
|
20
|
+
PAIRS = {
|
21
|
+
"(" => %r/(\)[\.,;\+]?)\z/, # Markdown (,), Ruby (+) (, for arrays)
|
22
|
+
"'" => %r/('[\.,;\+]?)\z/, # Perl / Ruby
|
23
|
+
"!" => %r/(![\.,;\+]?)\z/, # Perl / Ruby
|
24
|
+
}
|
25
|
+
|
26
|
+
def initialize(opts) # :nodoc:
|
27
|
+
end
|
28
|
+
|
29
|
+
def run(argv) # :nodoc:
|
30
|
+
out = $stdout
|
31
|
+
OptionParser.new("", 24, ' ') do |opts|
|
32
|
+
opts.on('-o', '--output PATH', 'output to given file') { |path|
|
33
|
+
out = File.open(path, 'w')
|
34
|
+
}
|
35
|
+
opts.parse!(argv)
|
36
|
+
end
|
37
|
+
argv[0] or abort 'manpage required'
|
38
|
+
cols = '72'
|
39
|
+
env = ENV.to_hash
|
40
|
+
env.merge!({ 'COLUMNS' => cols, 'MANWIDTH' => cols, 'TERM' => 'dumb' })
|
41
|
+
|
42
|
+
# note: I don't care for the styles groff and man2html throw
|
43
|
+
# on us, I just want indented and wrapped text with <a hrefs>
|
44
|
+
# for URLs.
|
45
|
+
|
46
|
+
# try man-db options, first:
|
47
|
+
str = IO.popen(env, ['man', '--nh', '--nj', *argv], &:read)
|
48
|
+
|
49
|
+
if str.empty? || !$?.success?
|
50
|
+
str = IO.popen(env, ['man', *argv], &:read)
|
51
|
+
end
|
52
|
+
if $?.success?
|
53
|
+
sections = '[A-Z][A-Z ]+'
|
54
|
+
str = str.split(/^(#{sections})$/mo)
|
55
|
+
|
56
|
+
str = str.map! do |s|
|
57
|
+
case s
|
58
|
+
when /\A(#{sections})$/o
|
59
|
+
# this is to be compatible with HTML fragments pandoc used
|
60
|
+
sec = $1
|
61
|
+
anchor = sec.downcase.tr(' ', '-')
|
62
|
+
"<h1\nid=#{anchor.encode(xml: :attr)}>#{sec}</h1>"
|
63
|
+
else
|
64
|
+
state = linkify_1(s)
|
65
|
+
s.encode!(xml: :text)
|
66
|
+
linkify_2(state, s)
|
67
|
+
s.rstrip!
|
68
|
+
s.empty? ? '' : "<pre>#{s}</pre>"
|
69
|
+
end
|
70
|
+
end.join
|
71
|
+
|
72
|
+
out.print(str)
|
73
|
+
|
74
|
+
# use mtime of the original source
|
75
|
+
if out.respond_to?(:path)
|
76
|
+
path = out.path
|
77
|
+
out.close
|
78
|
+
stat = src_input_stat(argv)
|
79
|
+
File.utime(stat.atime, stat.mtime, path) if stat
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def src_input_stat(argv)
|
85
|
+
argv.reverse_each do |f|
|
86
|
+
next unless File.file?(f)
|
87
|
+
return File.stat(f)
|
88
|
+
end
|
89
|
+
|
90
|
+
argv.reverse_each do |f|
|
91
|
+
path = IO.popen(%W(man -w #{f}), &:read)
|
92
|
+
path.chomp!
|
93
|
+
next unless File.file?(path)
|
94
|
+
return File.stat(path)
|
95
|
+
end
|
96
|
+
nil
|
97
|
+
end
|
98
|
+
|
99
|
+
def linkify_1(str) # :nodoc:
|
100
|
+
state = {}
|
101
|
+
str.gsub!(LINK_RE) do
|
102
|
+
head = $1 || ''
|
103
|
+
url = $2.dup
|
104
|
+
tail = ''.dup
|
105
|
+
|
106
|
+
# it's fairly common to end URLs in messages with
|
107
|
+
# '.', ',' or ';' to denote the end of a statement;
|
108
|
+
# assume the intent was to end the statement/sentence
|
109
|
+
# in English
|
110
|
+
if re = PAIRS[head]
|
111
|
+
url.sub!(re, '')
|
112
|
+
tail = $1
|
113
|
+
elsif url.sub!(/(\))?([\.,;])\z/, '')
|
114
|
+
tail = $2
|
115
|
+
# require ')' to be paired with '('
|
116
|
+
if $1 # ')'
|
117
|
+
if url.index('(').nil?
|
118
|
+
tail = ")#{tail}"
|
119
|
+
else
|
120
|
+
url += ')'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
elsif url !~ /\(/ && url.sub!(/\)\z/, '')
|
124
|
+
tail = ')'
|
125
|
+
end
|
126
|
+
|
127
|
+
# salt this, as this could be exploited to show
|
128
|
+
# links in the HTML which don't show up in the raw mail.
|
129
|
+
key = Digest::MD5.hexdigest("#{url}#{SALT}").freeze
|
130
|
+
state[key] = url
|
131
|
+
"#{head}OLD-LINK-#{key}#{tail}"
|
132
|
+
end
|
133
|
+
state
|
134
|
+
end
|
135
|
+
|
136
|
+
def linkify_2(state, str) # :nodoc:
|
137
|
+
# Added "OLD-LINK-" prefix to avoid false-positives on git commits
|
138
|
+
str.gsub!(/\bOLD-LINK-([a-f0-9]{32})\b/) do
|
139
|
+
key = $1
|
140
|
+
url = state[key]
|
141
|
+
if url
|
142
|
+
%Q{<a\nhref=#{url.encode(xml: :attr)}>#{url.encode(xml: :text)}</a>}
|
143
|
+
else
|
144
|
+
# false positive or somebody tried to mess with us
|
145
|
+
key
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
data/lib/oldweb.rb
CHANGED
@@ -5,7 +5,7 @@ require 'rdoc'
|
|
5
5
|
require 'erb'
|
6
6
|
require 'pathname'
|
7
7
|
require 'yaml'
|
8
|
-
require '
|
8
|
+
require 'cgi'
|
9
9
|
|
10
10
|
# oldweb is an \RDoc template and not intended as a programming API.
|
11
11
|
# You may specify it as an \RDoc formatter:
|
@@ -87,7 +87,7 @@ class Oldweb
|
|
87
87
|
|
88
88
|
if cgit_url
|
89
89
|
cgit_url += '/tree/%s' # path name
|
90
|
-
tag = @git_tag and cgit_url << "id=#{
|
90
|
+
tag = @git_tag and cgit_url << "id=#{CGI.escape(tag)}"
|
91
91
|
cgit_url << '#n%d' # lineno
|
92
92
|
@old_vcs_url = cgit_url
|
93
93
|
end
|
@@ -297,7 +297,7 @@ class Oldweb
|
|
297
297
|
def method_srclink(m) # :nodoc:
|
298
298
|
url = @old_vcs_url or return ""
|
299
299
|
line = m.line or return ""
|
300
|
-
path =
|
300
|
+
path = CGI.escape(m.file_name)
|
301
301
|
%Q(<a href="#{url % [ path, line ]}">source</a>)
|
302
302
|
end
|
303
303
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: olddoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- olddoc hackers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/olddoc.rb
|
61
61
|
- lib/olddoc/gemspec.rb
|
62
62
|
- lib/olddoc/history.rb
|
63
|
+
- lib/olddoc/man2html.rb
|
63
64
|
- lib/olddoc/merge.rb
|
64
65
|
- lib/olddoc/news_atom.rb
|
65
66
|
- lib/olddoc/news_rdoc.rb
|