Properly extract and display title for all formats.

This commit is contained in:
Tom Preston-Werner
2010-07-23 16:45:16 -07:00
parent bd3721d4d3
commit 5ce149715f
5 changed files with 74 additions and 23 deletions
+42 -11
View File
@@ -222,10 +222,6 @@ html {overflow-y: scroll;}
margin-top: 1.5em !important; margin-top: 1.5em !important;
} }
.wikistyle h1:first-child {
display: none;
}
.wikistyle h2 { .wikistyle h2 {
font-size: 150% !important; font-size: 150% !important;
margin-top: 1.5em !important; margin-top: 1.5em !important;
@@ -344,25 +340,60 @@ html {overflow-y: scroll;}
/* Special markup considerations */ /* Special markup considerations */
.wikistyle.gollum > h1:first-child {
display: none;
}
/* asciidoc */ /* asciidoc */
.wikistyle .ulist p, .wikistyle.gollum.asciidoc > div#header > h1:first-child {
.wikistyle .olist p { display: none;
}
.wikistyle.gollum.asciidoc .ulist p,
.wikistyle.gollum.asciidoc .olist p {
margin: 0 !important; margin: 0 !important;
} }
.wikistyle .loweralpha { .wikistyle.gollum.asciidoc .loweralpha {
list-style-type: lower-alpha; list-style-type: lower-alpha;
} }
.wikistyle .lowerroman { .wikistyle.gollum.asciidoc .lowerroman {
list-style-type: lower-roman; list-style-type: lower-roman;
} }
.wikistyle .upperalpha { .wikistyle.gollum.asciidoc .upperalpha {
list-style-type: upper-alpha; list-style-type: upper-alpha;
} }
.wikistyle .upperroman { .wikistyle.gollum.asciidoc .upperroman {
list-style-type: upper-roman; list-style-type: upper-roman;
} }
/* org */
.wikistyle.gollum.org > p.title:first-child {
display: none;
}
.wikistyle.gollum.org p:first-child + h1 {
border-top: none !important;
}
/* pod */
.wikistyle.gollum.pod > a.dummyTopAnchor:first-child + h1 {
display: none;
}
.wikistyle.gollum.pod h1 a {
text-decoration: none;
color: inherit;
}
/* rest */
.wikistyle.gollum.rest > div.document > div.section > h1:first-child {
display: none;
}
+1 -1
View File
@@ -4,7 +4,7 @@
<a href="/">Home</a> | <a href="/edit/{{name}}">Edit</a> <a href="/">Home</a> | <a href="/edit/{{name}}">Edit</a>
</div> </div>
<h1>{{human_name}}</h1> <h1>{{human_name}}</h1>
<div class="wikistyle"> <div class="wikistyle gollum {{format}}">
{{{content}}} {{{content}}}
</div> </div>
</div> </div>
+4
View File
@@ -11,6 +11,10 @@ module Precious
"A Page" "A Page"
end end
def format
@page.format.to_s
end
def author def author
@page.version.author.name @page.version.author.name
end end
+8 -1
View File
@@ -24,7 +24,14 @@ module Gollum
def render def render
data = extract_code(@data) data = extract_code(@data)
data = extract_tags(data) data = extract_tags(data)
data = GitHub::Markup.render(@name, data) rescue '' begin
data = GitHub::Markup.render(@name, data)
if data.nil?
raise "There was an error converting #{@name} to HTML."
end
rescue Object => e
data = %{<p class="gollum-error">#{e.message}</p>}
end
data = process_tags(data) data = process_tags(data)
data = process_code(data) data = process_code(data)
data = Sanitize.clean(data, SANITIZATION_OPTIONS) data = Sanitize.clean(data, SANITIZATION_OPTIONS)
+19 -10
View File
@@ -24,7 +24,7 @@ module Gollum
end end
# Checks if a filename has a valid extension understood by GitHub::Markup. # Checks if a filename has a valid extension understood by GitHub::Markup.
# Also, checks if the filename has no "_" in the front (such as # Also, checks if the filename has no "_" in the front (such as
# _Footer.md). # _Footer.md).
# #
# filename - String filename, like "Home.md". # filename - String filename, like "Home.md".
@@ -60,15 +60,24 @@ module Gollum
# #
# Returns the fully sanitized String title. # Returns the fully sanitized String title.
def title def title
doc = Nokogiri::HTML(self.formatted_data) doc = Nokogiri::HTML(%{<div id="gollum-root">} + self.formatted_data + %{</div>})
if doc.first_element_child &&
doc.first_element_child.children && header =
doc.first_element_child.children.first && case self.format
doc.first_element_child.children.first.children && when :asciidoc
doc.first_element_child.children.first.children.first && doc.css("div#gollum-root > div#header > h1:first-child")
doc.first_element_child.children.first.children.first.name && when :org
doc.first_element_child.children.first.children.first.name == 'h1' doc.css("div#gollum-root > p.title:first-child")
Sanitize.clean(doc.first_element_child.children.first.children.first.to_html) when :pod
doc.css("div#gollum-root > a.dummyTopAnchor:first-child + h1")
when :rest
doc.css("div#gollum-root > div > div > h1:first-child")
else
doc.css("div#gollum-root > h1:first-child")
end
if !header.empty?
Sanitize.clean(header.to_html)
else else
Sanitize.clean(self.name.split('.')[0..-2].join('.').gsub('-', ' ')) Sanitize.clean(self.name.split('.')[0..-2].join('.').gsub('-', ' '))
end end