FEATURE: allow advanced specification of excerpts for posts

FEATURE: allow advanced specification of excerpts for posts

Previously users could control excerpt with <span class='excerpt'>
in Markdown, this is somewhat limited for plugins that need to define this
across a section. This adds support for DIV as well

From 5c17e462744cb516313729b809e6094e25126e14 Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Tue, 4 Dec 2018 15:13:34 +1100
Subject: [PATCH] FEATURE: allow advanced specification of excerpts for posts

Previously users could control excerpt with `<span class='excerpt'>`
in Markdown, this is somewhat limited for plugins that need to define this
across a section. This adds support for DIV as well

diff --git a/app/assets/javascripts/pretty-text/white-lister.js.es6 b/app/assets/javascripts/pretty-text/white-lister.js.es6
index c303283..f864126 100644
--- a/app/assets/javascripts/pretty-text/white-lister.js.es6
+++ b/app/assets/javascripts/pretty-text/white-lister.js.es6
@@ -183,6 +183,7 @@ const DEFAULT_LIST = [
   "small",
   "span[lang]",
   "span.excerpt",
+  "div.excerpt",
   "span.hashtag",
   "span.mention",
   "strike",
diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb
index 20f1e82..304491c 100644
--- a/spec/components/post_creator_spec.rb
+++ b/spec/components/post_creator_spec.rb
@@ -270,6 +270,21 @@ describe PostCreator do
         }.to_not change { topic.excerpt }
       end
 
+      it 'supports custom excerpts' do
+        raw = <<~MD
+          <div class='excerpt'>
+          I am
+
+          a custom excerpt
+          </div>
+
+          testing
+        MD
+        post = create_post(raw: raw)
+
+        expect(post.excerpt).to eq("I am\na custom excerpt")
+      end
+
       it 'creates post stats' do
 
         Draft.set(user, 'new_topic', 0, "test")

GitHub

1 Like