docwatch-bin 1.1.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/docwatch +7 -5
- data/lib/docwatch/parser/frontmatter.rb +38 -0
- data/lib/docwatch/parser.rb +4 -0
- data/lib/docwatch/renderer/html.rb +1 -1
- data/lib/docwatch/renderer/markdown.rb +27 -5
- data/lib/docwatch/util/html.rb +22 -0
- data/lib/docwatch/version.rb +1 -1
- data/lib/docwatch.rb +2 -0
- data/res/github-markdown.css +0 -27
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb509ceb6063ce6bb07c728131806b0d6705b26cf869e0eca31f6008ad03f3f5
|
4
|
+
data.tar.gz: 40815b8a502babfa8deb9c3329868d3bdfcae8ffb71b863bdcdb1ccffb73ae76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 913f44ffdd8cadf8010115a3766c9d206ef161f9e88b1eee0965e4602229c6b0287aa5a976c5a4a9564073fa5e5ca70c426e3582c7d6e8269ec5db47807fe6ab
|
7
|
+
data.tar.gz: 721d248f9cea2d72f2d1b68d1d092bb28f01fd78daf0911f4e12375ec06bd52cc150d5ae48605f00dca7c5a424c15157f178017594dc5c5f322eae4eeea2e1f0
|
data/bin/docwatch
CHANGED
@@ -86,7 +86,7 @@ class Main
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
puts
|
89
|
+
puts 'Started server on %s, renderer %s'.yellow % [url, renderer.class]
|
90
90
|
puts 'Press enter to open page in the default handler (xdg-open)'.green
|
91
91
|
|
92
92
|
begin
|
@@ -95,21 +95,23 @@ class Main
|
|
95
95
|
end
|
96
96
|
rescue Interrupt
|
97
97
|
puts
|
98
|
-
puts 'Bye'
|
98
|
+
puts 'Bye!'
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
+
PROGRAM_NAME = File.basename($PROGRAM_NAME)
|
104
|
+
|
103
105
|
usage = <<~EOF
|
104
106
|
Usage:
|
105
|
-
#{
|
106
|
-
#{
|
107
|
+
#{PROGRAM_NAME} [options] <file-path>
|
108
|
+
#{PROGRAM_NAME} ( --version | --help )
|
107
109
|
|
108
110
|
Options:
|
109
111
|
-p, --port=VALUE Listen port [default: 8888]
|
110
112
|
--verbose Be verbose
|
111
113
|
-v, --version Show version
|
112
|
-
-h, --help Show
|
114
|
+
-h, --help Show help
|
113
115
|
|
114
116
|
Renderers:
|
115
117
|
markdown (.md)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Docwatch
|
2
|
+
class Parser::Frontmatter < Parser
|
3
|
+
def self.split(str)
|
4
|
+
lines = str.lines
|
5
|
+
|
6
|
+
if lines.first.chomp != '---'
|
7
|
+
return [nil, str]
|
8
|
+
end
|
9
|
+
|
10
|
+
in_frontmatter = false
|
11
|
+
in_document = false
|
12
|
+
document = ''
|
13
|
+
frontmatter_yaml = ''
|
14
|
+
|
15
|
+
lines.each do |line|
|
16
|
+
if line.strip == '---'
|
17
|
+
in_frontmatter = !in_frontmatter
|
18
|
+
in_document = true if !in_frontmatter
|
19
|
+
elsif in_frontmatter
|
20
|
+
frontmatter_yaml += line
|
21
|
+
elsif in_document
|
22
|
+
document += line
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
[Frontmatter.new(frontmatter_yaml), document]
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(yaml)
|
30
|
+
@data = YAML.safe_load(yaml)
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_html
|
35
|
+
Util::HTML.render(@data)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Docwatch
|
2
|
-
class
|
2
|
+
class Renderer::Markdown < Renderer
|
3
3
|
extension :md
|
4
4
|
|
5
5
|
def head
|
@@ -13,13 +13,35 @@ module Docwatch
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def body
|
16
|
-
|
17
|
-
|
16
|
+
# https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
|
17
|
+
markdown_args = {
|
18
18
|
fenced_code_blocks: true,
|
19
|
-
autolink: true,
|
20
19
|
tables: true,
|
20
|
+
no_intra_emphasis: true,
|
21
|
+
strikethrough: true,
|
22
|
+
space_after_headers: true,
|
23
|
+
superscript: true,
|
24
|
+
highlight: true,
|
21
25
|
footnotes: true,
|
22
|
-
|
26
|
+
}
|
27
|
+
|
28
|
+
# https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch
|
29
|
+
html_args = {
|
30
|
+
with_toc_data: true,
|
31
|
+
link_attributes: { rel: 'noreferrer nofollow noopener' },
|
32
|
+
hard_wrap: true, # no need for trailing spaces to create new paragraphs
|
33
|
+
}
|
34
|
+
|
35
|
+
frontmatter, document = Parser::Frontmatter.split(contents)
|
36
|
+
|
37
|
+
if frontmatter
|
38
|
+
document = frontmatter.to_html + document
|
39
|
+
end
|
40
|
+
|
41
|
+
Redcarpet::Markdown.new(
|
42
|
+
Redcarpet::Render::HTML.new(html_args),
|
43
|
+
markdown_args,
|
44
|
+
).render(document)
|
23
45
|
end
|
24
46
|
end
|
25
47
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Docwatch
|
2
|
+
module Util
|
3
|
+
class HTML
|
4
|
+
def self.render(data)
|
5
|
+
case data
|
6
|
+
when Hash
|
7
|
+
rows = data.map do |(k, v)|
|
8
|
+
'<th>%s</th><td>%s</td>' % [HTML.render(k), HTML.render(v)]
|
9
|
+
end.join('</tr><tr>')
|
10
|
+
'<table><tr>%s</tr></table>' % rows
|
11
|
+
when Array
|
12
|
+
rows = data.map do |v|
|
13
|
+
'<li>%s</li>' % HTML.render(v)
|
14
|
+
end.join
|
15
|
+
'<ul>%s</ul>' % rows
|
16
|
+
else
|
17
|
+
CGI.escapeHTML(data.to_s)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/docwatch/version.rb
CHANGED
data/lib/docwatch.rb
CHANGED
data/res/github-markdown.css
CHANGED
@@ -428,30 +428,3 @@
|
|
428
428
|
background-color: initial;
|
429
429
|
border: 0
|
430
430
|
}
|
431
|
-
|
432
|
-
.container .csv-data td,
|
433
|
-
.container .csv-data th {
|
434
|
-
padding: 5px;
|
435
|
-
overflow: hidden;
|
436
|
-
font-size: 12px;
|
437
|
-
line-height: 1;
|
438
|
-
text-align: left;
|
439
|
-
white-space: nowrap
|
440
|
-
}
|
441
|
-
|
442
|
-
.container .csv-data .blob-num {
|
443
|
-
padding: 10px 8px 9px;
|
444
|
-
text-align: right;
|
445
|
-
background: #fff;
|
446
|
-
border: 0
|
447
|
-
}
|
448
|
-
|
449
|
-
.container .csv-data tr {
|
450
|
-
border-top: 0
|
451
|
-
}
|
452
|
-
|
453
|
-
.container .csv-data th {
|
454
|
-
font-weight: 600;
|
455
|
-
background: #f6f8fa;
|
456
|
-
border-top: 0
|
457
|
-
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docwatch-bin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crdx
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -133,10 +133,13 @@ files:
|
|
133
133
|
- lib/docwatch.rb
|
134
134
|
- lib/docwatch/connection.rb
|
135
135
|
- lib/docwatch/logger.rb
|
136
|
+
- lib/docwatch/parser.rb
|
137
|
+
- lib/docwatch/parser/frontmatter.rb
|
136
138
|
- lib/docwatch/renderer.rb
|
137
139
|
- lib/docwatch/renderer/html.rb
|
138
140
|
- lib/docwatch/renderer/markdown.rb
|
139
141
|
- lib/docwatch/session.rb
|
142
|
+
- lib/docwatch/util/html.rb
|
140
143
|
- lib/docwatch/version.rb
|
141
144
|
- lib/docwatch/watcher.rb
|
142
145
|
- res/github-markdown.css
|
@@ -161,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
164
|
- !ruby/object:Gem::Version
|
162
165
|
version: '0'
|
163
166
|
requirements: []
|
164
|
-
rubygems_version: 3.
|
167
|
+
rubygems_version: 3.3.8
|
165
168
|
signing_key:
|
166
169
|
specification_version: 4
|
167
170
|
summary: Preview markdown documents in the browser with reload on change
|