Skip to content

Commit

Permalink
Link metadata after refs
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuap committed Sep 22, 2020
1 parent 6720d63 commit 418095f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions helpers/roam_helpers.rb
Expand Up @@ -28,10 +28,12 @@ def render_page_content(data, page = data)
def render_block(block, page)
content_tag(:div, class: block_class(block)) {
render_markdown(
link_tokens(
link_refs(
block["string"].to_s,
page
)
).gsub(/(?<name>[\w\s]+)::\s/) { |_match|
%(<span class="page-metadata">#{$1}:</span> )
}
).gsub(/\(\((?<uid>[^()]+)\)\)/) {
uid = Regexp.last_match[:uid]
if (ref = Hash(block["outbound_block_references"])[uid])
Expand All @@ -49,7 +51,7 @@ def render_block(block, page)
}
end

def link_tokens(string, page)
def link_refs(string, page)
refs = Hash(page["outbound_page_references"])
return string unless refs.any?

Expand All @@ -61,8 +63,6 @@ def link_tokens(string, page)
string.gsub!(/(?<=\s)#(?!\[)#{Regexp.escape(title)}/, %(<span class="page-tag"><a data-prefetch="true" href="/#{string_to_slug(title)}">##{title}</a></span>))
end

string.gsub!(/(?<name>[\w\s]+)::\s/) { |_match| %(<span class="page-metadata">#{$1}:</span> ) }

string
end

Expand Down

0 comments on commit 418095f

Please sign in to comment.