fix dtext styles

This commit is contained in:
albert
2011-10-22 17:23:33 -04:00
parent 9a3155d10b
commit 5444ad5107
8 changed files with 68 additions and 47 deletions

View File

@@ -40,7 +40,7 @@ em {
font-style: italic; font-style: italic;
} }
h1, h2, h3 { h1, h2, h3, h4, h5, h6 {
font-family: Tahoma; font-family: Tahoma;
font-weight: bold; font-weight: bold;
line-height: 1.25em; line-height: 1.25em;
@@ -54,7 +54,8 @@ h2 {
font-size: $h2_size; font-size: $h2_size;
} }
h3 { h3, h4, h5, h6 {
font-weight: bold;
font-size: $h3_size; font-size: $h3_size;
} }

View File

@@ -16,6 +16,10 @@ div.prose {
h3 { h3 {
padding: $h3_padding; padding: $h3_padding;
} }
h4, h5, h6 {
padding: 0;
}
ul { ul {
margin-left: 1em; margin-left: 1em;

View File

@@ -54,6 +54,15 @@ class WikiPagesController < ApplicationController
@wiki_page.revert_to!(@version) @wiki_page.revert_to!(@version)
respond_with(@wiki_page) respond_with(@wiki_page)
end end
def show_or_new
@wiki_page = WikiPage.find_by_name(params[:title])
if @wiki_page
redirect_to wiki_page_path(@wiki_page)
else
redirect_to new_wiki_page_path(:wiki_page => {:title => params[:title]})
end
end
private private
def normalize_search_params def normalize_search_params

View File

@@ -17,25 +17,29 @@ class DText
str.gsub!(/\n/m, "<br>") str.gsub!(/\n/m, "<br>")
str.gsub!(/\[b\](.+?)\[\/b\]/i, '<strong>\1</strong>') str.gsub!(/\[b\](.+?)\[\/b\]/i, '<strong>\1</strong>')
str.gsub!(/\[i\](.+?)\[\/i\]/i, '<em>\1</em>') str.gsub!(/\[i\](.+?)\[\/i\]/i, '<em>\1</em>')
str.gsub!(/(?<![=\]])(https?:\/\/\S+)/m) do |link| str.gsub!(/("[^"]+":(https?:\/\/|\/)\S+|https?:\/\/\S+)/m) do |url|
if link =~ /([;,.!?\)\]])$/ if url =~ /^"([^"]+)":(.+)$/
stop = $1 text = $1
link.chop! url = $2
text = link
else else
stop = "" text = url
text = link end
if url =~ /([;,.!?\)\]<>])$/
url.chop!
ch = $1
else
ch = ""
end end
link.gsub!(/"/, '&quot;') '<a href="' + url + '">' + text + '</a>' + ch
'<a href="' + link + '">' + text + '</a>' + stop
end
str.gsub!(/\[url\](http.+?)\[\/url\]/i) do
%{<a href="#{$1}">#{$1}</a>}
end
str.gsub!(/\[url=(http.+?)\](.+?)\[\/url\]/m) do
%{<a href="#{$1}">#{$2}</a>}
end end
# str.gsub!(/\[url\](http.+?)\[\/url\]/i) do
# %{<a href="#{$1}">#{$1}</a>}
# end
# str.gsub!(/\[url=(http.+?)\](.+?)\[\/url\]/m) do
# %{<a href="#{$1}">#{$2}</a>}
# end
str = parse_aliased_wiki_links(str) str = parse_aliased_wiki_links(str)
str = parse_wiki_links(str) str = parse_wiki_links(str)
str = parse_post_links(str) str = parse_post_links(str)
@@ -44,34 +48,23 @@ class DText
end end
def self.parse_aliased_wiki_links(str) def self.parse_aliased_wiki_links(str)
str.gsub(/\[\[(.+?)\|(.+?)\]\]/m) do str.gsub(/\[\[([^\|\]]+)\|([^\]]+)\]\]/m) do
text = CGI.unescapeHTML($1) text = CGI.unescapeHTML($1).tr("_", " ")
title = CGI.unescapeHTML($2) title = CGI.unescapeHTML($2)
wiki_page = WikiPage.find_title_and_id(title) %{<a href="/wiki_pages/show_or_new?title=#{u(title)}">#{h(text)}</a>}
if wiki_page
%{<a href="/wiki_pages/#{wiki_page.id}">#{h(text)}</a>}
else
%{<a href="/wiki_pages/new?title=#{u(title)}">#{h(text)}</url>}
end
end end
end end
def self.parse_wiki_links(str) def self.parse_wiki_links(str)
str.gsub(/\[\[(.+?)\]\]/) do str.gsub(/\[\[([^\]]+)\]\]/) do
title = CGI.unescapeHTML($1) title = CGI.unescapeHTML($1)
wiki_page = WikiPage.find_title_and_id(title) text = title.tr("_", " ")
%{<a href="/wiki_pages/show_or_new?title=#{u(title)}">#{h(text)}</a>}
if wiki_page
%{<a href="/wiki_pages/#{wiki_page.id}">#{h(title)}</a>}
else
%{<a href="/wiki_pages/new?wiki_page[title]=#{u(title)}">#{h(title)}</a>}
end
end end
end end
def self.parse_post_links(str) def self.parse_post_links(str)
str.gsub(/\{\{(.+?)\}\}/) do str.gsub(/\{\{([^\}]+)\}\}/) do
tags = CGI.unescapeHTML($1) tags = CGI.unescapeHTML($1)
%{<a href="/posts?tags=#{u(tags)}">#{h(tags)}</a>} %{<a href="/posts?tags=#{u(tags)}">#{h(tags)}</a>}
end end

View File

@@ -5,7 +5,7 @@
<section id="content"> <section id="content">
<h1 id="wiki-page-title"><%= @wiki_page.pretty_title %></h1> <h1 id="wiki-page-title"><%= @wiki_page.pretty_title %></h1>
<div id="wiki-page-body" class="dtext"> <div id="wiki-page-body" class="prose">
<%= format_text(@wiki_page.body) %> <%= format_text(@wiki_page.body) %>
</div> </div>

View File

@@ -136,6 +136,9 @@ Danbooru::Application.routes.draw do
member do member do
put :revert put :revert
end end
collection do
get :show_or_new
end
end end
resources :wiki_page_versions, :only => [:index, :show] resources :wiki_page_versions, :only => [:index, :show]

View File

@@ -19,7 +19,7 @@ class ArtistTest < ActiveSupport::TestCase
@post = Factory.create(:post, :tag_string => "aaa") @post = Factory.create(:post, :tag_string => "aaa")
@artist = Factory.create(:artist, :name => "aaa") @artist = Factory.create(:artist, :name => "aaa")
@artist.reload @artist.reload
@artist.update_attributes(:is_banned => true) @artist.update_attributes(:is_banned => true, :as => :admin)
@post.reload @post.reload
end end

View File

@@ -12,8 +12,8 @@ class DTextTest < ActiveSupport::TestCase
end end
def test_wiki_links def test_wiki_links
assert_equal("<p>a <a href=\"/wiki_pages/new?wiki_page%5Btitle%5D=b\">b</a> c</p>", p("a [[b]] c")) assert_equal("<p>a <a href=\"/wiki_pages/show_or_new?title=b\">b</a> c</p>", p("a [[b]] c"))
assert_equal("<p>a <a href=\"/wiki_pages/new?wiki_page%5Btitle%5D=spoiler\">spoiler</a> c</p>", p("a [[spoiler]] c")) assert_equal("<p>a <a href=\"/wiki_pages/show_or_new?title=spoiler\">spoiler</a> c</p>", p("a [[spoiler]] c"))
end end
def test_spoilers def test_spoilers
@@ -46,16 +46,22 @@ class DTextTest < ActiveSupport::TestCase
assert_equal('<p>a (<a href="http://test.com">http://test.com</a>) b</p>', p('a (http://test.com) b')) assert_equal('<p>a (<a href="http://test.com">http://test.com</a>) b</p>', p('a (http://test.com) b'))
end end
def test_links # def test_links
assert_equal('<p><a href="http://test.com">test</a></p>', p('[url=http://test.com]test[/url]')) # assert_equal('<p><a href="http://test.com">test</a></p>', p('[url=http://test.com]test[/url]'))
assert_equal('<p>"1" <a href="http://two.com">2</a></p>', p('"1" [url=http://two.com]2[/url]')) # assert_equal('<p>"1" <a href="http://two.com">2</a></p>', p('"1" [url=http://two.com]2[/url]'))
assert_equal('<p>"1" <a href="http://three.com">2 &amp; 3</a></p>', p('"1" [url=http://three.com]2 & 3[/url]')) # assert_equal('<p>"1" <a href="http://three.com">2 &amp; 3</a></p>', p('"1" [url=http://three.com]2 & 3[/url]'))
# end
def test_old_syle_links
assert_equal('<p><a href="http://test.com">test</a></p>', p('"test":http://test.com'))
assert_equal('<p>"1" <a href="http://two.com">2</a></p>', p('"1" "2":http://two.com'))
assert_equal('<p>"1" <a href="http://three.com">2 &amp; 3</a></p>', p('"1" "2 & 3":http://three.com'))
end end
def test_aliased_urls # def test_aliased_urls
assert_equal('<p>a <a href="http://test.com">bob</a>. b</p>', p('a [url=http://test.com]bob[/url]. b')) # assert_equal('<p>a <a href="http://test.com">bob</a>. b</p>', p('a [url=http://test.com]bob[/url]. b'))
assert_equal('<p><em><a href="http://test.com">bob</a></em></p>', p('[i][url=http://test.com]bob[/url][/i]')) # assert_equal('<p><em><a href="http://test.com">bob</a></em></p>', p('[i][url=http://test.com]bob[/url][/i]'))
end # end
def test_lists def test_lists
assert_equal('<ul><li>a</li></ul>', p('* a')) assert_equal('<ul><li>a</li></ul>', p('* a'))
@@ -78,4 +84,9 @@ class DTextTest < ActiveSupport::TestCase
def test_extra_newlines def test_extra_newlines
assert_equal('<p>a</p><p>b</p>', p("a\n\n\n\n\n\n\nb\n\n\n\n")) assert_equal('<p>a</p><p>b</p>', p("a\n\n\n\n\n\n\nb\n\n\n\n"))
end end
def test_complex_links
assert_equal('<p><a href="/wiki_pages/show_or_new?title=2+3">1</a> | <a href="/wiki_pages/show_or_new?title=5+6">4</a></p>', p("[[1|2 3]] | [[4|5 6]]"))
assert_equal("<p>Tags <strong>(<a href=\"/wiki_pages/show_or_new?title=Tagging+Guidelines\">howto:tag</a> | <a href=\"/wiki_pages/show_or_new?title=Tag+Checklist\">howto:tag checklist</a> | <a href=\"/wiki_pages/show_or_new?title=Tag+Groups\">Tag Groups</a>)</strong></p>", p("Tags [b]([[howto:tag|Tagging Guidelines]] | [[howto:tag_checklist|Tag Checklist]] | [[Tag Groups]])[/b]"))
end
end end