Files
leadchat/lib/superscript_renderer.rb
Nithin David Thomas d2aa19579e feat: Adds support for superscript in help center articles (#7279)
- Adds support for superscript when rendering article markdown
- Chatwoot Markdown Render to render markdown everywhere

Co-authored-by: Sojan <sojan@pepalo.com>
2023-06-14 15:39:00 +05:30

29 lines
713 B
Ruby

class SuperscriptRenderer < CommonMarker::HtmlRenderer
def text(node)
content = node.string_content
# Check for presence of '^' in the content
if content.include?('^')
# Split the text and insert <sup> tags where necessary
split_content = parse_sup(content)
# Output the transformed content
out(split_content.join)
else
# Output the original content
out(escape_html(content))
end
end
private
def parse_sup(content)
content.split(/(\^[^\^]+\^)/).map do |segment|
if segment.start_with?('^') && segment.end_with?('^')
"<sup>#{escape_html(segment[1..-2])}</sup>"
else
escape_html(segment)
end
end
end
end