From 5ce149715f77b7dc116f1d9506be0bbd40721d6d Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Fri, 23 Jul 2010 16:45:16 -0700 Subject: [PATCH] Properly extract and display title for all formats. --- lib/gollum/frontend/public/css/screen.css | 53 ++++++++++++++++----- lib/gollum/frontend/templates/page.mustache | 2 +- lib/gollum/frontend/views/page.rb | 4 ++ lib/gollum/markup.rb | 9 +++- lib/gollum/page.rb | 29 +++++++---- 5 files changed, 74 insertions(+), 23 deletions(-) diff --git a/lib/gollum/frontend/public/css/screen.css b/lib/gollum/frontend/public/css/screen.css index 7e6f7828..fb7e61ac 100644 --- a/lib/gollum/frontend/public/css/screen.css +++ b/lib/gollum/frontend/public/css/screen.css @@ -222,10 +222,6 @@ html {overflow-y: scroll;} margin-top: 1.5em !important; } - .wikistyle h1:first-child { - display: none; - } - .wikistyle h2 { font-size: 150% !important; margin-top: 1.5em !important; @@ -344,25 +340,60 @@ html {overflow-y: scroll;} /* Special markup considerations */ +.wikistyle.gollum > h1:first-child { + display: none; +} + /* asciidoc */ -.wikistyle .ulist p, -.wikistyle .olist p { +.wikistyle.gollum.asciidoc > div#header > h1:first-child { + display: none; +} + +.wikistyle.gollum.asciidoc .ulist p, +.wikistyle.gollum.asciidoc .olist p { margin: 0 !important; } -.wikistyle .loweralpha { +.wikistyle.gollum.asciidoc .loweralpha { list-style-type: lower-alpha; } -.wikistyle .lowerroman { +.wikistyle.gollum.asciidoc .lowerroman { list-style-type: lower-roman; } -.wikistyle .upperalpha { +.wikistyle.gollum.asciidoc .upperalpha { list-style-type: upper-alpha; } -.wikistyle .upperroman { +.wikistyle.gollum.asciidoc .upperroman { list-style-type: upper-roman; -} \ No newline at end of file +} + +/* 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; +} diff --git a/lib/gollum/frontend/templates/page.mustache b/lib/gollum/frontend/templates/page.mustache index 96420561..89164917 100644 --- a/lib/gollum/frontend/templates/page.mustache +++ b/lib/gollum/frontend/templates/page.mustache @@ -4,7 +4,7 @@ Home | Edit

{{human_name}}

-
+
{{{content}}}
diff --git a/lib/gollum/frontend/views/page.rb b/lib/gollum/frontend/views/page.rb index f2ac6688..88f1297e 100644 --- a/lib/gollum/frontend/views/page.rb +++ b/lib/gollum/frontend/views/page.rb @@ -11,6 +11,10 @@ module Precious "A Page" end + def format + @page.format.to_s + end + def author @page.version.author.name end diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 5deb059b..f39caf59 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -24,7 +24,14 @@ module Gollum def render data = extract_code(@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 = %{

#{e.message}

} + end data = process_tags(data) data = process_code(data) data = Sanitize.clean(data, SANITIZATION_OPTIONS) diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index 83aaba90..7edb9002 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -24,7 +24,7 @@ module Gollum end # 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). # # filename - String filename, like "Home.md". @@ -60,15 +60,24 @@ module Gollum # # Returns the fully sanitized String title. def title - doc = Nokogiri::HTML(self.formatted_data) - if doc.first_element_child && - doc.first_element_child.children && - doc.first_element_child.children.first && - doc.first_element_child.children.first.children && - doc.first_element_child.children.first.children.first && - doc.first_element_child.children.first.children.first.name && - doc.first_element_child.children.first.children.first.name == 'h1' - Sanitize.clean(doc.first_element_child.children.first.children.first.to_html) + doc = Nokogiri::HTML(%{
} + self.formatted_data + %{
}) + + header = + case self.format + when :asciidoc + doc.css("div#gollum-root > div#header > h1:first-child") + when :org + doc.css("div#gollum-root > p.title:first-child") + 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 Sanitize.clean(self.name.split('.')[0..-2].join('.').gsub('-', ' ')) end