diff --git a/app/furniture/journal/entry.rb b/app/furniture/journal/entry.rb
index 24c6d4b5a..6586dd87d 100644
--- a/app/furniture/journal/entry.rb
+++ b/app/furniture/journal/entry.rb
@@ -1,49 +1,62 @@
-class Journal::Entry < ApplicationRecord
- self.table_name = "journal_entries"
- include RendersMarkdown
- extend StripsNamespaceFromModelName
+class Journal
+ class Entry < ApplicationRecord
+ self.table_name = "journal_entries"
+ include RendersMarkdown
+ extend StripsNamespaceFromModelName
- scope :recent, -> { order("published_at DESC NULLS FIRST") }
+ scope :recent, -> { order("published_at DESC NULLS FIRST") }
- attribute :headline, :string
- attribute :body, :string
- validates :body, presence: true
+ attribute :headline, :string
+ attribute :body, :string
+ validates :body, presence: true
- # URI-friendly description of the entry.
- attribute :slug, :string
- validates :slug, uniqueness: {scope: :journal_id}
+ # URI-friendly description of the entry.
+ attribute :slug, :string
+ validates :slug, uniqueness: {scope: :journal_id}
- # FriendlyId does the legwork to make the slug uri-friendly
- extend FriendlyId
- friendly_id :headline, use: :scoped, scope: :journal
+ # FriendlyId does the legwork to make the slug uri-friendly
+ extend FriendlyId
+ friendly_id :headline, use: :scoped, scope: :journal
- attribute :published_at, :datetime
+ attribute :published_at, :datetime
- # @!attribute journal
- # @return [Journal::Journal]
- belongs_to :journal, class_name: "Journal::Journal", inverse_of: :entries
- delegate :room, :space, to: :journal
+ # @!attribute journal
+ # @return [Journal::Journal]
+ belongs_to :journal, class_name: "Journal::Journal", inverse_of: :entries
+ delegate :room, :space, to: :journal
- def published?
- published_at.present?
- end
+ def published?
+ published_at.present?
+ end
- def to_html
- render_markdown(body)
- end
+ def to_html
+ render_markdown(body)
+ end
- def to_param
- slug
- end
+ def self.renderer
+ @_renderer ||= Redcarpet::Markdown.new(
+ Renderer.new(filter_html: true, with_toc_data: true),
+ autolink: true, strikethrough: true,
+ no_intra_emphasis: true,
+ lax_spacing: true,
+ fenced_code_blocks: true, disable_indented_code_blocks: true,
+ tables: true, footnotes: true, superscript: true, quote: true
+ )
+ end
+
+ def to_param
+ slug
+ end
- def location(action = :show)
- case action
- when :new
- [:new] + journal.location + [:entry]
- when :edit
- [:edit] + journal.location + [self]
- else
- journal.location + [self]
+ def location(action = :show)
+ case action
+ when :new
+ [:new] + journal.location + [:entry]
+ when :edit
+ [:edit] + journal.location + [self]
+ else
+ journal.location + [self]
+ end
end
end
end
diff --git a/app/furniture/journal/flavored_markdown.rb b/app/furniture/journal/flavored_markdown.rb
new file mode 100644
index 000000000..e69de29bb
diff --git a/app/furniture/journal/renderer.rb b/app/furniture/journal/renderer.rb
new file mode 100644
index 000000000..8ac0d8888
--- /dev/null
+++ b/app/furniture/journal/renderer.rb
@@ -0,0 +1,12 @@
+class Journal
+ class Renderer < Redcarpet::Render::Safe
+ def autolink(link, link_type)
+ return link if link_type == :email
+ "#{link}"
+ end
+
+ def postprocess(doc)
+ doc.gsub(/@([a-zA-Z\d]*)@(.*\.[a-zA-Z]*)/, '@\1@\2')
+ end
+ end
+end
diff --git a/app/lib/renders_markdown.rb b/app/lib/renders_markdown.rb
index 4f42bc397..c24c6967b 100644
--- a/app/lib/renders_markdown.rb
+++ b/app/lib/renders_markdown.rb
@@ -1,6 +1,6 @@
module RendersMarkdown
def render_markdown(content)
- RendersMarkdown.renderer.render(content)
+ self.class.renderer.render(content)
end
def self.renderer
diff --git a/spec/furniture/journal/entry_spec.rb b/spec/furniture/journal/entry_spec.rb
new file mode 100644
index 000000000..6daac5f92
--- /dev/null
+++ b/spec/furniture/journal/entry_spec.rb
@@ -0,0 +1,18 @@
+require "rails_helper"
+
+RSpec.describe Journal::Entry do
+ subject(:entry) { build(:journal_entry, body: body) }
+
+ let(:body) { Faker::Books::CultureSeries.civ }
+
+ describe "#to_html" do
+ subject(:to_html) { entry.to_html }
+
+ context "when #body is 'https://www.google.com @zee@weirder.earth'" do
+ let(:body) { "https://www.google.com @zee@weirder.earth" }
+
+ it { is_expected.to include('@zee@weirder.earth') }
+ it { is_expected.to include('https://www.google.com') }
+ end
+ end
+end