diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 2b38846d..1dba4482 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -1,7 +1,8 @@ module PagesHelper def wikified_body(body) - r = RedCloth.new(generate_anchors(body)) + body = wiki_header(body) + r = RedCloth.new(body) r.gsub!(/\[\[(.*?)(\|(.*?))?\]\]/) { wiki_link($1, $3) } sanitize r.to_html r.to_html @@ -16,6 +17,10 @@ module PagesHelper end end + def wiki_header(body) + body.gsub(/^(={2,6})\s+(.*)\s+={2,6}$/) { "h#{$1.size}. #{$2}" } + end + def generate_toc(body) toc = "" body.gsub(/^\s*h([1-6])\.\s+(.*)/) do diff --git a/app/models/page.rb b/app/models/page.rb index 96ca4c00..ca7de36e 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -1,3 +1,18 @@ +# == Schema Information +# Schema version: 20090325175756 +# +# Table name: pages +# +# id :integer not null, primary key +# title :string(255) +# body :text +# permalink :string(255) +# lock_version :integer default(0) +# updated_by :integer +# created_at :datetime +# updated_at :datetime +# + class Page < ActiveRecord::Base belongs_to :user, :foreign_key => 'updated_by' diff --git a/test/fixtures/articles.yml b/test/fixtures/articles.yml index 00162119..032471bb 100644 --- a/test/fixtures/articles.yml +++ b/test/fixtures/articles.yml @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 20090317175355 +# Schema version: 20090325175756 # # Table name: articles # diff --git a/test/fixtures/pages.yml b/test/fixtures/pages.yml index 9a2e19cb..362b3d4a 100644 --- a/test/fixtures/pages.yml +++ b/test/fixtures/pages.yml @@ -1,3 +1,18 @@ +# == Schema Information +# Schema version: 20090325175756 +# +# Table name: pages +# +# id :integer not null, primary key +# title :string(255) +# body :text +# permalink :string(255) +# lock_version :integer default(0) +# updated_by :integer +# created_at :datetime +# updated_at :datetime +# + # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html one: diff --git a/test/fixtures/suppliers.yml b/test/fixtures/suppliers.yml index 201290c1..f7e1d13b 100644 --- a/test/fixtures/suppliers.yml +++ b/test/fixtures/suppliers.yml @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 20090317175355 +# Schema version: 20090325175756 # # Table name: suppliers # diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb index b12dd9a6..7b102e6b 100644 --- a/test/unit/page_test.rb +++ b/test/unit/page_test.rb @@ -1,3 +1,18 @@ +# == Schema Information +# Schema version: 20090325175756 +# +# Table name: pages +# +# id :integer not null, primary key +# title :string(255) +# body :text +# permalink :string(255) +# lock_version :integer default(0) +# updated_by :integer +# created_at :datetime +# updated_at :datetime +# + require 'test_helper' class PageTest < ActiveSupport::TestCase