FEATURE: allow for custom excerpt BBCODE
This allows fidelity in controlling excerpt (text that shows up when you pin a topic or link to it externally): ``` I am some text [excerpt] This is some **custom** markdown that should be the excerpt [/excerpt] More text ``` Previous solution relied on DIVs, unfortunately DIVs do not play well, by design with mixing markdown unless you have a preceding newline eg: ``` <div class='hello'> this will be treated properly as markdown </div> ``` This extra newline is not desirable. I am also considering adding ``` [div class=excerpt] [/div] ``` This would offer lots of flexibility to themes and plugins that do not want the extra annoying newline.
This commit is contained in:
parent
2cbb513c98
commit
69aa8f18c2
|
@ -344,6 +344,11 @@ export function setup(helper) {
|
||||||
helper.registerPlugin(md => {
|
helper.registerPlugin(md => {
|
||||||
const ruler = md.block.bbcode.ruler;
|
const ruler = md.block.bbcode.ruler;
|
||||||
|
|
||||||
|
ruler.push("excerpt", {
|
||||||
|
tag: "excerpt",
|
||||||
|
wrap: "div.excerpt"
|
||||||
|
});
|
||||||
|
|
||||||
ruler.push("code", {
|
ruler.push("code", {
|
||||||
tag: "code",
|
tag: "code",
|
||||||
replace: function(state, tagInfo, content) {
|
replace: function(state, tagInfo, content) {
|
||||||
|
|
|
@ -287,7 +287,7 @@ describe PrettyText do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not convert mentions to links' do
|
it 'should not convert mentions to links' do
|
||||||
user = Fabricate(:user)
|
_user = Fabricate(:user)
|
||||||
|
|
||||||
expect(PrettyText.cook('hi @user')).to eq('<p>hi @user</p>')
|
expect(PrettyText.cook('hi @user')).to eq('<p>hi @user</p>')
|
||||||
end
|
end
|
||||||
|
@ -579,6 +579,17 @@ describe PrettyText do
|
||||||
expect(PrettyText.excerpt(nil, 100)).to eq('')
|
expect(PrettyText.excerpt(nil, 100)).to eq('')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "handles custom bbcode excerpt" do
|
||||||
|
raw = <<~RAW
|
||||||
|
[excerpt]
|
||||||
|
hello [site](https://site.com)
|
||||||
|
[/excerpt]
|
||||||
|
more stuff
|
||||||
|
RAW
|
||||||
|
post = Fabricate(:post, raw: raw)
|
||||||
|
expect(post.excerpt).to eq("hello <a href=\"https://site.com\" rel=\"nofollow noopener\">site</a>")
|
||||||
|
end
|
||||||
|
|
||||||
it "handles span excerpt at the beginning of a post" do
|
it "handles span excerpt at the beginning of a post" do
|
||||||
expect(PrettyText.excerpt("<span class='excerpt'>hi</span> test", 100)).to eq('hi')
|
expect(PrettyText.excerpt("<span class='excerpt'>hi</span> test", 100)).to eq('hi')
|
||||||
post = Fabricate(:post, raw: "<span class='excerpt'>hi</span> test")
|
post = Fabricate(:post, raw: "<span class='excerpt'>hi</span> test")
|
||||||
|
|
Loading…
Reference in New Issue