markdownr 0.5.1 → 0.5.2
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 +4 -4
- data/lib/markdown_server/app.rb +36 -8
- data/lib/markdown_server/version.rb +1 -1
- data/views/layout.erb +3 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e91138e164e026f52b6957f44693eb86d75b79eda7e4404d094f1ea0d4e35d26
|
|
4
|
+
data.tar.gz: b549ff9d07b45f43cc1639c2b4a47171f3a38bb76e2e98c1bb0ffe03ddc53fbe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cfc1004e65a89e09263f3a35f2da2b3b354afe8351efa87e49194b0aec3bef5aaeedd7d4aba70f00c01ebca6468150a296be2bdad0d8ca238f87b5bc73ebca0d
|
|
7
|
+
data.tar.gz: c0cc3d73580b42c40c3f9244ed5acc69a74363237c54af0d21877bf4f1a64d2b642150fc4c384d13a6efb74a1bf86f12819d10b913f935ff60298e1e055e8460
|
data/lib/markdown_server/app.rb
CHANGED
|
@@ -180,15 +180,33 @@ module MarkdownServer
|
|
|
180
180
|
def resolve_wiki_link(name)
|
|
181
181
|
filename = "#{name}.md"
|
|
182
182
|
base = File.realpath(root_dir)
|
|
183
|
+
|
|
184
|
+
# Check the current file's directory first (exact case, then case-insensitive)
|
|
185
|
+
if @current_wiki_dir
|
|
186
|
+
local_exact = nil
|
|
187
|
+
local_ci = nil
|
|
188
|
+
Dir.glob(File.join(@current_wiki_dir, filename), File::FNM_CASEFOLD).each do |path|
|
|
189
|
+
real = File.realpath(path) rescue next
|
|
190
|
+
next unless real.start_with?(base)
|
|
191
|
+
relative = real.sub("#{base}/", "")
|
|
192
|
+
first_segment = relative.split("/").first
|
|
193
|
+
next if EXCLUDED.include?(first_segment) || first_segment&.start_with?(".")
|
|
194
|
+
if File.basename(real) == filename
|
|
195
|
+
local_exact = relative
|
|
196
|
+
break
|
|
197
|
+
else
|
|
198
|
+
local_ci ||= relative
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
return local_exact if local_exact
|
|
202
|
+
return local_ci if local_ci
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
# Fall back to global recursive search
|
|
183
206
|
exact_match = nil
|
|
184
207
|
ci_match = nil
|
|
185
|
-
|
|
186
208
|
Dir.glob(File.join(base, "**", filename), File::FNM_CASEFOLD).each do |path|
|
|
187
|
-
|
|
188
|
-
real = File.realpath(path)
|
|
189
|
-
rescue Errno::ENOENT
|
|
190
|
-
next
|
|
191
|
-
end
|
|
209
|
+
real = File.realpath(path) rescue next
|
|
192
210
|
next unless real.start_with?(base)
|
|
193
211
|
relative = real.sub("#{base}/", "")
|
|
194
212
|
first_segment = relative.split("/").first
|
|
@@ -517,7 +535,7 @@ module MarkdownServer
|
|
|
517
535
|
if slash.empty?
|
|
518
536
|
m = attrs.match(/href\s*=\s*["']([^"']*)["']/i)
|
|
519
537
|
if m && !m[1].match?(/\Ajavascript:/i)
|
|
520
|
-
href = m[1]
|
|
538
|
+
href = m[1].gsub(/&/i, "&")
|
|
521
539
|
if base_url && href !~ /\Ahttps?:\/\//i && !href.start_with?("#")
|
|
522
540
|
href = (URI.join(base_url, href).to_s rescue href)
|
|
523
541
|
end
|
|
@@ -635,9 +653,18 @@ module MarkdownServer
|
|
|
635
653
|
|
|
636
654
|
meta, body = parse_frontmatter(content)
|
|
637
655
|
title = (meta.is_a?(Hash) && meta["title"]) || File.basename(real, ".md")
|
|
656
|
+
@current_wiki_dir = File.dirname(real)
|
|
638
657
|
html = render_markdown(body)
|
|
639
658
|
|
|
640
|
-
|
|
659
|
+
frontmatter_html = ""
|
|
660
|
+
if meta && !meta.empty?
|
|
661
|
+
rows = meta.map { |key, value|
|
|
662
|
+
"<tr><th>#{h(key)}</th><td>#{render_frontmatter_value(value)}</td></tr>"
|
|
663
|
+
}.join
|
|
664
|
+
frontmatter_html = %(<div class="frontmatter"><div class="frontmatter-heading">Frontmatter</div><table class="meta-table">#{rows}</table></div>)
|
|
665
|
+
end
|
|
666
|
+
|
|
667
|
+
JSON.dump({ title: title.to_s, html: html, frontmatter_html: frontmatter_html })
|
|
641
668
|
end
|
|
642
669
|
|
|
643
670
|
get "/fetch" do
|
|
@@ -748,6 +775,7 @@ module MarkdownServer
|
|
|
748
775
|
when ".md"
|
|
749
776
|
content = File.read(real_path, encoding: "utf-8")
|
|
750
777
|
@meta, body = parse_frontmatter(content)
|
|
778
|
+
@current_wiki_dir = File.dirname(real_path)
|
|
751
779
|
@content = render_markdown(body)
|
|
752
780
|
@toc = extract_toc(@content)
|
|
753
781
|
@has_toc = @toc.length > 1
|
data/views/layout.erb
CHANGED
|
@@ -1578,8 +1578,9 @@
|
|
|
1578
1578
|
.then(function(r) { return r.ok ? r.json() : null; })
|
|
1579
1579
|
.then(function(data) {
|
|
1580
1580
|
if (!data) { cache[path] = false; updatePopup('<p style="margin:0;color:#c44;font-family:sans-serif;font-size:0.85rem">Preview unavailable.</p>'); return; }
|
|
1581
|
-
|
|
1582
|
-
|
|
1581
|
+
var bodyHtml = data.html + (data.frontmatter_html || '');
|
|
1582
|
+
cache[path] = { title: data.title, html: bodyHtml };
|
|
1583
|
+
updatePopup(bodyHtml, data.title || label);
|
|
1583
1584
|
})
|
|
1584
1585
|
.catch(function() {
|
|
1585
1586
|
cache[path] = false;
|