mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 23:31:18 +08:00
FEATURE: Bundle discourse-footnote plugin into core (#23995)
Formerly https://github.com/discourse/discourse-footnote
This commit is contained in:
46
plugins/footnote/plugin.rb
Normal file
46
plugins/footnote/plugin.rb
Normal file
@ -0,0 +1,46 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# name: footnote
|
||||
# about: Adds markdown.it footnote support to Discourse
|
||||
# version: 1.0
|
||||
# authors: Discourse Team
|
||||
# url: https://github.com/discourse/discourse/tree/main/plugins/footnote
|
||||
|
||||
enabled_site_setting :enable_markdown_footnotes
|
||||
|
||||
register_asset "vendor/javascripts/markdown-it-footnote.js", :vendored_pretty_text
|
||||
|
||||
register_asset "stylesheets/footnotes.scss"
|
||||
|
||||
register_svg_icon "ellipsis-h" if respond_to?(:register_svg_icon)
|
||||
|
||||
on(:before_post_process_cooked) do |doc, post|
|
||||
doc
|
||||
.css("a.footnote-backref")
|
||||
.each do |backref|
|
||||
href = backref["href"] || ""
|
||||
id = href[6..-1].to_i
|
||||
backref["href"] = "#footnote-ref-#{post.id}-#{id}"
|
||||
end
|
||||
|
||||
doc
|
||||
.css("sup.footnote-ref a")
|
||||
.each do |ref|
|
||||
href = ref["href"] || ""
|
||||
id = href[3..-1].to_i
|
||||
ref["href"] = "#footnote-#{post.id}-#{id}"
|
||||
|
||||
id = ref["id"] || ""
|
||||
id = id[5..-1].to_i
|
||||
ref["id"] = "footnote-ref-#{post.id}-#{id}"
|
||||
end
|
||||
|
||||
doc
|
||||
.css("li.footnote-item")
|
||||
.each do |li|
|
||||
id = li["id"] || ""
|
||||
id = id[2..-1].to_i
|
||||
|
||||
li["id"] = "footnote-#{post.id}-#{id}"
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user