Skip to content

id added in heading for scroll #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/services/html/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@ def parse_emojis
self
end

def addIdHeadings
doc = Nokogiri::HTML.fragment(@html)
doc.search("a.anchor").each do |anchor|
anchor.set_attribute("id", anchor.attr("name"))
end

@html = doc.to_html

self
end

private

def img_of_size(source, width = 880)
Expand Down
1 change: 1 addition & 0 deletions app/services/markdown_processor/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def parse_html(html)
Html::Parser
.new(html)
.remove_nested_linebreak_in_list
.addIdHeadings
.prefix_all_images
.wrap_all_images_in_links
.add_control_class_to_codeblock
Expand Down