Merge pull request #338 from jroes/resize-sha1s
Fit generated SHA1 placeholders to original length.
This commit is contained in:
@@ -5,3 +5,5 @@ notifications:
|
||||
disabled: true
|
||||
before_install:
|
||||
- sudo apt-get install -y asciidoc
|
||||
- sudo easy_install docutils
|
||||
|
||||
+30
-6
@@ -80,17 +80,41 @@ module Gollum
|
||||
def extract_tex(data)
|
||||
data.gsub(/\\\[\s*(.*?)\s*\\\]/m) do
|
||||
tag = CGI.escapeHTML($1)
|
||||
id = Digest::SHA1.hexdigest(tag)
|
||||
id = generate_placeholder(tag, $&.length)
|
||||
@texmap[id] = [:block, tag]
|
||||
id
|
||||
end.gsub(/\\\(\s*(.*?)\s*\\\)/m) do
|
||||
tag = CGI.escapeHTML($1)
|
||||
id = Digest::SHA1.hexdigest(tag)
|
||||
id = generate_placeholder(tag, $&.length)
|
||||
@texmap[id] = [:inline, tag]
|
||||
id
|
||||
end
|
||||
end
|
||||
|
||||
# Fit `id` into `len` by adding trailing spaces or truncating.
|
||||
#
|
||||
# id - The String identifier to be fit.
|
||||
# len - The Integer target length.
|
||||
#
|
||||
# Returns the newly-fit String.
|
||||
def fit_width(id, len)
|
||||
if id.length < len
|
||||
id.ljust(len)
|
||||
else
|
||||
id[0...len]
|
||||
end
|
||||
end
|
||||
|
||||
# Generate a placeholder of a particular length.
|
||||
#
|
||||
# tag - The original String tag to be processed later.
|
||||
# length - The Integer length the placeholder should be.
|
||||
#
|
||||
# Returns the new placeholder String.
|
||||
def generate_placeholder(tag, length)
|
||||
fit_width(Digest::SHA1.hexdigest(tag), length)
|
||||
end
|
||||
|
||||
# Process all TeX from the texmap and replace the placeholders with the
|
||||
# final markup.
|
||||
#
|
||||
@@ -131,14 +155,14 @@ module Gollum
|
||||
parts = $2.split('][')
|
||||
parts[0][0..4] = ""
|
||||
link = "#{parts[1]}|#{parts[0].sub(/\.org/,'')}"
|
||||
id = Digest::SHA1.hexdigest(link)
|
||||
id = generate_placeholder(link, $&.length)
|
||||
@tagmap[id] = link
|
||||
"#{pre}#{id}#{post}"
|
||||
else
|
||||
$&
|
||||
end
|
||||
else
|
||||
id = Digest::SHA1.hexdigest($2)
|
||||
id = generate_placeholder($2, $2.length+4)
|
||||
@tagmap[id] = $2
|
||||
"#{$1}#{id}#{$3}"
|
||||
end
|
||||
@@ -385,7 +409,7 @@ module Gollum
|
||||
# Returns the placeholder'd String data.
|
||||
def extract_code(data)
|
||||
data.gsub!(/^([ \t]*)``` ?([^\r\n]+)?\r?\n(.+?)\r?\n\1```\r?$/m) do
|
||||
id = Digest::SHA1.hexdigest("#{$2}.#{$3}")
|
||||
id = generate_placeholder("#{$2}.#{$3}", [$2, $3].join.length)
|
||||
cached = check_cache(:code, id)
|
||||
@codemap[id] = cached ?
|
||||
{ :output => cached } :
|
||||
@@ -467,7 +491,7 @@ module Gollum
|
||||
# Returns the placeholder'd String data.
|
||||
def extract_wsd(data)
|
||||
data.gsub(/^\{\{\{ ?(.+?)\r?\n(.+?)\r?\n\}\}\}\r?$/m) do
|
||||
id = Digest::SHA1.hexdigest($2)
|
||||
id = generate_placeholder($2, $&.length)
|
||||
@wsdmap[id] = { :style => $1, :code => $2 }
|
||||
id
|
||||
end
|
||||
|
||||
@@ -195,6 +195,36 @@ context "Markup" do
|
||||
assert_equal "<p><code>make a link [[home|sweet home]]</code></p>", page.formatted_data
|
||||
end
|
||||
|
||||
test "table with links" do
|
||||
table = <<EOT
|
||||
+------------------------------+
|
||||
| Proposal | Mentor |
|
||||
+===============+==============+
|
||||
| [[Ray-Bans]] | technoweenie |
|
||||
+------------------------------+
|
||||
EOT
|
||||
expected_table = <<EOT
|
||||
<div class="document">
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="52%">
|
||||
<col width="48%">
|
||||
</colgroup>
|
||||
<thead valign="bottom"><tr>
|
||||
<th class="head" colspan="2">Proposal | Mentor</th>
|
||||
</tr></thead>
|
||||
<tbody valign="top"><tr>
|
||||
<td colspan="2">
|
||||
<a class="internal absent" href="/Ray-Bans">Ray-Bans</a> | technoweenie</td>
|
||||
</tr></tbody>
|
||||
</table>
|
||||
</div>
|
||||
EOT
|
||||
@wiki.write_page("Potato", :rest, table, commit_details)
|
||||
page = @wiki.page("Potato")
|
||||
assert_equal expected_table.chomp, page.formatted_data
|
||||
end
|
||||
|
||||
#########################################################################
|
||||
#
|
||||
# Images
|
||||
|
||||
Reference in New Issue
Block a user