diff --git a/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js b/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js index 0d42988e1de..3d6d500ec97 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js @@ -670,7 +670,7 @@ eviltrout
assert.cooked( "# #category-hashtag", - 'b
\nc\n
',
+ 'b
\nc\n
',
"it handles headings with code blocks after them."
);
});
diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/anchor.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/anchor.js
index 03941e6a0f8..4ac19201e62 100644
--- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/anchor.js
+++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/anchor.js
@@ -1,5 +1,3 @@
-const SPECIAL_CHARACTERS_REGEX = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~’]/g;
-
export function setup(helper) {
if (helper.getOptions().previewing) {
return;
@@ -7,7 +5,11 @@ export function setup(helper) {
helper.registerPlugin((md) => {
md.core.ruler.push("anchor", (state) => {
- for (let idx = 0, lvl = 0; idx < state.tokens.length; idx++) {
+ for (
+ let idx = 0, lvl = 0, headingId = 0;
+ idx < state.tokens.length;
+ idx++
+ ) {
if (
state.tokens[idx].type === "blockquote_open" ||
(state.tokens[idx].type === "bbcode_open" &&
@@ -37,15 +39,7 @@ export function setup(helper) {
.replace(/^-+/, "")
.replace(/-+$/, "");
- if (slug.length === 0) {
- slug = state.tokens[idx + 1].content
- .replace(/\s+/g, "-")
- .replace(SPECIAL_CHARACTERS_REGEX, "")
- .replace(/\-\-+/g, "-")
- .replace(/^-+/, "")
- .replace(/-+$/, "");
- slug = encodeURI(slug).replace(/%/g, "").substr(0, 24);
- }
+ slug = `${slug || "heading"}-${++headingId}`;
linkOpen.attrSet("name", slug);
linkOpen.attrSet("class", "anchor");
diff --git a/plugins/poll/spec/lib/pretty_text_spec.rb b/plugins/poll/spec/lib/pretty_text_spec.rb
index c5b25e09a93..52fed2284ea 100644
--- a/plugins/poll/spec/lib/pretty_text_spec.rb
+++ b/plugins/poll/spec/lib/pretty_text_spec.rb
@@ -189,8 +189,8 @@ describe PrettyText do
HTML
- expect(cooked).to include("