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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf955ffcbe5dfc1e1f5070b3fa36a6d2d15a092e7be6ca7f8ac5dcd4b863162a
4
- data.tar.gz: 3ea514cfed258bc71a8a3e82f6ef883e1ed619fc63b46e9217eb4745c455fdd5
3
+ metadata.gz: e91138e164e026f52b6957f44693eb86d75b79eda7e4404d094f1ea0d4e35d26
4
+ data.tar.gz: b549ff9d07b45f43cc1639c2b4a47171f3a38bb76e2e98c1bb0ffe03ddc53fbe
5
5
  SHA512:
6
- metadata.gz: 19f44c77aab4f8a5a2978c85f8fd900f6a0cc45d9399897a26acae80d5809ce57669716a1a5e488c276a4b53e0b2e5d5e3bc13d8b6463a5c8d9c76342eb39e4f
7
- data.tar.gz: b8adb9e49b1def08d6d3f4061de5048d3cf14232d4ce0c3b9fde51f605f52fb9338a9b39ad49f569d9663fdf9e718e1396f37674e55c7c3f025ffa7a271d3548
6
+ metadata.gz: cfc1004e65a89e09263f3a35f2da2b3b354afe8351efa87e49194b0aec3bef5aaeedd7d4aba70f00c01ebca6468150a296be2bdad0d8ca238f87b5bc73ebca0d
7
+ data.tar.gz: c0cc3d73580b42c40c3f9244ed5acc69a74363237c54af0d21877bf4f1a64d2b642150fc4c384d13a6efb74a1bf86f12819d10b913f935ff60298e1e055e8460
@@ -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
- begin
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
- JSON.dump({ title: title.to_s, html: html })
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
@@ -1,3 +1,3 @@
1
1
  module MarkdownServer
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
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
- cache[path] = { title: data.title, html: data.html };
1582
- updatePopup(data.html, data.title || label);
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;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdownr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Dunn